I'm running into a problem while trying to send an xml message to a JMS queue via jndi lookup on Liberty 20.0.0.1.
My server.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<server description="Default server">
<featureManager>
<feature>el-3.0</feature>
<feature>localConnector-1.0</feature>
<feature>monitor-1.0</feature>
<feature>restConnector-2.0</feature>
<feature>jacc-1.5</feature>
<feature>servlet-4.0</feature>
<feature>jndi-1.0</feature>
<feature>concurrent-1.0</feature>
<feature>requestTiming-1.0</feature>
<feature>ssl-1.0</feature>
<feature>jdbc-4.0</feature>
<feature>cdi-2.0</feature>
<feature>jms-2.0</feature>
<feature>jaxrs-2.1</feature>
<feature>ejbLite-3.2</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint"
host="*"
httpPort="9080"
httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files-->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
<messagingEngine>
<queue id="jmsQueue" forceReliability="ReliablePersistent" maxMessageDepth="5000"></queue>
</messagingEngine>
<jmsQueueConnectionFactory jndiName="jms/JMS_CF" connectionManagerRef="ConMgr">
<properties.wasJms
nonPersistentMapping="ExpressNonPersistent"
persistentMapping="ReliablePersistent"/>
</jmsQueueConnectionFactory>
<connectionManager id="ConMgr" maxPoolSize="10"/>
<jmsQueue id="jms_StockQueue" jndiName="jms/STOCK_JMS_QUEUE">
<properties.wasJms queueName="stockQueue"
deliveryMode="Application"
timeToLive="500000"
priority="1"
readAhead="AsConnection" />
</jmsQueue>
<jmsActivationSpec id="core_indexing/jms-mdb/StockMDB">
<properties.wasJms destinationRef="jms_StockQueue" />
</jmsActivationSpec>
</server>
and my Java (non-ejb class) code is:
final InitialContext context = new InitialContext();
final QueueConnectionFactory qcf = (QueueConnectionFactory) context.lookup("jms/JMS_CF");
final Queue destination = (Queue) context.lookup("jms/STOCK_JMS_QUEUE");
queueConnection = qcf.createQueueConnection();
queueSession = queueConnection.createQueueSession(false, 0);
final ObjectMessage message = queueSession.createObjectMessage(object);
queueSender = queueSession.createSender(destination);
queueSender.send(message);
However when I run tests against this in-container code I'm getting:
Intermediate context does not exist: jms/JMS_CF
javax.naming.NameNotFoundException: Intermediate context does not exist: jms/JMS_CF
at com.ibm.ws.jndi.internal.ContextNode.getTargetNode(ContextNode.java:125) ~[?:?]
at com.ibm.ws.jndi.internal.ContextNode.lookup(ContextNode.java:211) ~[?:?]
at com.ibm.ws.jndi.internal.WSContext.lookup(WSContext.java:306) ~[?:?]
at com.ibm.ws.jndi.WSContextBase.lookup(WSContextBase.java:61) ~[?:?]
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161) ~[?:?]
at javax.naming.InitialContext.lookup(InitialContext.java:428) ~[?:1.8.0]
If I change the Java code so that the connection factory lookup is done with @Resource i.e.
@Resource(lookup = "jms/JMS_CF")
private QueueConnectionFactory queueConnectionFactory;
the error is:
[ERROR ] SRVE0315E: An exception occurred: java.lang.Throwable:
javax.ejb.EJBException: CWNEN0030E: The server was unable to obtain an object
instance for the
java:comp/env/com.xyz.www.stock.api.ws.StockWS/queueConnectionFactory
reference. The exception message was: CWNEN1003E: The server was unable to
find the jms/JMS_CF binding with the javax.jms.QueueConnectionFactory type
for the java:comp/env/com.xyz.www.stock.api.ws.StockWS/queueConnectionFactory
reference.
Replacing jms-2.0 with wasJmsServer-1.0 and wasJmsClient-2.0 gets rid of the JNDI lookup error but the MDB won't activate.