I’ve failed for over a week to learn enough JBoss/Wildfly 10 to write a java class that could obtain a JMS connection to Wildfly. Can anyone point me in the right direction?
The class is executed on Eclipse running on the same computer as Wildfly. (technically it’s a remote connection?)
The error is:
javax.naming.CommunicationException
Failed to connect to any server.
Servers tried: [http-remoting://localhost:9990
//Servers tried: [http-remoting://localhost:8080 depending on Context.PROVIDER_URL
(java.io.IOException: Unknown service name)]
I start Wildfly with this command:
<wildfly-10.1.0.Final>\bin\standalone.bat --server-config=standalone-full.xml
Wildfly command window excerpts (below) confirms standalone-full.xml was used.
Also that there is a factory bound to jndi name: “java:jboss/exported/jms/RemoteConnectionFactory”
The Wildfly console opens from
http://localhost:9990
The user ID and password shone in the code opens it
I’ve pasted the CLASS CODE, ECLIPSE CONSOLE OUTPUT, and WILDFLY CONSOLE EXCERPTS below.
I’m out of ideas. Hope someone can point me in the right direction
CLASS CODE
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import java.util.HashMap;
import java.util.Properties;
import org.hornetq.jms.client.HornetQJMSConnectionFactory;
import static org.america3.gotest.shared.tools.Utility.padRight;
public class PostedCode implements ConnectionValues {
private Context ctx = null;
private HornetQJMSConnectionFactory factory = null;
private Properties ENV_LOCAL = new Properties() {
private static final long serialVersionUID = 1L;
{
put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
put(Context.PROVIDER_URL,
"http-remoting://localhost:9990");
//put(Context.PROVIDER_URL,
// "http://localhost:9990"); This produces identical failures
//put(Context.PROVIDER_URL,
// "http-remoting://localhost:8080"); This produces identical failures
put(Context.SECURITY_PRINCIPAL,
"jmsUser");
put(Context.SECURITY_CREDENTIALS,
"jmsPW123!");
//put("jboss.naming.client.ejb.context",
// true); This made no difference either
}
};
public static void main (String args[]) {
PostedCode test = new PostedCode ();
// Set Wildfly Initial Context
test.ctx = test.getInitialContetext();
if (test.ctx == null) {return;} else {System.out.println("\nInitialContext not null: " + test.ctx);}
// Print list of IntialContxt
test.listCtx (test.ctx);
// Set JMS ConnectionFacytory
test.factory = (HornetQJMSConnectionFactory)test.getFactory(test.ctx);
if (test.factory == null) {return;} else {System.out.println("ConnectionFactory not null: " + test.factory);}
}
private Context getInitialContetext () {
pProps(ENV_LOCAL); // Prints properties to console
try {
return new InitialContext(ENV_LOCAL);
} catch (Exception e) {
System.out.println("\ngetInitialContext() caught: " + e.getClass().getName());
System.out.println(" msg : " + e.getMessage());
return null;
}
}
private HornetQJMSConnectionFactory getFactory (Context ctx) {
try {
return (HornetQJMSConnectionFactory) ctx.lookup("java:jboss/exported/jms/RemoteConnectionFactory");
} catch (Exception e) {
System.out.println("\ngetFactory() caught: " + e.getClass().getName());
System.out.println(" msg : " + e.getMessage());
e.printStackTrace();
return null;
}
}
static private void pProps (Properties p) {
StringBuffer sb = new StringBuffer ();
sb.append("Properties used to obtain IntialContext"+"\n");
for (Object key: p.keySet()) {
String pKey = padRight (" " + (String)key,40,' ');
sb.append(pKey);
sb.append("\"" + p.get(key) + "\"" + "\n");
}
System.out.println(sb);
}
private void listCtx (Context ctx) {
HashMap<String, String> map = new HashMap<String, String>();
try {
System.out.println("Listing InitialContext NameClassPair Enumeration:");
NamingEnumeration<NameClassPair> list = this.ctx.list("");
System.out.println("Enumerator: " + list);
while (list.hasMoreElements()) {
NameClassPair next = list.next();
String name = next.getName();
String jndiPath = "name: " + name;
map.put(name, jndiPath);
}
System.out.println("map.size(): " +map.size());
} catch (Exception e) {
System.out.println("\nlistCtx(): caught: " + e.getClass().getName());
System.out.println(" msg : " + e.getMessage());
}
}
}
ECLIPSE CONSOLE OUTPUT:
Properties used to obtain IntialContext
java.naming.provider.url "http-remoting://localhost:9990"
java.naming.factory.initial "org.jboss.naming.remote.client.InitialContextFactory"
java.naming.security.principal "jmsUser"
java.naming.security.credentials "jmsPW123!"
Aug 08, 2017 11:03:03 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.4.6.Final
Aug 08, 2017 11:03:03 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.4.3.Final
Aug 08, 2017 11:03:03 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.7.Final
InitialContext not null: javax.naming.InitialContext@6108b2d7
Listing InitialContext NameClassPair Enumeration:
listCtx(): caught: javax.naming.CommunicationException
msg : Failed to connect to any server. Servers tried: [http-remoting://localhost:9990 (java.io.IOException: Unknown service name)]
//msg : Failed to connect to any server. Servers tried: [http-remoting://localhost:8080 (java.io.IOException: Unknown service name)] depending on Context.PROVIDER_URL
getFactory() caught: javax.naming.CommunicationException
msg : Failed to connect to any server. Servers tried: [http-remoting://localhost:9990 (java.io.IOException: Unknown service name)]
//msg : Failed to connect to any server. Servers tried: [http-remoting://localhost:8080 (java.io.IOException: Unknown service name)] depending on Context.PROVIDER_URL
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [http-remoting://localhost:9990 (java.io.IOException: Unknown service name)]
at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:244)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:149)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:130)
at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:87)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:129)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.america3.gotest.xtra.PostedCode.getFactory(PostedCode.java:55)
at org.america3.gotest.xtra.PostedCode.main(PostedCode.java:38)
WILDFLY CONSOLE EXCEPTS:
Calling "C:\ProgramFilesGeo\Wildfly\wildfly-10.1.0.Final\bin\standalone.conf.bat"
Setting JAVA property to "C:\Program Files\Java\jdk1.8.0_121\bin\java"
====================================================
JBoss Bootstrap Environment
…
JAVA_OPTS: "-Dprogram.name=standalone.bat -Xms64M -Xmx512M -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman"
=====================================================
…
10:48:03,475 INFO [org.wildfly.extension.messaging-activemq]
(ServerService Thread Pool -- 73) WFLYMSGAMQ0002:
Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
…
10:48:04,111 INFO [org.jboss.as]
(Controller Boot Thread) WFLYSRV0051:
Admin console listening on http://127.0.0.1:9990 …
10:48:04,113 INFO [org.jboss.as]
(Controller Boot Thread) WFLYSRV0025:
WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 3714ms - Started 486 of 741 services (428 services are lazy, passive or on-demand)