I am trying to look up a QueueConnectionFactory and Queue via Geronimo’s JNDI. The Queue gets returned fine, but the QueueConnectionFactory lookup always returns null. It doesn’t throw a NamingException, which is what I’d expect if the JNDI name was incorrect.
Can anyone see what I’m doing wrong? The test code below outputs:
true false
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class JndiTest
{
private final static String QUEUE_NAME = "jca:/org.apache.geronimo.configs/activemq-ra/JCAAdminObject/SendReceiveQueue";
private final static String FACTORY_NAME = "jca:/org.apache.geronimo.configs/activemq-ra/JCAManagedConnectionFactory/DefaultActiveMQConnectionFactory";
public static void main(String[] args) throws NamingException
{
InitialContext ctx = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup(FACTORY_NAME);
Queue queue = (Queue)ctx.lookup(QUEUE_NAME);
System.out.println(factory == null);
System.out.println(queue == null);
}
}
In case it makes a difference: I’ve added openejb-client-3.0.1.jar, geronimo-ejb_3.0_spec-1.0.1.jar and activemq-core-4.1.2-G20090207.jar to my class path, and my jndi.properties file has the properties:
java.naming.factory.initial = org.apache.openejb.client.RemoteInitialContextFactory java.naming.provider.url = ejbd://127.0.0.1:4201
The reason why it is not throwing an exception is that – there is a ClassLoadException that comes when the resource is accessed.
And the reason why that is happening because the class : com.sun.jndi.url.jca.jcaURLContextFactory is being searched for by the ClassLoader called from ResourceManager.
If you change the Factory name to some other name then you shall see the NamingException – but in the case of lookup , for Exceptions such as ClassNotFound/IllegalState – no exceptions are raised.
The dependencies of ActiveMQ thus need to be analysed.
Update1: One of the possible reasons is that the factory object can only be instantiated in a managed environment. Are you running your code as an application client?.
Update2: Some other pointers found for the cause of this behavior:
Found this on ActiveMQ site:
See more on how to Connect using JNDI:
The initial context factory used in the explanation is: org.apache.activemq.jndi.ActiveMQInitialContextFactory
Some sample code to test with JNDI can be found here
I wrote a simple java client – note below the provider url is the brokerURL that is being used.
This program gives the output:
conn is : org.apache.activemq.ActiveMQConnectionFactory
queue is : org.apache.geronimo.configs/activemq-ra/JCAAdminObject/SendReceiveQueue