3 Replies Latest reply on Sep 5, 2003 6:15 AM by blakbox

    Context.lookup returns null

    miksu

      I'm fighting with a client-software which uses JBoss 2.4.9 /Tomcat 3.2.3 over Win2k (j2sdk1.4.1_02). The problem is that this line gives me a java.lang.NullPointerException:

      TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup("RMIConnectionFactory");

      After a while I noticed that context.lookup("RMIConnectionFactory") returns a null so it's no wonder that the line above gives a NullPointerException. But the question is, why it's returning a null? I think it should return NameNotFoundException if RMIConnectionFactory wasn't declared in jboss.jcml.

      This program has worked before but afaik, little older versions of Jboss/tomcat/j2re were used and Jboss/tomcat were running in a Linux-machine.

      Really big thanks in advance.

        • 1. Re: Context.lookup returns null
          miksu

          Some more code from the program:

          Hashtable props = new Hashtable();
          props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          props.put(Context.PROVIDER_URL, myResources.getString("CHATHOST"));
          props.put("java.naming.rmi.security.manager", "yes");
          props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");

          context = new InitialContext(props);

          TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup("java:/RMIConnectionFactory");
          topicConnection = topicFactory.createTopicConnection();

          The lookup returns null so the next line causes a NullPointerException. I made a mistake in first post, it's the second line giving NullPointerException, not the first.

          • 2. Re: Context.lookup returns null
            xibin

            I am having the same problem running JBoss 3.2.0.

            The strangest thing is, of the two identical server machines, the client works against one and fails against the other, consistently.

            My code looks like this:

            initialContext = new InitialContext();

            System.err.println("got context " + initialContext);

            Hashtable env = initialContext.getEnvironment();
            String connectionFactory = (String)env.get(CONNECTION_FACTORY_JNDI_NAME);
            String username = (String)env.get(Context.SECURITY_PRINCIPAL);
            String password = (String)env.get(Context.SECURITY_CREDENTIALS);

            Object factory = initialContext.lookup(connectionFactory);

            The last line of code returned null, so factory is null.

            The string value of connectionFactory is "UILConnectionFactory". I have tried "ConnectionFactory" as well and it failed the same way.

            Can someone out there point out to me what the problem is?

            • 3. Re: Context.lookup returns null
              blakbox

              Hi,

              I'm experiencing the same problem with jboss 3.0.4, but only in debian. If i run jboss in winXP, there's no problem.

              I thought it was because the firewall. However i disabled the firewall, but the lookup is still returning null.

              Help will be apreciated