I'm trying to use http-remoting from a Java client with a remote wildfly 9. This always results in the ClassNotFoundException.
This is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>iz.alerting</groupId>
<artifactId>AlertingClientTest</artifactId>
<version>1.0.6-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<version>9.0.2.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-remote-naming</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
This is a very simple Java Main class that illustrates the problem.
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Main {
public static void main(String[] args) {
Logger log = Logger.getLogger("");
try {
Class.forName("org.hornetq.jms.client.HornetQTopic");
} catch (ClassNotFoundException e1) {
log.log(Level.SEVERE,"Could not find org.hornetq.jms.client.HornetQTopic",e1);
}
Properties env= new Properties();
String url="http-remoting://servername:12080";
log.log(Level.INFO,"Connecting to server "+url);
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_PRINCIPAL, "xxx");
env.put(Context.SECURITY_CREDENTIALS, "xxx");
InitialContext remoteContext=null;
try {
remoteContext = new InitialContext(env);
} catch (NamingException e) {
log.log(Level.SEVERE,"Could not create initialcontext", e);
}
Topic topic=null;
String eventname = "jms/izalerting/alertresult";
if(remoteContext!=null){
try {
topic = (Topic) remoteContext.lookup(eventname);
if(topic == null) {
log.log(Level.SEVERE,"Could not find topic" + eventname+ ". It was null");
}
} catch (NamingException e) {
log.log(Level.SEVERE,"Could not find topic" + eventname, e);
}finally {
try {
remoteContext.close();
} catch (NamingException e) {
log.log(Level.SEVERE,"Could not close remoteContext", e);
}
}
}
}
}
In my Wildfly standalone.xml I have this definition regarding the JMS topic called jms/izalerting/alertresult
.
<jms-destinations>
<jms-topic name="izalertAlertresult">
<entry name="jms/izalerting/alertresult"/>
<entry name="java:jboss/exported/jms/izalerting/alertresult"/>
</jms-topic>
</jms-destinations>
This program always results in a ClassNotFoundException on the line topic = (Topic) remoteContext.lookup(eventname);
. Below I've added the full output of the program.
I've added the Class.forName("org.hornetq.jms.client.HornetQTopic");
in the beginning of the program because I don't understand why it isn't found. It should be made available by the maven dependency hornetq-jms-client
.
Does anyone have a clue on how to fix this issue? Do I need an additional maven dependency?
I'm fairly sure that the connection to the server succeeds because when I remove the principal and credentials lines it says that it can not authenticate.
mrt 20, 2019 1:32:24 PM java.util.logging.LogManager$RootLogger log
SEVERE: Could not find org.hornetq.jms.client.HornetQTopic
java.lang.ClassNotFoundException: org.hornetq.jms.client.HornetQTopic
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at Main.main(Main.java:15)
mrt 20, 2019 1:32:24 PM java.util.logging.LogManager$RootLogger log
INFO: Connecting to server http-remoting://servername:12080
mrt 20, 2019 1:32:24 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.1.Final
mrt 20, 2019 1:32:25 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.1.Final
mrt 20, 2019 1:32:25 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.9.Final
mrt 20, 2019 1:32:26 PM java.util.logging.LogManager$RootLogger log
SEVERE: Could not find topicjms/izalerting/alertresult
org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: org.hornetq.jms.client.HornetQTopic]
at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)
at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)
at org.jboss.naming.remote.client.HaRemoteNamingStore$1.operation(HaRemoteNamingStore.java:276)
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137)
at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
at org.jboss.naming.remote.client.RemoteContext.lookupInternal(RemoteContext.java:104)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:93)
at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:146)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at Main.main(Main.java:43)
Caused by: java.io.IOException: java.lang.ClassNotFoundException: org.hornetq.jms.client.HornetQTopic
at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:159)
at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:149)
at org.jboss.naming.remote.protocol.v1.BaseProtocolCommand.readResult(BaseProtocolCommand.java:59)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleClientMessage(Protocol.java:149)
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver$1.run(RemoteNamingStoreV1.java:232)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.hornetq.jms.client.HornetQTopic
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.jboss.marshalling.AbstractClassResolver.loadClass(AbstractClassResolver.java:131)
at org.jboss.marshalling.AbstractClassResolver.resolveClass(AbstractClassResolver.java:112)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:948)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1255)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.jboss.naming.remote.protocol.v1.Protocol$1$3.read(Protocol.java:156)
... 7 more
The issue is resolved. The ClassNotFoundException
was actually caused by a java.util.zip.ZipException: invalid LOC header (bad signature)
. Apparently a bad jar was downloaded from the maven repositories.
The issue was resolved by deleting the .m2 directory an redownloading the maven dependencies.