2 Replies Latest reply on Nov 3, 2006 7:37 PM by Srdjan Djuricic

    invoking remote session bean NotContextException

    Srdjan Djuricic Newbie

      Hi,

      I am having trouble when looking up for a remote session bean from my ejb application. I am running jboss 4.0.4 with ejb3.0. I am trying to access a remote computer running jboss 4.0.4 but with 2.1 option. Instead of deploying remotely on a different machine I tried deploying the third party application in my instance of jboss and everything works fine.


      Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory");
      props.setProperty(Context.SECURITY_PRINCIPAL, "admin");
      props.setProperty(Context.SECURITY_CREDENTIALS, "admin");
      props.setProperty(Context.PROVIDER_URL, "jnp://192.168.10.130:1099/");
      
      Context ctx = new InitialContext(props);
      Object object = ctx.lookup( "ejb/com/blah/Manager/remote" );
       ManagerRemoteHome home = (ManagerRemoteHome)PortableRemoteObject.narrow ( object, ManagerRemoteHome.class);
      
       ManagerRemote manager = home.create();
      
      I get an exception when executing this line
      ManagerRemoteHome home = (ManagerRemoteHome)PortableRemoteObject.narrow ( object, ManagerRemoteHome.class);
      
      2006-11-02 15:02:49,194 ERROR [STDERR] javax.naming.NotContextException
      2006-11-02 15:02:49,194 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:285)
      2006-11-02 15:02:49,194 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      2006-11-02 15:02:49,194 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      2006-11-02 15:02:49,194 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      2006-11-02 15:02:49,194 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      2006-11-02 15:02:49,194 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      2006-11-02 15:02:49,194 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      









        • 1. Re: invoking remote session bean NotContextException
          Srdjan Djuricic Newbie

          I still didn't solve my problem but I tried to deploy it on my local machine and see I could somehow find what the issue is when deploying it on a remote machine.

          Initially deploying it on my local machine everything worked fine
          However when I add the following line I see that code breaks.

          String host = "jnp://localhost:1099";
          props.setProperty(Context.PROVIDER_URL, host);
          I started getting the following exception
          
          2006-11-03 10:17:18,319 ERROR [STDERR] java.lang.ClassCastException
          2006-11-03 10:17:18,319 ERROR [STDERR] at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
          2006-11-03 10:17:18,319 ERROR [STDERR] at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
          

          As soon as I uncomment that props.setProperty(Context.PROVIDER_URL, host);
          line everything works fine.
          I have seen this type of exception before when I tried invoking the ejb on a different computer as well. I am not sure how to see what is the wrapper class for the object since the call to object.getClass().getName() prints something like this $Proxy184

          This is my code again:

          Properties props = new Properties();

          props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory");
          props.setProperty(Context.SECURITY_PRINCIPAL, "admin");
          props.setProperty(Context.SECURITY_CREDENTIALS, "admin");
          props.put(javax.naming.Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

          String host = "jnp://localhost:1099";
          props.setProperty(Context.PROVIDER_URL, host);
          ctx = new InitialContext( props );

          Object object = ctx.lookup( "ejb/com/blah/Manager" );

          ManagerRemoteHome home = (ManagerRemoteHome)PortableRemoteObject.narrow ( object, ManagerRemoteHome.class);
          ManagerRemote manager = home.create();

          Thanks

          • 2. Re: invoking remote session bean NotContextException
            Srdjan Djuricic Newbie

            Through reflection on object I see that it is the correct HomeRemote interface and the right method, but I still can not figure out what is the difference of specifying Context.PROVIDER_URL with jnp://localhost:1099