1

I'm working with an existing web application (running in Tomcat 7.0.26) that normally communicates with external systems over IBM WebsphereMQ, via the JMS API. The code looks similar to:

Hashtable<String, String> env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
env.put(Context.PROVIDER_URL, providerURL);

// Note that this is instantiating an InitialDirContext,
// NOT an InitialContext!!!
Context context = new InitialDirContext(environment);

qcf = (QueueConnectionFactory)context.lookup(qcfName);
requestQueue = (Queue)context.lookup(requestQueueName);
responseQueue = (Queue)context.lookup(responseQueueName);

//... etc, usual type of JMS code

I'm now trying to make this work with ActiveMQ 5.10 client libraries. A restriction on my end is that I cannot modify the source code. The only thing I have to play with are the variables as shown in the above code:

  • initialContextFactory is in the current case always set to com.sun.jndi.fscontext.RefFSContextFactory
  • providerURL is currently set to a file://C:/directory URL, pointing to a .bindings file as generated by "Managed JMS Objects" from WebsphereMQ Explorer
  • requestQueueName & responseQueueName

I'm now changing initialContextFactory to org.apache.activemq.jndi.ActiveMQInitialContextFactory, and providerURL to tcp://localhost:61616. Although I'm not getting any errors from the code, it doesn't work. I cannot see any connection in the ActiveMQ Web Admin console.

Researching on the web, I see that normally ActiveMQ JNDI with Tomcat is set up differently:

  • Resource entries in context.xml
  • Create the InitialContext as new InitialContext();
  • get a 'sub context' as envContext = (Context) initCtx.lookup("java:comp/env");
  • Get the JMS objects from this sub context (using a "jms/" prefix)

But as I wrote before, this is not an option for me: although I have access to the code, I cannot modify it.

Does anybody know a way around this? How can I get ActiveMQ QueueConnectionFactory/Queue objects from an instance of InitialDirContext, initialized only with INITIAL_CONTEXT_FACTORY and PROVIDER_URL, and presumably without any additional configuration on the Tomcat side (although if necessary I do have the option of changing the tomcat config as well).

Maarten

Maarten Boekhold
  • 867
  • 11
  • 21

1 Answers1

1

Turns out I needed to include geronimo-j2ee-management_1.1_spec-1.0.1.jar into the CLASSPATH of this application as well. Without this, an exception was thrown that wasn't logged anywhere, so it took some ingenuity to figure that one out.

Maarten

Maarten Boekhold
  • 867
  • 11
  • 21