I am trying to get oracle connection from hibernate. below is the code that I am using.
server.xml
<library id="jdbcDriverFiles">
<fileset dir="libraries" includes="ojdbc7.jar" />
</library>
<dataSource id="x" jndiName="jndisce"
statementCacheSize="20" type="javax.sql.DataSource">
<containerAuthData password="Pwd" user="User" />
<jdbcDriver javax.sql.DataSource="oracle.jdbc.pool.OracleDataSource" libraryRef="jdbcDriverFiles" />
<connectionManager agedTimeout="600"
connectionTimeout="180" maxIdleTime="1800" maxPoolSize="70"
minPoolSize="1" purgePolicy="EntirePool" reapTime="180" />
<properties.oracle
URL="url"
password="Pwd" portNumber="123" serverName="server"
user="User" />
</dataSource>
<webApplication id="cm" location="cm.war"
name="cm">
<classloader commonLibraryRef="jdbcDriverFiles" />
</webApplication>
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jndisce");
Connection conn = ds.getConnection();
OracleConnection con = conn.unwrap(OracleConnection.class);
and below is the error that I am getting.
java.sql.SQLException: DSRA9122E: com.ibm.ws.rsadapter.jdbc.v41.WSJdbc41Connection#7acaddcd does not
wrap any objects of type oracle.jdbc.OracleConnection.
This has nothing to do with Hibernate, you are not even using a Hibernate API here. You are trying to unwrap an OracleConnection from a IBM datasource connection but apparently it does not let you do this. According to the following article, this might be due to class loader issues: how to unwrap PostgreSQL connection from the IBM WSJdbc41Connection
Related
I wrote a simple program to connect to a DB using a spring bean from inside Docker or WSl2. It connects fine.
The moment I add a broker tag to the XML it fails with error.
NOTE : the 'broker' tag, even when added as empty, commenting everything out, causes the same issue.
Below is my program and the bean XML
public class TestDB {
public static void main(String[] args) {
Connection connection1 = null, connection2 = null;
try (ConfigurableApplicationContext mContext = new ClassPathXmlApplicationContext("test.xml");) {
String jdbcClassName="oracle.jdbc.OracleDriver";
String url="jdbc:oracle:thin:#xyz.company.com:1521:abc";
String user="TEST_DB";
String password="test";
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(jdbcClassName);
ds.setUrl(url);
ds.setUsername(user);
ds.setPassword(password);
connection1 = ds.getConnection();
BasicDataSource ds2 = (BasicDataSource) mContext.getBean("application-ds");
connection2 = ds2.getConnection();
}
catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection1!=null) {
System.out.println("Connected successfully.");
try {
connection1.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection2!=null) {
System.out.println("Connected via bean.");
try {
connection2.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
Here is the test.xml:
<beans .....>
<broker xmlns="http://activemq.apache.org/schema/core" persistent="true" brokerName="ABC_MESSAGING_SERVER" advisorySupport="false" useJmx="false">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue="my_account" />
</policyEntries>
</policyMap>
</destinationPolicy>
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#application-ds"/>
</persistenceAdapter>
</broker>
<bean id="application-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#xyz.company.com:1521:abc" />
<property name="username" value="TEST_DB" />
<property name="password" value="test" />
<property name="maxActive" value="200" />
<property name="poolPreparedStatements" value="true" />
</bean>
</beans>
The output, with the broker part commented is:
and with broker :
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-01017: invalid username/password; logon denied)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at TestDB.main(TestDB.java:29)
Caused by: java.sql.SQLException: ORA-01017: invalid username/password; logon denied
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:456)
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:451)
at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:1040)
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:552)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:501)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1292)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:1025)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:57)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:747)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:562)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
I am answering my own question.
The problem was my Database was version Oracle 12.2.0.1 and my ojdbc jar was ojdbc8-19.3.0.0.
It did not matter when testing on widnows or linux machines.
However using it alongside activemq broker in WSL2 or Docker (virtual envs basically) then it caused 'Invalid username password logon error'.
had to replace the jar with ojdbc8-12.2.0.1 on client side
Setting up listener using IBM MQ in eclipse using wlp for java springboot application
Hi, I am trying to set up listener using wlp in my local in eclipse,
following is the code :
pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0</version>
</dependency>
java class:
#JmsListener(containerFactory = "jmsListenerContainerFactory", destination = test.queue)
public void recieve(Message message) {
log.info("inside message receiver");
try {
if (message instanceof TextMessage) {
message.acknowledge();
String json = ((TextMessage) message).getText();
/** To solve Json injection fortify issue **/
String sanitisedJsonMessage = JsonSanitizer.sanitize(json);
Gson gson = new Gson();
//business logic
} else {
log.error("ERROR ::: invalid message type");
message.acknowledge();
}
} catch (JsonSyntaxException | JMSException ex) {
log.error("ERROR: " + ex + ex.getMessage());
}
}
#Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
ConnectionFactory connectionfactory;
DefaultJmsListenerContainerFactory listenerFactory;
try {
log.info("inside listener factory");
#Cleanup
Context context = null;
listenerFactory = new DefaultJmsListenerContainerFactory();
context = new InitialContext();
connectionfactory = (ConnectionFactory) context.lookup(jms/ConnectionFactory);
listenerFactory.setConnectionFactory(connectionfactory);
listenerFactory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
} catch (NamingException ex) {
log.error("ERROR: error looking up queue connection factory jndi {}", ex);
}
return listenerFactory;
}
Now I tried to set up my server.xml in wlp as per ibm guidelines as follows:
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>javaee-7.0</feature>
<feature>jndi-1.0</feature>
<feature>jaxws-2.2</feature>
<feature>localConnector-1.0</feature>
<feature>transportSecurity-1.0</feature>
<feature>servlet-3.1</feature>
<feature>mdb-3.2</feature>
<feature>wmqJmsClient-2.0</feature>
<feature>jsp-2.3</feature>
</featureManager>
<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
<user name="admin" password="adminpwd" />
<user name="nonadmin" password="nonadminpwd" />
</basicRegistry>
<!-- Assign 'admin' to Administrator -->
<administrator-role>
<user>admin</user>
</administrator-role>
<keyStore id="defaultKeyStore" password="Liberty" />
<httpEndpoint host="*" httpPort="9081" httpsPort="9444"
id="defaultHttpEndpoint" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true" />
<applicationMonitor updateTrigger="mbean" />
<enterpriseApplication
id="mqtest-ear"
location="mqtest-ear.ear"
name="mqtest-ear" />
<variable name="wmqJmsClient.rar.location"
value="path\to\wlp\wmq\wmq.jmsra.rar" />
<jmsQueueConnectionFactory
jndiName="jms/ConnectionFactory">
<properties.wmqJms transportType="CLIENT"
hostName="<test.correcthostname>" port="<test.correctportname>"
channel="<test.correctchannelname>" queueManager="<test.correctqmgrname>" useSSL="true"
headerCompression="SYSTEM" messageCompression="RLE"
sslCipherSuite="SSL_RSA_WITH_AES_256_CBC_SHA256"
targetClientMatching="true" />
<connectionManager></connectionManager>
</jmsQueueConnectionFactory>
<jmsQueue id="JMSQueue" jndiName="jms/InQueue">
<properties.wmqJms baseQueueName="test.queue"
baseQueueManagerName="<test.correctqmgrname>" receiveConversion="CLIENT_MSG"
putAsyncAllowed="DESTINATION" targetClient="MQ"
readAheadAllowed="ENABLED" />
</jmsQueue>
<!-- <resourceAdapter
location="${wmqJmsClient.rar.location}" id="resourceAdapter">
</resourceAdapter> -->
<keyStore id="keyAndTrustStore" password="password"
location="path\to\keyandtruststore"
type="PKCS12">
</keyStore>
I have downloaded latest resource adapter and 9.0.0.8-IBM-MQ-Java-InstallRA.jar,
When I run the application , I get constant error:
2020-01-10 11:21:16 ERROR o.s.j.l.DefaultMessageListenerContainer - Could not refresh JMS Connection for destination 'test.queue' - retrying using FixedBackOff{interval=5000, currentAttempts=12, maxAttempts=unlimited}. Cause: MQJCA1011: Failed to allocate a JMS connection.
what Can I do to make listener work
After trying and troubleshoting a lot, I found a solution to set up ibm mq message listener using springboot and jms locally in websphere liberty server version 19.0.0.6.
I used following steps to make listener work:
download resource adaptor 9.0.0.8-IBM-MQ-Java-InstallRA.jar
Run the jar, and a folder named wmq will be generated with required .rar file in it.
Place the wmq folder inside wlp server : path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer
if using keystores for ssl , place trust and key store .jks or .p12 file inside wlp server path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\resources\security
create a new file name jvm.options with following details:
-Dcom.ibm.mq.cfg.useIBMCipherMappings=false
-Djavax.net.debug="all"
-Djdk.tls.client.protocols="TLSv1.2"
-Dhttps.protocols="TLSv1.2"
-Djavax.net.ssl.trustStore="path\to\keyandtruststore.jks"
-Djavax.net.ssl.trustStorePassword="secret"
-Djavax.net.ssl.keyStore="path\to\keyandtruststore.jks"
-Djavax.net.ssl.keyStorePassword="secret"
save file inside following location : path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer
now add required dependencies in pom.xml
I am using spring boot version 2.1.4.release and following are important dependecies which will be required:
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq-jms-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
now change the wlp server.xml as follows:
<!-- Enable features -->
<featureManager>
<feature>webProfile-8.0</feature>
<feature>localConnector-1.0</feature>
<feature>jndi-1.0</feature>
<feature>jaxws-2.2</feature>
<feature>transportSecurity-1.0</feature>
<feature>wmqJmsClient-2.0</feature>
<feature>jsp-2.3</feature>
<feature>servlet-4.0</feature>
<feature>jms-2.0</feature>
<feature>javaee-8.0</feature>
</featureManager>
<!-- Define an Administrator and non-Administrator -->
<basicRegistry id="basic">
<user name="admin" password="adminpwd"/>
<user name="nonadmin" password="nonadminpwd"/>
</basicRegistry>
<!-- Assign 'admin' to Administrator -->
<administrator-role>
<user>admin</user>
</administrator-role>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<variable name="wmqJmsClient.rar.location" value="path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\wmq\wmq.jmsra.rar"/>
<jmsQueueConnectionFactory jndiName="jms/ConnectionFactory" id="QueueConnectionFactory ">
<properties.wmqJms channel="channelName" headerCompression="NONE" hostName="host name" messageCompression="RLE" port="1414" queueManager="qmgrName" sslCipherSuite="TLS_RSA_WITH_AES_256_CBC_SHA256" targetClientMatching="true" transportType="CLIENT" temporaryModel="SYSTEM.DEFAULT.MODEL.QUEUE" pollingInterval="5s" rescanInterval="5s"/>
<connectionManager connectionTimeout="180s" maxPoolSize="20" minPoolSize="1" reapTime="180s" agedTimeout="0" maxIdleTime="30m"/>
</jmsQueueConnectionFactory>
<jmsQueue id="JMSQueue" jndiName="jms/testInQueue">
<properties.wmqJms putAsyncAllowed="DISABLED" readAheadAllowed="ENABLED" receiveConversion="CLIENT_MSG" targetClient="JMS" baseQueueName="queueName" baseQueueManagerName="qmgrName" failIfQuiesce="true" persistence="APP"/>
</jmsQueue>
<!-- <wmqJmsClient nativeLibraryPath="C:\Users\n78724\CRAS\resource adapter\lib"/> -->
<resourceAdapter id="resourceAdapter"
location="${wmqJmsClient.rar.location}">
<customize></customize>
</resourceAdapter>
<ssl id="keyAndTrustStore" keyStoreRef="defaultKeyStore" sslProtocol="TLSv1.2" trustStoreRef="defaultTrustStore"/>
<keyStore id="defaultKeyStore" location="path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\resources\security\keyandtruststore.jks" password="secret"/>
<keyStore id="defaultTrustStore" location="path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\resources\security\keyandtruststore.jks" password="secret"/>
<enterpriseApplication id="Test-ear" location="Test-ear.ear" name="Test-ear"/>
start the server
hope it helps.
Good morning to everyone,
I have a big issue to run a job in Mule ESB. I'm trying to map an CSV file in a table of an oracle database. To do that, I created a JDBC Connector with a Oracle DataSource and the Connection Test is Valid. But if i run The Job an error Message appears.
[Error Message]
-------------------------------------
ERROR 2015-06-17 09:01:26,223 [[....].connector.file.mule.default.receiver.01] org.mule.exception.DefaultMessagingExceptionStrategy:
******************************************************************************
Message : com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[jdbc:oracle:thin:#.....:....:.......]:user[......]. (java.lang.RuntimeException). Message payload is of type: ReceiverFileInputStream
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot load class 'oracle.jdbc.OracleDriver' (java.lang.ClassNotFoundException)
org.mule.module.launcher.application.CompositeApplicationClassLoader:74 (null)
2. Cannot create JDBC driver 'Oracle'. Cannot find class. (org.jetel.exception.ComponentNotReadyException)
org.jetel.connection.jdbc.driver.JdbcDriverImpl:188 (null)
3. Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[.......]. (org.jetel.exception.ComponentNotReadyException)
org.jetel.graph.TransformationGraph:413 (null)
4. Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[...........]. (com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException)
com.mulesoft.mule.module.datamapper.clover.impl.graphfactory.DocumentCloverGraphFactoryImpl:59 (null)
5. com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[............]:user[.....]. (java.lang.RuntimeException)
com.mulesoft.mule.module.datamapper.clover.impl.graphprovider.PoolGraphProvider:109 (null)
6. com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[..............]. (java.lang.RuntimeException). Message payload is of type: ReceiverFileInputStream (org.mule.api.MessagingException)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassNotFoundException: Cannot load class 'oracle.jdbc.OracleDriver'
at org.mule.module.launcher.application.CompositeApplicationClassLoader.loadClass(CompositeApplicationClassLoader.java:74)
at org.jetel.util.classloader.GreedyURLClassLoader.loadClassGreedy(GreedyURLClassLoader.java:137)
at org.jetel.util.classloader.GreedyURLClassLoader.loadClass(GreedyURLClassLoader.java:111)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
******************************************************************************
Do I have to put the driver "ojdbc7.jar" in a specific directory?
What it looks like you have configured oracle.jdbc.OracleDriver instead of oracle.jdbc.driver.OracleDriver
You can configure the following example :-
<spring:beans>
<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<spring:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<spring:property name="url" value="jdbc:oracle:thin:#192.168.28.129:1521:xe"/>
<spring:property name="username" value="yourUserName"/>
<spring:property name="password" value="yourPassword"/>
<spring:property name="removeAbandoned" value="true"/>
<spring:property name="initialSize" value="10"/>
<spring:property name="maxActive" value="50"/>
</spring:bean>
</spring:beans>
<db:generic-config name="Database_Configuration" dataSource-ref="dataSource" doc:name="Generic Database Configuration" />
<flow name="mainFlow">
<http:listener config-ref="httpListenerConfig" path="/*" doc:name="HTTP" allowedMethods="GET"/>
///////////////////////////////////////
Your Code
////////////////////////////////////
<db:select config-ref="Database_Configuration" doc:name="Database">
<db:parameterized-query><![CDATA[select * from yourtableName]]></db:parameterized-query>
</db:select>
</flow>
You need to configure and change as per your ip, username, password etc
Add commons-dbcp-1.2.2.jar or other version and ojdbc6.jar in your classpath as dependancy
Trying to get my Liberty profile server to create a transacted jmsConnectionFactory to my instance of Websphere message queue.
Liberty profile v 8.5.5.5
Websphere MQ 7.x
I've tried to change the jmsQueueConnectionFactory to jmsXAQueueConnectionFactory but it does not help -> Then it seems to just ignore it and doesn't connect to the MQ
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>wmqJmsClient-1.1</feature>
<feature>jndi-1.0</feature>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<variable name="wmqJmsClient.rar.location" value="D:\wlp\wmq\wmq.jmsra.rar"/>
<jmsQueueConnectionFactory jndiName="jms/wmqCF" connectionManagerRef="ConMgr6">
<properties.wmqJms
transportType="CLIENT"
hostName="hostname"
port="1514"
channel="SYSTEM.DEF.SVRCONN"
queueManager="QM"
/>
</jmsQueueConnectionFactory>
<connectionManager id="ConMgr6" maxPoolSize="2"/>
<applicationMonitor updateTrigger="mbean"/>
<application id="App"
location="...\app.war"
name="App" type="war"/>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443"/>
</server>
log
2015-04-23 17:07:14,981 [JmsConsumer[A0]] WARN ultJmsMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'A0' - trying to recover. Cause: Could not commit JMS transaction; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: JMSCC0014: It is not valid to call the 'commit' method on a nontransacted session. The application called a method that must not be called on a nontransacted session. Change the application program to remove this behavior.
2015-04-23 17:07:14,983 [JmsConsumer[A0]] INFO ultJmsMessageListenerContainer - Successfully refreshed JMS Connection
Camel code
public static JmsComponent mqXAComponentTransacted(InitialContext context, String jndiName) throws JMSException, NamingException {
return JmsComponent.jmsComponentTransacted((XAQueueConnectionFactory) context.lookup(jndiName));
}
Ended up with:
public static JmsComponent mqXAComponentTransacted(InitialContext context, String connectionFactoryJndiName, String userTransactionJndiName) throws JMSException, NamingException {
LOG.info("Setting up JmsComponent using jndi lookup");
final JtaTransactionManager jtaTransactionManager = new JtaTransactionManager((UserTransaction) context.lookup(userTransactionJndiName));
final ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryJndiName);
final JmsComponent jmsComponent = JmsComponent.jmsComponentTransacted(connectionFactory, (PlatformTransactionManager) jtaTransactionManager);
jmsComponent.setTransacted(false);
jmsComponent.setCacheLevel(DefaultMessageListenerContainer.CACHE_NONE);
return jmsComponent;
}
I'm having difficulty getting a JDBC DataSource using Tomcat 7
javax.naming.NameNotFoundException: Name [jdbc/weblogin01b] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.naming.factory.ResourceLinkFactory.getObjectInstance(ResourceLinkFactory.java:92)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
at org.apache.naming.NamingContext.lookup(NamingContext.java:841)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.NamingContext.lookup(NamingContext.java:829)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
In CATALINA_BASE/conf/server.xml
I have included a variety of slightly different resources
all aiming to be the same connection hopefully one of them will be right:
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource name="jdbc/weblogin01"
username="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.pool.OracleDataSource"
description="Global Address Database"
url="jdbc:oracle:thin:#10.15.120.29:1522:DGSPC"
maxActive="15"
maxIdle="3" />
<Resource name="jdbc/weblogin01b"
user="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:#10.15.120.29:1522:DGSPC"
maxActive="20"
maxIdle="3"
maxWait="-1" />
<Resource name="jdbc/weblogin01c"
user="weblogin01"
password="xxxxx"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#10.15.120.29:1522:DGSPC"
maxActive="20"
maxIdle="3"
maxWait="-1" />
</GlobalNamingResources>
In META-INF/context.xml
I have a ResourceLink to each resource
<Context antiJARLocking="true" path="/testDbAccess">
<ResourceLink name="jdbc/weblogin01"
global="jdbc/weblogin01"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/weblogin01b"
global="jdbc/weblogin01b"
type="javax.sql.DataSource"/>
<ResourceLink name="jdbc/weblogin01c"
global="jdbc/weblogin01c"
type="javax.sql.DataSource"/>
</Context>
In web.xml I made no changes related to JDBC on the understanding that
the ResourceLink elements will be sufficient.
In Java code I try to get a DataSource as follows:
String dbUser = "weblogin01b";
try {
// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
// Look up our data source
ds = (DataSource) envCtx.lookup("jdbc/" + dbUser);
if (ds == null) {
logger.log(Level.WARNING,"Null datasource for " + dbUser);
}
}
Given the exception above, it never gets a DataSource, this is the same for:
jdbc/weblogin01
jdbc/weblogin01b
jdbc/weblogin01c
I'm finding Tomcat an uphill struggle, any help would be much appreciated.
Part 1 of the puzzle is solved:
I was editing the wrong copy of server.xml
I am running Tomcat under NetBeans which makes a separate copy of CATALINA_HOME which it configures as CATALINA_BASE, I had not noticed the separate copy.
I wish Tomcat's CATALINA_HOME and CATALINA_BASE were always separate and distinctly different, i.e. no duplication of files.
Part 2 is a different story:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
I know that I've specified the correct username and password but I'm not seeing these values logged anywhere, I'm guessing that I've specified the correct values in the wrong properties.
Part 2 of the puzzle is solved:
That should be:
username="weblogin01"
NOT
user="weblogin01"