Search code examples
javajmswildflyjndi

Invalid URL scheme name "http-remoting" occurring when running application jar


I am using one of the JBoss JMS quickstart projects (HelloWorld-JMS) which uses JMS to write to a message queue. The queue has been defined in the JBoss XML configuration file. Our application runs perfectly fine when we run it from the IDE. However, when we package it as a JAR, we start seeing the exception:

SEVERE: Exception NamingException: javax.naming.InvalidNameException: WFNAM00007: Invalid URL scheme name "http-remoting"

We have also tried:

http-remoting://127.0.0.1:8080
remoting+http://127.0.0.1:8080

But we get the same exception.

Here's the main part of my code:

private static final String DEFAULT_MESSAGE = "Hello, World!";
private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
private static final String DEFAULT_DESTINATION = "jms/queue/myqueue";
private static final String DEFAULT_MESSAGE_COUNT = "1";
private static final String DEFAULT_USERNAME = "john";
private static final String DEFAULT_PASSWORD = "doe";
private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory";
private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8080";
Context namingContext = null;

String userName = System.getProperty("username", DEFAULT_USERNAME);
String password = System.getProperty("password", DEFAULT_PASSWORD);

// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
namingContext = new InitialContext(env);

// Perform the JNDI lookups
String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");

The exception occurs at this line:

ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);

These are the dependencies in pom.xml:

<dependency>
   <groupId>org.jboss.eap</groupId>
   <artifactId>wildfly-jms-client-bom</artifactId>
   <version>7.3.4.GA</version>
   <type>pom</type>
</dependency>
<dependency>
   <groupId>org.jboss.eap</groupId>
   <artifactId>wildfly-ejb-client-bom</artifactId>
   <version>7.3.4.GA</version>
   <type>pom</type>
</dependency>
<dependency>
   <groupId>org.jboss.spec.javax.jms</groupId>
   <artifactId>jboss-jms-api_2.0_spec</artifactId>
   <version>1.0.0.Final-redhat-1</version>
</dependency>
<dependency>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
   <version>2.8.0</version>
</dependency>
<dependency>
   <groupId>org.jboss</groupId>
   <artifactId>jboss-ejb-client</artifactId>
   <version>4.0.37.Final</version>
</dependency>
<dependency>
   <groupId>org.wildfly.common</groupId>
   <artifactId>wildfly-common</artifactId>
   <version>1.5.4.Final</version>
</dependency>
<dependency>
   <groupId>org.jboss.remotingjmx</groupId>
   <artifactId>remoting-jmx</artifactId>
   <version>3.0.4.Final</version>
</dependency>

Solution

  • It looks to me like your classpath has overlapping classes on it. I see the same thing in your pom.xml. This will cause the wrong classes to be loaded at runtime.

    For example, if you look at the pom.xml of the HelloWorld-JMS project you'll see that it only uses the wildfly-jms-client-bom. In fact, the whole point of such a "bom" (i.e. bill of materials) is to incorporate all the required dependencies into a single dependency. Therefore, I recommend you just use this in your pom.xml:

    <dependency>
       <groupId>org.jboss.eap</groupId>
       <artifactId>wildfly-jms-client-bom</artifactId>
       <version>7.3.4.GA</version>
       <type>pom</type>
    </dependency>
    

    Likewise, on your application's classpath you should only have the dependencies of wildfly-jms-client-bom on your classpath (or aggregated equivalents).