What is correct JNDI name format for Remote Context.lookup() by remote Java Client?
gberish Aug 15, 2017 5:45 PMCan Anyone tell me why all of these JNDI names for a JMS Queue cause Context.lookup() to throw:
javax.naming.NameNotFoundException ?
I’m working to resurrect an old Eclipse-Luna/Wildfly-8 project with Eclipse-Neon/WildFly-10.
I know the strategy for Context.lookup() from a remote client (i.e. one outside the Wildfly container) has changed a lot over time.
I just can’t find the one I need to use today. These all fail.
java:/jms/queue/goSendToClientQueue
java:jboss/exported/jms/queue/goSendToClientQueueX
java:jboss/remote/jms/queue/goSendToClientQueueZ
Here’s what I pasted below:
-- The CLI console output when I added the Queues to standalone-full.xml.
-- The lines it added to standalone-full.xml.
-- The relevant part of my code leading up to the lookup().
-- The Eclipse Console output for one try that threw the NotFoundException
Note 1: I think Console confirms I have a valid InitialContext. Can lookup() a ConnectionFactory. Has a valid Connections. And valid Session.
Note 2: All runs have identical Console output except for the JNDI name that fails).
Note 3: In my code
P() is a helper method I use to simplify printing to System.out.
TK is a helper class that lets me put my InitialContext Properties in and external file.
Both let me make my Eclipse Console output easy to follow.
CLI Command Line Output to Set Up Queues:
-----
c) 2017 Microsoft Corporation. All rights reserved.
C:\ProgramFilesGeo\Wildfly\wildfly-10.1.0.Final\bin>jboss-cli.bat
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9990 /] /subsystem=messaging-activemq/server=default/jms-queue=goSendToClientQueue:add(entries=[java:/jms/qu
eue/goSendToClientQueue])
{"outcome" => "success"}
standalone@localhost:9990 /] /subsystem=messaging-activemq/server=default/jms-queue=goSendToClientQueueX:add(entries=[java:jboss/
exported/jms/queue/goSendToClientQueueX])
{"outcome" => "success"}
[standalone@localhost:9990 /] /subsystem=messaging-activemq/server=default/jms-queue=goSendToClientQueueZ:add(entries=[java:jboss/
remote/jms/queue/goSendToClientQueueZ])
{"outcome" => "success"}
[standalone@localhost:9990 /]
-----
FROM standalone-full.xml
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
<server name="default">
...
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<jms-queue name="goSendToClientQueue" entries="java:/jms/queue/goSendToClientQueue"/>
<jms-queue name="goSendToClientQueueX" entries="java:jboss/exported/jms/queue/goSendToClientQueueX"/>
<jms-queue name="goSendToClientQueueZ" entries="java:jboss/remote/jms/queue/goSendToClientQueueZ"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
</server>
</subsystem>
MY CODE:
public void run () {
...
P(iAmM + "beg");
try {
//get InitialContext Properties
P(s + iAmM + "Requesting InitialContext");
Properties env = TK.getEnvironmentVariablesFor(LOCAL);
//print InitialContext Properties
P(TK.printInitialContextProperties(LOCAL));
//get InitialContext Properties
Context ctx = new InitialContext(env);
P(s + iAmM + "InitialContext : OK - " + ctx);
//Check InitalContext
P(s + iAmM + "List InitialContext NameClassPairs");
NamingEnumeration<NameClassPair> list = ctx.list("");
int ctr = 0;
while (list.hasMoreElements()) {
ctr++;
NameClassPair next = list.next();
String name = next.getName();
String className = next.getClassName();
String sx = "000" + ctr;
P(s + iAmM + " [" + ("000" + sx).substring(sx.length()) + "] " + name + " - " + className);
}
P(s + iAmM + "End List InitialContext NameClassPairs");
// get ConnectionFactory
P(s + iAmM + "Lookingup ConnectionFactory");
ConnectionFactory factory = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
P(s + iAmM + "ConnectionFactory: Ok - " + factory );
// get JMS connection
P(s + iAmM + "Instantiating Connection");
this.jmsConnection = factory.createConnection("appUser", "appUser9#");
P(s + iAmM + "JMS Connection : " + this.jmsConnection);
// get Session
this.jmsSession = this.jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
P(s + iAmM + "JMS Session : " + jmsSession);
// get Queue
String recQueueJNDIName = SetupTK.getStringProperty("SendToClientQueue");
P(s + iAmM + "Lookup Queue w/ JNDI name: [\"" + recQueueJNDIName + "\"]");
Queue jmsReceiveFmQueue = (Queue) ctx.lookup(recQueueJNDIName);
//THROWS ERROR
ECLIPSE CONSOLE OUTPUT
MsgCenterReceive.run () beg
MsgCenterReceive.run () Requesting InitialContext
CONNECTION VARIABLES
key: java.naming.provider.url
value: http-remoting://localhost:8080
key: java.naming.factory.initial
value: org.jboss.naming.remote.client.InitialContextFactory
key: java.naming.security.principal
value: appUser
key: java.naming.security.credentials
value: appUser9#
MsgCenterReceive.run () InitialContext: OK - javax.naming.InitialContext@646d64ab
MsgCenterReceive.run () List InitialContext NameClassPairs
MsgCenterReceive.run () [001] jms - javax.naming.Context
MsgCenterReceive.run () End List InitialContext NameClassPairs
MsgCenterReceive.run () Lookingup ConnectionFactory
MsgCenterReceive.run () ConnectionFactory: Ok - ActiveMQConnectionFactory [serverLocator=ServerLocatorImp ... + around 20 more lines of properties]
MsgCenterReceive.run () Instantiating Connection
MsgCenterReceive.run () JMS Connection : org.apache.activemq.artemis.jms.client.ActiveMQConnection@24313fcc
MsgCenterReceive.run () JMS Session : ActiveMQSession->ClientSessionImpl [name=d6fcde0c ...]@7d20d0b
MsgCenterReceive.run () Lookup Queue w/ JNDI name: ["java:jboss/remote/jms/queue/goSendToClientQueueZ"]
MsgCenterReceive.run () caught: javax.naming.NameNotFoundException
MsgCenterReceive.run () : jboss/remote/jms/queue/goSendToClientQueueZ -- service jboss.naming.context.java.jboss.exported.jboss.remote.jms.queue.goSendToClientQueueZ
- MsgCenterReceive.run () end