You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by boekhold <bo...@gmx.com> on 2015/04/20 07:47:34 UTC

ActiveMQ 5.10 client in Tomcat 7 with InitialDirContext

Hi all,

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 Explore
- 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.
Unfortunately I also cannot run this in a debugger to see what's going on :(

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




--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-5-10-client-in-Tomcat-7-with-InitialDirContext-tp4695248.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: ActiveMQ 5.10 client in Tomcat 7 with InitialDirContext

Posted by boekhold <bo...@gmx.com>.
Hi,

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



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-5-10-client-in-Tomcat-7-with-InitialDirContext-tp4695248p4695343.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.