3 Replies Latest reply on Jan 12, 2006 7:17 AM by amitguz

    failed to implement a stand alone java client calling to EJB

    amitguz

      Hi All,
      I'm using JBOSS 4.0.3 and my stand alone client failed to connect to EJB.

      I tried to implement it as follow :

      in the server side :
      I create a stateless AuthorBean class which implements Authors Remote interface


      in the client side I wrote :

      Properties jndiProps = new Properties();
       jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
       jndiProps.setProperty(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
       jndiProps.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
       Context c = new InitialContext(jndiProps);
       Object reference = c.lookup("Authors");
      


      but I'm receiving the following error:
      javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: java.security.AccessControlException: access denied (java.net.SocketPermission 230.0.0.4 connect,accept,resolve) [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)]]
       at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1399)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at client.startApplication.main(startApplication.java:29)
      


      What I'm doing wrong ?
      Can someone point me to an example of how to implement such call
      from stand alone client to ejb on JBOSS?

      tnx, amit


        • 1. Re: failed to implement a stand alone java client calling to
          amitguz

          found the problem.
          I needed set the security.
          add new file to the client side
          policy.all which contain :

          grant {
           permission java.security.AllPermission "", "";
          };
          

          and run the client VC with -Djava.security.policy=policy.all

          but now I lookup failed with:
          javax.naming.NameNotFoundException: authors not bound
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
           at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
           at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
           at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          


          • 2. Re: failed to implement a stand alone java client calling to
            okism

             

            but now I lookup failed with:
            javax.naming.NameNotFoundException: authors not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
             at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
             at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
             at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            


            Did you solve it? I have the same problem, too. There are no examples on how to find (lookup) deployed EJB from VM other then EJB containers. When I look in JNDI tree in JMX console, and compare it to what InitialContext contains, I see that it does not search through java namespace, but only through global JNDI namespace.
            Here is the code:
            InitialContext ctx;
             try {
             ctx = new InitialContext();
             Enumeration ctxList = ctx.list("");
             int i = 0;
             while (ctxList.hasMoreElements()) {
             i++;
             NameClassPair element = (NameClassPair) ctxList.nextElement();
             System.out.println("element "+i+" : "+element);
             }
             } catch (NamingException e) {
             e.printStackTrace();
             }
            


            • 3. Re: failed to implement a stand alone java client calling to
              amitguz

              the JNDI rules are like that:
              under JAVA : u can reach JNDI names only from the same VM which JBOSS use, meaning if your client is a standalone client (on a separate VM) and your JBOSS run on a different VM u cannot fetch the namespaces in this area from the client.
              under GLOBAL: u can fetch the objects from the JNDI even from different VM.

              my problem was that my remote interface wasn't written to the global JDNI due to bye mistake I assign both the local and the remote to the same interface.
              @local
              @remote
              public interface Authors {
              dddd,,,,
              }