TomEE ignores resource configuration when it can't find MySQL driver classes - apache-tomee

I made reference to Configuring data source - tomee.xml, persistence.xml. My persistence.xml is exactly as in the above except for the persistence unit name and jta datasource name
My tomee.xml is also similar
<Resource id="****DB" type="javax.sql.DataSource">
UserName ××××
Password ××××
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://localhost/××××
JtaManaged true
connectionProperties zeroDateTimeBehavior=convertToNull;useUnicode=yes;characterEncoding=UTF-8
</Resource>
I also verified by enumerating em.getEntityManagerFactory().getProperties() and found that Platform:OpenJPA JDBC Edition: MySQL Database.
But when I tried doing em.createNamedQuery... I got org.hsqldb.HsqlException: user lacks privilege or object not found. So it seems OpenJPA uses the default hsqldb in spite of the settings.
The sql statement in the server log was copy-and-pasted to phpmyadmin and worked. I even deleted the connectionProperties in tomee.xml but still did not work. Why?

My fault: mysql-connector-java.jar is not in tomee/lib folder. But I think tomee should complain instead of falling back to using hsqldb.

Related

An exception occured while establishing a connection to figure out your platform version

Trying to install PrestaShop through CLI but getting error
An exception occured while establishing a connection to figure out
your platform version. You can circumvent this by setting a
'server_version' configuration value
For further information have a look at:
https://github.com/doctrine/DoctrineBundle/issues/673
Anyone has any idea where do I add the server_version config value?
You should set server_version to your database server version (that depends on your hosting provider).
In your PrestaShop/app/config/config.yml there should be a "doctrine" section.
Beware that config is in yaml format and is case-sensitive and whitespace-sensitive. You should use the exact same indentations.
doctrine:
dbal:
default_connection: xxx
connections:
xxx:
server_version:
If you don't know your database version, and using mysql, nowadays, "8.0" is a safe first guess.

CAS and LDAP custom integration

I'm going to describe an odd situation.. We have a product with a properly working CAS and LDAP integration. The problem is that not all of our clients use LDAP, which is fine, EXCEPT that the integration is still in place and so CAS is actively attempting to connect to the ldap server (and failing of course). It attempts to connect every five minutes, which creates a very bloated Tomcat log. My goal is to prevent it from attempting to connect without gutting the integration. I'm hoping someone knows of a way to prevent or manage when/how CAS attempts to connect to the defined LDAP server.
I've attempted to remove key components of the CAS property file as well as the deployerConfigContext.xml but the integration has too many dependencies, and I haven't been successful.
Here are some of the properties that are used in the cas.properties file. Setting the ldap.auth.enabled to false allows our integration to not use LDAP when authenticating the user but doesn't prevent CAS from attempting to connect to the LDAP server:
ldap.auth.enabled=false
ldap.url=ldap://xyz.customurl.com
ldap.useStartTLS=false
ldap.rootDn=DC=xyz,DC=xyz,DC=com
ldap.baseDn=DC=xyz,DC=xyz,DC=com
ldap.connectTimeout=3000
ldap.managerDn=CN=xyz,CN=Users,DC=xyz,DC=xyz,DC=com
ldap.managerPassword=xyz
ldap.authn.searchFilter=(&(sAMAccountName={user})(objectClass=user))
ldap.domain=123.456.7.890
ldap.pool.minSize=1
ldap.pool.maxSize=10
ldap.pool.validateOnCheckout=false
ldap.pool.validatePeriodically=true
ldap.pool.blockWaitTime=3000
ldap.pool.validatePeriod=300
ldap.pool.prunePeriod=300
ldap.pool.idleTime=600
ldap.usePpolicy=false
ldap.allowMultipleDns=true
This is the relevant section from the deployerConfigContext.xml. I've tried commenting the entire ldap section but have received various other errors that caused TomCat to crash:
<bean id="ldapAuthenticationHandler"
class="org.jasig.cas.authentication.LdapAuthenticationHandler"
p:principalIdAttribute="sAMAccountName"
c:authenticator-ref="authenticator" lazy-init="true"/>
<ldaptive:ad-authenticator id="authenticator"
ldapUrl="${ldap.url}"
userFilter="${ldap.authn.searchFilter}"
bindDn="${ldap.managerDn}"
bindCredential="${ldap.managerPassword}"
allowMultipleDns="${ldap.allowMultipleDns:false}"
connectTimeout="${ldap.connectTimeout}"
validateOnCheckOut="${ldap.pool.validateOnCheckout}"
failFastInitialize="false"
blockWaitTime="${ldap.pool.blockWaitTime}"
idleTime="${ldap.pool.idleTime}"
baseDn="${ldap.baseDn}"
maxPoolSize="${ldap.pool.maxSize}"
minPoolSize="${ldap.pool.minSize}"
validatePeriodically="${ldap.pool.validatePeriodically}"
validatePeriod="${ldap.pool.validatePeriod}"
prunePeriod="${ldap.pool.prunePeriod}"
useSSL="${ldap.use.ssl:false}"
subtreeSearch="${ldap.subtree.search:true}"
useStartTLS="${ldap.useStartTLS}"/>
The stack trace for the CAS to LDAP server connection is huge. Here is a small snippet. I can attach the whole thing if that is useful.
org.ldaptive.provider.ConnectionException:
javax.naming.CommunicationException: ldap.url.com:389 [Root exception
is java.net.UnknownHostException: ldap.url.com
I toggle between JDBC and LDAP/AD Handlers. Ensure that you comment out your ldap handler under:
deployerConfigContext.xml
xpath:
/beans
/bean[class=org.jasig.cas.authentication.AuthenticationManagerImpl]
/property[name=authenticationHandlers]
/list/
We satisfactorily resolved this by disabling this log4j property in the log4j configuration file in CAS:
<Logger name="org.ldaptive.pool.BlockingConnectionPool" level="debug">
<AppenderRef ref="console" />
</Logger>
Another option may have been to create a log4j filter and target the particular message that was causing the tomcat file to become huge.

Apache Jmeter JDBC connection issue - JDBC driver class not found

I am trying to connect to PL/SQL 8.0.4.1514 through JMeter.
In JDBC connection configuration ,I have provided the database URL as "jdbc:oracle:thin:#//01HW552780:6129))/tnsfile" and JDBC driver class as "com.plsql.jdbc.Driver"
But getting error as "No suitable driver found for jdbc:oracle:thin:#//01HW552780:6129))/tnsfile"
Could someone rectify me here regarding driver class?
I believe that you need oracle.jdbc.OracleDriver class instead.
I believe that you need to remove // from your JDBC URL
I'm not too sure regarding tnsfile (unless it is you real oracle database name) as Oracle JDBC URL takes forms:
jdbc:oracle:thin:#host:port /databaseName
jdbc:oracle:thin:#host:port :serviceName
Relevant driver can be downloaded from Oracle website or alternatively (better) take it from $ORACLE_HOME/jdbc/ folder on the machine where Oracle lives
See The Real Secret to Building a Database Test Plan With JMeter guide for more configuration and usage details for the JDBC Sampler.
Faced the same problem.
I used oracle.jdbc.OracleDriver as Driver Class.
No need to remove //. It can be present.
In database URL, it should be jdbc:oracle:thin:#//MachineName:Port/Schema
Download or better copy JDBC Jars from your DB installation and paste it under Jmeter/lib path.
For example, I presume you DB as Oracle 12c, it required ojdbc6.jar and ojdbc7.jar copied and pasted under Jmeter/lib folder.
After this activity, the problem vanished away for me.

how to fix Javax. Naming.exception: nameNotFoundException <my_JNDI_name> not found

I got this exception while trying to deploy ejb-jar file on a glassfish 2.1 :
Javax. Naming.exception: nameNotFoundException not found.
This drive me to be crazy !!!
I don't know why i got this exception while when i launch the hole application (ear) using Netbeans 6.7.1 with integrated glassfish 2.1 it work like magic !
But when i try to deploy it manually under another glassfish in an other pc it does not work
And i am having this exception when i try to deploy it
So i think that the ejb module does not find out how to link to the database
So it must be something that the netbeans do and i am not, when deploying the ejb-jar
Any help ?
I realise this is a bit old, but having just worked through this, I thought I may as well document it here.
For me the issue was the database connection. In your project you should have a persistence.xml file (mine was in the EJB project), which details the database connection parameters. I was using a localhost URL, but when I ran the database project, I noticed in my Services tab under Glassfish that no database connection was being registered.
Here's what I did:
Create a new database connection (right click in Services, Java DB node)
In Services, right click Java DB connection, Properties, check that the pool it's registered to is in the Glassfish JDBC Connection Pools and is the correct one, if not, make sure your database connection is correct, update persistence.xml
Clean the project before running again
This worked for me, hope it's helpful for someone else.

Tomcat 6.x JDBC realm, classpath for driver problem

I've set up a JDBC Realm in my META-INF/Context.xml as shown below, and that works.
The trouble is the JDBC driver now have to be placed under $CATALINA_HOME/lib/
Is there any way I can get that realm to load the jdbc driver from elsewhere, such as WEB-INF/lib/ in my webapp ?
META-INF/Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.postgresql.Driver"
connectionURL="jdbc:postgresql://daemon/testdb"
userTable="users" userNameCol="userName" userCredCol="password"
connectionPassword="xxxxx"
connectionName="xxxxx"
userRoleTable="users" roleNameCol="role"
digest="MD5"/>
</Context>
I'm pretty sure you can't do that, no. The Realm exists and is managed outside of the scope of any application. Consider the case where two webapps were deployed, for example, with conflicting drivers.
If you need to keep your JDBC driver inside your WAR, then you'll need to do the security management there also, rather than relying on tomcat to do it for you.
I'm not saying I WOULD do this, but I'm sure you could. Check the catalina.sh (or .bat), in there they set up the classpath, if you add the driver JAR in your webapp to the Tomcat classpath then I don't see why you couldn't use the driver in your Realm. I've never tried this, but I don't see why it would not work.
Tried this and it doesnt wrk. Tomcat complains of a ClassNotFound for the referenced jar, even though the refereced jar is present under on on the project's WEB_INF/lib folder.