2 Replies Latest reply on Mar 19, 2002 9:38 AM by nir z

    Connecting JBoss to external RMI service

    Ian Hunter Newbie

      Hi Folks,

      I need help in connecting an EJB to an external RMI service. This is what I *think* is the best solution, but any other suggestions welcomed

      Basically I have to connect up to an asynchronous socket based service from within JBoss. Because of threading issues and connection persistance I assume it's easiest to get out of EJB and into non-container land...RMI.

      So I have 2 approaches :-

      1. create an RMI object and then incorperate that within the EJB JNDI context and look it up from an EJB - EJB is just another client

      2. Run an RMI server using rmiregistry (not on port 1099). Run EJB and make an external lookup from EJB as per any other RMI client.

      Now for (1) I get problems with protocol exceptions when trying to
      bind. My code for this is basically:-

      /////////////////////////////////////////////////////
      public static void main(String[] args) {

      // JNDI props for JBoss....
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "localhost:1099");
      env.put(Context.URL_PKG_PREFIXES,
      "org.jboss.naming:org.jnp.interfaces");

      if (System.getSecurityManager() == null) {
      System.setSecurityManager(new RMISecurityManager());
      }

      String name = "jnp://localhost/rmi_object";
      try {

      InitialContext jndiContext =
      new InitialContext(env);

      RMI_ObjectImpl ro = new RMI_ObjectImpl();
      jndiContext.rebind(name, ro);

      } catch (Exception e) {
      System.err.println("RO exception: " +
      e.getMessage());
      e.printStackTrace();
      }
      }
      }
      ////////////////////////////////////////////////////////

      This yields the following exception...

      ///////////////////////////////////////////////////////
      RO exception: null
      javax.naming.CommunicationException. Root exception is
      java.rmi.ServerException
      : RemoteException occurred in server thread; nested exception is:
      java.rmi.UnmarshalException: error unmarshalling arguments;
      nested excep
      tion is:
      java.net.MalformedURLException: unknown protocol: d
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
      RemoteCall.java:248)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
      223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:136)
      at org.jnp.server.NamingServer_Stub.rebind(Unknown Source)
      at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:267)
      at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:240)
      at javax.naming.InitialContext.rebind(InitialContext.java:366)
      at com.teamwarrior.fleetcommander.RMI_ObjectImpl.main(RMI_ObjectImpl.java:48)
      Caused by: java.rmi.UnmarshalException: error unmarshalling arguments;
      nested ex
      ception is:
      java.net.MalformedURLException: unknown protocol: d
      ... 8 more
      Caused by: java.net.MalformedURLException: unknown protocol: d
      ... 8 more
      ////////////////////////////////////////////////////////

      I'm stuck - I don't see how I fix the unknown protocol. Varying the provider URL doesnt seem to do anything.

      Option (2) provides me with a security exception in the EJB object along the lines of I can't connect to a socket (1100), even tho' I've enabled java.policy in the JRE to allow this from any client (another test client confirms that this works).

      So, any ideas gratefully recieved....including alternative approaches to the whole thing. I'd appreciate any sample template code if possible

      Many Thanks for any help
      Ian Hunter