4 Replies Latest reply on Jan 31, 2003 6:42 AM by petertje

    Problem in session EJB lookup

    matias

      Hi,
      I'm trying to look-up a stateless session EJB (called HousingController) from a servlet using

      Context ctx = new InitialContext();
      housingControllerHome = (HousingControllerHome) ctx.lookup("java:/comp/env/housingController");


      and get the following exception thrown:

      javax.naming.CommunicationException. Root exception is java.net.MalformedURLException: no protocol: and
      (full exception stack below)

      I'm using JBoss 2.4.3 (java version "1.3.1_01") and an internally-referenced EJB in the same application (ie everything's in the same EAR file that gets deployed).
      I also tried referencing the EJB externally but with same exact results.

      Here are relevant snippets from the XML config files:

      ejb-jar.xml:
      <ejb-jar>
      <enterprise-beans>

      <ejb-name>housingController</ejb-name>
      org.theonelist.housing.ejb.HousingControllerHome
      org.theonelist.housing.ejb.HousingController
      <ejb-class>org.theonelist.housing.ejb.HousingControllerBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      </enterprise-beans>
      </ejb-jar>


      From web.xml:
      <ejb-ref>
      <ejb-ref-name>housingController</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      org.theonelist.housing.ejb.HousingControllerHome
      org.theonelist.housing.ejb.HousingController
      <ejb-link>housingController</ejb-link>
      </ejb-ref>


      and the full exception stack:
      javax.naming.CommunicationException. Root exception is java.net.MalformedURLException: no protocol: and
      at java.net.URL.(Unknown Source)
      at java.net.URL.(Unknown Source)
      at java.net.URL.(Unknown Source)
      at sun.rmi.server.LoaderHandler.pathToURLs(Unknown Source)
      at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
      at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
      at java.io.ObjectInputStream.inputClassDescriptor(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.inputClassFields(Unknown Source)
      at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
      at java.io.ObjectInputStream.inputObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.readExternal(HomeProxy.java:212)
      at java.io.ObjectInputStream.inputObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.inputClassFields(Unknown Source)
      at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
      at java.io.ObjectInputStream.inputObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at java.rmi.MarshalledObject.get(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:353)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:421)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:457)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at org.theonelist.housing.servlet.HousingServlet.service(HousingServlet.java:58)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
      at org.apache.tomcat.core.Handler.service(Handler.java:287)
      at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
      at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Unknown Source)



      I had tried this on a different computer that had JBoss 2.4.0 and it had worked just fine....
      And I checked and made sure that my Sun j2ee.jar is *not* in my classpath.

      I've been trying workarounds for a while with no results... Any suggestions would be most greatly appreciated.

      Thanks,
      Matias

      If you prefer to email me directly, please use matias at email dot com.

        • 1. Re: Problem in session EJB lookup
          hstech

          Matias,

          Is there a difference in the jndi.properties file between the two machines? Maybe you should post the contents of the file also.

          Aaron.

          • 2. Re: Problem in session EJB lookup
            espend

            Hi,

            if you are looking up a ejb bean from a servlet you have to set the following enviroment variables when getting the InitialContext:

            env = new Hashtable();
            env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
            env.put("java.naming.provider.url","localhost:1099");
            env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");

            InitialContext initial = new InitialContext(env);

            else the servlet engine would not know where to look up the naming context...

            Espen

            • 3. Re: Problem in EJB lookup
              rajkonduru

              Hi,
              I am trying to lookup a session bean deployed in JBoss from an application deployed in WebSphere on a different machine.
              The following is the source code of the application in the WebSphere.

              Hashtable ht = new Hashtable();
              ht.put(InitialContext.PROVIDER_URL, "10.3.31.109");
              InitialContext ic = new InitialContext(ht);

              Object object = ic.lookup("adss/ScheduleInfo");

              I gave the JNDI name in the deployment descriptor as adss/ScheduleInfo

              It does't work. Any help is greatly appreciated.
              Thanks,
              Raj

              • 4. Re: Problem in EJB lookup

                > I am trying to lookup a session bean deployed in
                > JBoss from an application deployed in WebSphere on a
                > different machine.

                If you are performing a jndi lookup from _outside_ JBoss, you have to pass the proper jndi properties to the InitialContext (either by passing a Hashtable or by using a jndi.properties file - given the fact that you want to use it in another application server, i guess you'll have to stick to the hashtable solution).

                > Hashtable ht = new Hashtable();
                > ht.put(InitialContext.PROVIDER_URL, "10.3.31.109");
                > InitialContext ic = new InitialContext(ht);

                Setting the provider url only is not enough: see the previous post that you responsed to for the properties you have to set, or check it in the JBoss online docs.

                Peter.

                >
                > Object object = ic.lookup("adss/ScheduleInfo");
                >
                > I gave the JNDI name in the deployment descriptor as
                > adss/ScheduleInfo
                >
                > It does't work. Any help is greatly appreciated.
                > Thanks,
                > Raj