1

I'm trying to send a JMS message (remotely) from Jboss 4.2.3GA instance to Jboss 7.1.1.Final instance. When I try to do it "7.1.1 style"

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
InitialContext jndiContext = new InitialContext(properties);
ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory");

I got

ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory

When I try to do it "4.2.3" way

properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
InitialContext jndiContext = new InitialContext(properties);
ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory");

I got

UnknownHostException: remote

With different address (jnp://127.0.0.1:4447) I have java.io.StreamCorruptedException: invalid stream header: 0000000C

I'm starting the 7.1.1 with standalone.bat --server-config=standalone-full.xml -b 0.0.0.0. Please help cause I'm stepping blindfolded here. Any example on how to send a JMS from 4.2.3GA to 7.1.1 would be greatly appreciated.

zbig
  • 3,830
  • 2
  • 29
  • 37

1 Answers1

0

The main problem with this issue lays in the fact that

The old jnp based JNDI implementation used in previous JBoss versions is no longer supported

We have to use remote: protocol. Useful resources are jboss dev guide JNDI and master the jboss ejb tutorial.

They tell you that you need jboss-client.jar from %JBOSS_HOME%/bin/client. This is indeed true for Java SE project. With different app server it is too much cause it results in some javax.* conflicts and causes my injection points to fail. I ended up with this set up of jars:

  • jboss-remoting-3.2.3.GA.jar
  • jboss-remote-naming-1.0.2.Final.jar
  • jboss-sasl-1.0.0.Final.jar
  • jboss-marshalling-1.3.11.GA.jar
  • jboss-marshalling-river-1.3.11.GA.jar
  • jboss-logging-3.1.0.GA.jar
  • netty-3.2.6.Final.jar
  • xnio-api-3.0.3.GA.jar
  • xnio-nio-3.0.3.GA.jar
  • hornetq-core-client-2.2.13.Final.jar
  • hornetq-jms-client-2.2.13.Final.jar

And successfully send a message to Jboss 7.1.1 test topic:

final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
InitialContext jndiContext = new InitialContext(env);
ConnectionFactory cf = (ConnectionFactory) jndiContext.lookup("jms/RemoteConnectionFactory");
Topic topic = (Topic) jndiContext.lookup("jms/topic/test");
Connection conn = null;
try {
    conn = cf.createConnection();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(topic);
    TextMessage message = session.createTextMessage("Hello world");
    producer.send(message);
} catch (JMSException e) {
    log.error(e);
} finally {
    if (conn != null) {
        try {
            conn.close();
        } catch (JMSException e) {
            log.error(e);
        }
    }
}

However I had to turn off security because of

javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

I didn't figure out how to authenticate. I add user with add-user script and play with different properties without success. You can turn off security by removing security-realm="ApplicationRealm" from this section in standalone-full.xml

<subsystem xmlns="urn:jboss:domain:remoting:1.1">
    <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
</subsystem>

and deselectiong Profile>Messaging>Messaging Provider>Security enabled? in Jboss server administration console.

UPDATE Disabling security is not necessary. Use this options:

env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "pass");
zbig
  • 3,830
  • 2
  • 29
  • 37