JNDI with JMS in jdeveloper 11g - jms

I'm trying to start JMS application from OAS 10.1.2 to BeaWebLogic 11g
but there is a problem locating the JMS JNDI's.
When I start the server this exception is thrown:
weblogic.application.ModuleException: Could not setup environment
at weblogic.servlet.internal.WebAppModule.activateContexts(WebAppModule.java:1495)
at weblogic.servlet.internal.WebAppModule.activate(WebAppModule.java:438)
at weblogic.application.internal.flow.ModuleStateDriver$2.next(ModuleStateDriver.java:375)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.flow.ModuleStateDriver.activate(ModuleStateDriver.java:95)
Truncated. see log file for complete stacktrace
Caused By: javax.naming.NamingException: Cannot bind null object to jndi with name jms/TopicJNDI
at weblogic.jndi.internal.BasicNamingNode.bind(BasicNamingNode.java:311)
at weblogic.jndi.internal.WLEventContextImpl.bind(WLEventContextImpl.java:277)
at weblogic.deployment.EnvironmentBuilder.addConnectorRef(EnvironmentBuilder.java:277)
at weblogic.deployment.EnvironmentBuilder.addResourceReferences(EnvironmentBuilder.java:169)
at weblogic.servlet.internal.CompEnv.activate(CompEnv.java:138)
Truncated. see log file for complete stacktrace
The jndi which I have mapped in the BWL console is jms/Topic.
I recieved this error on server start up:
<An entity of type "ConnectionFactories" withname "Demo Topic Connection Factory" in JMS module "jmsModule" is not targeted. There is no sub-deployment with name "Demo Topic Connection Factory" in the configuration repository (config.xml), and so this entity will not exist anywhere in the domain.>
Thanks in advance.

The answer of my question is here
Here is how I got it to work.
Add the following line to the weblogic.xml file.
<resource-description>
<res-ref-name>MyDataSourceRefName<res-ref-name>
<jndi-name>jdbc/MyDataSourceNameAsDefinedInWeblogic</jndi-name>
</resource-description>
Then add the following to your web.xml file
<resource-ref>
<description>Some description</description>
<res-ref-name>MyResourceRefName</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
After I did that, everything worked fine. Additionally, if you are trying to configure Spring to use this data source, add the following bean.
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>MyDataSourceRefName</value>
</property>
</bean>
Then use your data source a appropriate. I hope this helps.

Related

SpringBoot and IBM MQ connection properties not overrided on deploy

I've a SpringBoot App with a local configuration to connect and listen a local Queue
ibm:
mq:
queueManager: LOCAL_QM
channel: DEV.ADMIN.SVRCONN
connName: localhost(1414)
user: admin
password: passw0rd
user-authentication-m-q-c-s-p: false
When a I deploy the app with Gitlab CI some properties are overrided (with a war_name.xml file in ../tomcat/current/conf/Catalina/localhost/) like database connection properties and mq connection properties to listen a Developpement or Qualification environment queue.
But when the app start the database connection is OK but not the MQ connection (The app use the local connection properties defined in the application.yml file)
When I check the xml file on the remote server, the properties are override.
And when I use a tool like spring actuator, I have the right properties override with the specific env properties.
But in the logs: /tomcat/current/logs/catalina.out I can read that the app try to connect to the local queue manage : LOCAL_QM not the specific environment queue.
2021-05-11 12:19:23.484 ERROR 14483 --- [ntContainer#0-1] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination '***' - retrying using FixedBackOff{interval=5000, currentAttempts=16093, maxAttempts=unlimited}. Cause: JMSWMQ0018: Failed to connect to queue manager 'LOCAL_QM' with connection mode 'Client' and host name 'localhost(1414)'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE')
The properties are in the same xml file, it works for the database "spring.datasource" but not for MQ "ibm.mq"
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Environment name="spring.datasource.url" value="jdbc:postgresql://***:5432/**" type="java.lang.String"/>
<Environment name="spring.datasource.username" value="****" type="java.lang.String"/>
<Environment name="spring.datasource.password" value="****" type="java.lang.String"/>
<Environment name="ibm.mq.queueManager" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.channel" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.connName" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.user" value="***" type="java.lang.String"/>
<Environment name="ibm.mq.password" value="" type="java.lang.String"/>
</Context>
Any idea why the properties are not overrided ?
Thanks
This started out as a comment, but as I wrote it I suspected that you are missing the relevant ibm.mq properties. If you don't provide the following properties:
ibm.mq.queueManager
ibm.mq.channel
ibm.mq.connName
ibm.mq.user
ibm.mq.password
then they default to
ibm.mq.queueManager=QM1
ibm.mq.channel=DEV.ADMIN.SVRCONN
ibm.mq.connName=localhost(1414)
ibm.mq.user=admin
ibm.mq.password=passw0rd
ie. localhost.
The mq-jms-spring-boot-starter makes use of
import org.springframework.boot.context.properties.ConfigurationProperties;
#ConfigurationProperties(prefix = "ibm.mq")
to read the connection properties. In this module https://github.com/ibm-messaging/mq-jms-spring/blob/master/mq-jms-spring-boot-starter/src/main/java/com/ibm/mq/spring/boot/MQConfigurationProperties.java
So it relies on spring to make the properties prefixed with ibm.mq available to it. ie. As long as spring through #ConfigurationProperties knows how to handle the overrides it will make them available to mq-jms-spring-boot-starter.

NameNotFoundException when starting JBoss with an EAR using HornetQ ConnectionFactory via JNDI using Spring JMS

I'm trying to deploy an application (EAR) which has Spring JMS listeners, BlazeDS flex and HornetQ in Jboss EAP 6.2.4. When I deploy the application and try to start the server, I'm getting the below exception.
Caused by: javax.naming.NameNotFoundException: JmsXA -- service jboss.naming.context.java.JmsXA
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:241)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_80]
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_80]
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) [spring-context-3.0.7.RELEASE.jar:3.0.7.RELEASE]
I saw this thread with similar problem (https://stackoverflow.com/a/12278834/1326592) but this wouldn't work in my case as I dont have a SAR file in my application.
I'm looking up to the Queues and ConnectionFactory via jee
<jee:jndi-lookup id="connectionFactory" jndi-name="java:/JmsXA"/>
<jee:jndi-lookup id="RequestsQueue" jndi-name="java:/jms/queue/requestQueue"/>
Please suggest a solution of how to start the HornetQ in Jboss before deploying my application.
I found a solution for the above issue.
This got resolved after referring to the JNDI's via resource-ref in web.xml
<resource-ref id="ItftRequestsQueue">
<res-ref-name>requestQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Container</res-auth>
<lookup-name>java:/jms/queue/requestQueue</lookup-name>
</resource-ref>
and
referring to the resource-ref in my spring.xml as
<jee:jndi-lookup id="connectionFactory" jndi-name="connectionFactory"/>
<jee:jndi-lookup id="requestsQueue" jndi-name="requestQueue"/>

in spring : how to handle name not found exception in application-context.xml?

I am creating a spring project using Oracle and jboss server.
I have one bean in my application-context.xml.
<!-- Datasource for TaskManager -->
<jee:jndi-lookup id="tmTestDataSource"
jndi-name="test_datasource" expected-type="javax.sql.DataSource"/>
<bean id="tmTestJdbcTemplate" name="TmTestJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="tmTestDataSource" />
</bean>
If the 'test_datasource' JNDI (one datasource.xml file in jboss deployment folder, which contains db credentials like url, uid, password) inside the file found deployment is successfull, but if the file is not there then the deployment is failing.
I want to handle this exception so that deployment should not fail.
how I can do this. Can anybody provide me any solution.
Thanks.

Spring DataSource configuration using JNDI

I am having trouble configuring the dataSource bean using JNDI in the Spring applicationContext.xml file.
This is how my applicationContext.xml entry looks like:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myApp" expected-type="javax.sql.DataSource"/>
I have made an entry in web.xml:
<resource-env-ref>
<resource-env-ref-name>jdbc/myApp</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
<resource-env-ref>
Context.xml file in Tomcat:
<Resource
auth="Container"
factory="bitronix.tm.resource.ResourceObjectFactory"
name="jdbc/myApp" type="javax.sql.DataSource"
uniqueName="jdbc/myApp" />
With these configuration I keep getting this error on Tomcat console:
Caused by: javax.naming.NameNotFoundException: Name [jdbc/myApp] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:819)
at org.apache.naming.NamingContext.lookup(NamingContext.java:167)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
Please help me resolve this issue. It appears to me that the bitronix transaction factory in Context.xml is causing the issue.
You need to use a different jndi name, because in Tomcat all configured entries and resources are placed in the java:comp/env portion of the JNDI namespace and you need to specify that, as well:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/myApp" expected-type="javax.sql.DataSource"/>

No SQL connection

Recently I've decided to move from Common DBCP to Tomcat JDBC Connection Pool. I changed bean description (using spring 3.1 + hibernate 4 + tomcat) and was faced with the next issue on my web app start up:
HHH000342: Could not obtain connection to query metadata : com.mysql.jdbc.Driver
and then when I try to query db from my app I am getting:
23:04:40,021 WARN [http-bio-8080-exec-10] spi.SqlExceptionHelper:(SqlExceptionHelper.java:143) - SQL Error: 0, SQLState: null
23:04:40,022 ERROR [http-bio-8080-exec-10] spi.SqlExceptionHelper:(SqlExceptionHelper.java:144) - com.mysql.jdbc.Driver
I must have done something wrong with configuration so hibernate cannot obtain connection but do not see it. really appreciate if you can point me to the right direction.
here is piece of my datasource bean definition
<bean id="jdbcDataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy- method="close"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://127.0.0.1:3306/test"
p:username="root"
p:password="test"
p:defaultAutoCommit="false"
p:maxActive="100"
p:maxIdle="100"
p:minIdle="10"
p:initialSize="10"
p:maxWait="30000"
p:testWhileIdle="true"
p:validationInterval="60000"
p:validationQuery="SELECT 1"
p:timeBetweenEvictionRunsMillis="60000"
p:minEvictableIdleTimeMillis="600000"
p:maxAge="360000"
/>
and here is how I tie it with spring's session factory
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="jdbcDataSource" />...
Make sure you are using JDK 6. Using JDK5 might be one cause of this error.
However, there is a workaround to your problem, explained here.
after migration, I forgot to add lib tomcat-jdbc to my classpath :)
now it wroks

Resources