Cannot obtain JMS ConnectionFactory
gberish Jun 5, 2015 11:43 PMThe code below was supposed to be a simple learning exercise that attemped JMS with WildFly. But it wasn't. I couldn't get past getting a ConnectionFactory.
WildFly is running on my PC.
I run the java client from Eclipse Luna, also on my PC.
The WildFly properties (Servers Tab in Luna) show standalone-full.xml
The code is overkill out of frustration. I added a static String array to hold all the jndi names I tried. The main method just gets a context, and looks up all the names in the String array. And it prints out what it's doing.
I think I'm getting a context. But all jndi names fail. Although my 1st try -- which I read was the one that is supposed to work -- looks close.
Any help or direction would be appreciated.
CODE (output follows)
package org.america3.go.client.controller.messages;
import javax.jms.ConnectionFactory;
import javax.naming.Context;
import java.util.Properties;
import javax.naming.InitialContext;
public class SimpleTest2 {
static String[] factoryLookupNames = {
"jms/RemoteConnectionFactory",
"java:jboss/exported/jms/RemoteConnectionFactory",
"java:jboss/DefaultJMSConnectionFactory",
"java:/ConnectionFactory" };
static public void main (String args[]) {
Properties jndiProps = null;
Context ctx = null;
ConnectionFactory factory = null;
jndiProps = getjndiProperties ();
ctx = getContext (jndiProps);
// try all names
for (String factoryName : factoryLookupNames) {
factory = getFactory (ctx, factoryName);
if (factory != null) break;
}
}
static private Properties getjndiProperties () {
try {
Properties output = new Properties();
output.setProperty (Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
output.setProperty (Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
output.setProperty (Context.PROVIDER_URL, "http-remoting://localhost:8080/");
//This property is important for remote resolving
output.setProperty ("jboss.naming.client.ejb.context", "true");
//This property is not important for remote resolving
output.setProperty ("org.jboss.ejb.client.scoped.context", "true");
System.out.println("Local Connection Properties:");
for (Object key:output.keySet()) {
System.out.println("Key: " + (String) key + " Value: " + output.getProperty((String) key) );
}
return output;
}catch (Exception e) {
System.out.println("Error #1");
return null;
}
}
static private Context getContext (Properties jndiProps) {
try{
Context ctx = (Context) new InitialContext(jndiProps);
System.out.println("\nSuccessfully obtained a Local WildFly server context");
System.out.println(ctx);
return ctx;
} catch (Exception e) {
System.out.println("Error #2");
return null;
}
}
static private ConnectionFactory getFactory (Context ctx, String jndiName) {
try{
System.out.println("\nAttempting to lookup: " + jndiName);
ConnectionFactory rtnFactory = (ConnectionFactory) ctx.lookup(jndiName);
System.out.println("\nSuccessfully obtained ConnectionFactory from local WildFly server");
System.out.println(rtnFactory);
return rtnFactory;
} catch (Exception e) {
System.out.println("Exception Message: " + e.getMessage());
System.out.println("Exception Cause: " + e.getCause());
return null;
}
}
}
OUTPUT:
Local Connection Properties:
Key: java.naming.provider.url Value: http-remoting://localhost:8080/
Key: java.naming.factory.initial Value: org.jboss.naming.remote.client.InitialContextFactory
Key: jboss.naming.client.ejb.context Value: true
Key: java.naming.factory.url.pkgs Value: org.jboss.ejb.client.naming
Key: org.jboss.ejb.client.scoped.context Value: true
Jun 05, 2015 5:14:39 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.0.Final
Jun 05, 2015 5:14:39 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.0.Final
Jun 05, 2015 5:14:39 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.6.Final
Successfully obtained a Local WildFly server context
- javax.naming.InitialContext@6108b2d7
Attempting to lookup: jms/RemoteConnectionFactory
Jun 05, 2015 5:14:39 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
Jun 05, 2015 5:14:39 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@5700d6b1, receiver=Remoting connection EJB receiver [connection=Remoting connection <3310ea64>,channel=jboss.ejb,nodename=ace]} on channel Channel ID 92ba6449 (outbound) of Remoting connection 0f38d515 to localhost/127.0.0.1:8080
Jun 05, 2015 5:14:45 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000015: Initial module availability report for Remoting connection EJB receiver [connection=Remoting connection <3310ea64>,channel=jboss.ejb,nodename=ace] wasn't received during the receiver context association
Exception Message: jms/RemoteConnectionFactory -- service jboss.naming.context.java.jboss.exported.jms.RemoteConnectionFactory
Exception Cause: null
Attempting to lookup: java:jboss/exported/jms/RemoteConnectionFactory
Exception Message: jboss/exported/jms/RemoteConnectionFactory -- service jboss.naming.context.java.jboss.exported.jboss.exported.jms.RemoteConnectionFactory
Exception Cause: null
Attempting to lookup: java:jboss/DefaultJMSConnectionFactory
Exception Message: jboss/DefaultJMSConnectionFactory -- service jboss.naming.context.java.jboss.exported.jboss.DefaultJMSConnectionFactory
Exception Cause: null
Attempting to lookup: java:/ConnectionFactory
Exception Message: ConnectionFactory -- service jboss.naming.context.java.jboss.exported.ConnectionFactory
Exception Cause: null
END OF OUTPUT
In case it helps here is the stack trace from the 1st failure:
Stack Trace:
org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)
org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202)
org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)