6 Replies Latest reply on Jun 6, 2007 3:23 PM by psyllogism

    javax.naming.NotContextException

    psyllogism

      Help me please! I am getting the following exception when I try to connect my client application to my server:

      javax.naming.NotContextException: Reference Class Name: java.lang.Object
      Type: FACTORY
      Content: MetaAgentImplStatefulProxyFactory
      is not a Context
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:692)
       ...


      It is happening when I look up my EJB:
      Object ref = jndiContext.lookup("MetaAgentImpl/remote");


      My jboss.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN" "http://www.jboss.org/j2ee/dtd/jboss.dtd">
      
      <jboss>
      
       <enterprise-beans>
       <session>
       <ejb-name>MetaAgentImpl</ejb-name>
       <jndi-name>MetaAgentImpl</jndi-name>
       </session>
       </enterprise-beans>
      
       <resource-managers>
       </resource-managers>
      </jboss>


      What is going on?? Thanks in advance!

        • 1. Re: javax.naming.NotContextException
          jaikiran

           

          <jndi-name>MetaAgentImpl</jndi-name>


          So your lookup should be:

          Object ref = jndiContext.lookup("MetaAgentImpl");


          • 2. Re: javax.naming.NotContextException
            psyllogism

            Okay. Then on this line:

            m_metaAgent = (MetaAgent) PortableRemoteObject.narrow(ref, MetaAgent.class);


            I get the exception:
            java.lang.ClassCastException
             at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
             at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
             ...


            The jndiContext.lookup(...) method returned a "MetaAgentImplStatefulProxyFactory" object, which isn't anything in my project!

            So I still need help. Thanks.

            • 3. Re: javax.naming.NotContextException
              jaikiran

              Which version of EJB are you using? Is it EJB2 or EJB3. Since you posted this in EJB3 forum, i guessed it was EJB3, but i am not sure going by your question.

              Also, could you post the contents of your ejb-jar.xml (if you have one) and the code where you are doing this lookup and narrow

              • 4. Re: javax.naming.NotContextException
                psyllogism

                Yes, I am using EJB 3.0. I currently do not have an ejb-jar.xml file. I have not developed with EJBs before but I thought that EJB 3.0 does not need one?

                The lookup code:

                // Lookup the meta-agent
                Properties p = new Properties();
                p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                p.put(Context.PROVIDER_URL, "jnp://" + m_hostName + ":" + m_serverPortNumber);
                Context jndiContext = new InitialContext(p);
                
                Object ref = jndiContext.lookup("MetaAgentImpl");
                m_metaAgent = (MetaAgent) PortableRemoteObject.narrow(ref, MetaAgent.class);


                The MetaAgent interface:
                @Remote
                public interface MetaAgent {
                ...
                }


                The MetaAgent implementation:
                @Stateful
                public class MetaAgentImpl
                 extends AbstractSessionAgent implements MetaAgent,
                 Serializable {
                ...
                }


                Thanks for looking!

                • 5. Re: javax.naming.NotContextException
                  jaikiran

                   

                  Yes, I am using EJB 3.0. I currently do not have an ejb-jar.xml file. I have not developed with EJBs before but I thought that EJB 3.0 does not need one?


                  Yes, that's right. I just wanted to confirm you were not using one.

                  m_metaAgent = (MetaAgent) PortableRemoteObject.narrow(ref, MetaAgent.class);


                  In EJB3, you no longer need the PortableRemoteObject.narrow. You can directly cast the returned object to the remote interface:

                  MetaAgent metaAgent = (MetaAgent) jndiContext.lookup("MetaAgentImpl");


                  • 6. Re: javax.naming.NotContextException
                    psyllogism

                    I solved it!

                    I needed to add:

                    jboss-ejb3-client.jar
                    jboss-aspect-jdk50-client.jar
                    jboss-aop-jdk50-client.jar

                    to my build path.

                    Now I get to move on to my next error(s), which does not seem to be JBoss/EJB3 related.

                    Thanks for being patient with me!