2 Replies Latest reply on Dec 13, 2005 5:46 AM by Chris

    JBoss as a RMI Server

    Chris Newbie

      Hi,
      I'm really new to JBoss and would really appreciate any help on this...

      Following lies some details but my real question is :
      "How to set up a couple of plain old RMI Remote object available through a lookup (be it rmi registery or JNDI?)"

      First of all some background information:
      I'm trying to port our current project to JBoss for:
      1- commercial reasons (ie we *have to* use an application server anyway)
      2- be able to benefit mostly from the persistence framework and other cool stuff (but that's for later)

      The current application is a swing-based and connects to the serverside via RMI.
      There are 4 RMI RemoteObjects registered in the RMI Registery (these could be considered as stateless), one of them providing methods to return some other Remote objects ( these not beeing registered in the RMI registery and could be considered as statefull).

      I haven't found how to expose the 4 RMI RemoteObject in the RMI registery from JBoss.
      So if there is a way of doing it, I'd greatly appreciate if someone could point me to how to do it.

      We're are not really willing to use EJB, nor SessionBeans if we can keep away from the J2EE stack, by using simple POJOs. (Actually, all of our remote objects are enhanced at run-time by CGLib (FYI) )

      Then, I thought that I could declare the 4 RMI RemoteObject (the ones that are exposed in the RMI registery) as StatelessSessionBeans and live with it happilly.
      Unfortunately, JBoss won't allow me to declare a method returning a Remote object (not an EJB, just a plain RMI Remote object). (I guess that it would prevent the container to handle the Remote object )

      So the question really is:
      How to set up a couple of plain old RMI Remote object available through a lookup (be it rmi registery or JNDI?)

      Thanks in advance for any help
      Cheers
      Chris

        • 1. Re: JBoss as a RMI Server
          Vivek Srivastav Newbie

          You need the following:

          1. rmi.policy file with the following content
          grant {
          // Allow everything for now
          permission java.security.AllPermission;
          };

          2. You will need the jboss-client.jar available in JBOSS_HOME/client folder. The jar provides JNDI lookups.

          3. In the client application do the following:

          // your client method for looking up the registered RMI server object from JNDI
          String BINDING = "RMIServerObjectRemoteInterface";
          String binding = "//"+host+"/"+BINDING;
          if(System.getSecurityManager() == null) {
          ClassLoader cl = client.class.getClassLoader();
          java.net.URL url = cl.getResource("config/rmi.policy");
          System.setProperty("java.security.policy", url.toExternalForm());
          System.out.println("Initializing the security manager");
          System.setSecurityManager(new RMISecurityManager());
          }
          try{
          // replacing rmi lookup with JNDI lookup
          //obj = (IRMIService)Naming.lookup(binding);
          Context context = getContext(host);
          Object objref = context.lookup(BINDING);
          obj = (IRMIService)PortableRemoteObject.narrow(objref,IRMIService.class);} catch(java.rmi.ConnectException ex){
          System.out.println("The service may not be running on the host: "+host);
          }
          catch(Exception ex){
          System.out.println("Exception: "+ex.getMessage());
          ex.printStackTrace();
          }

          3. Server registration to the JNDI:

          First create a security Manager

          if(System.getSecurityManager() == null) {
          ClassLoader cl = this.getClass().getClassLoader();
          java.net.URL url = cl.getResource("config/rmi.policy");
          System.setProperty("java.security.policy", url.toExternalForm());
          System.out.println("Initializing the security manager");
          System.setSecurityManager(new RMISecurityManager());
          }

          //To bind the server object to the JNDI
          try{
          m_service = new PASTService();
          String binding;
          String host;
          if(args.length>0){
          host = args[0];
          }
          else {
          host = "localhost";
          }
          binding = "//"+host+"/"+BINDING;
          // binding with rmi commented
          // Naming.rebind(binding, m_service);
          // will try JBoss JNDI
          Context context = getContext(host);
          context.rebind(BINDING, m_service);
          } catch (Exception ex){
          System.out.println("Exception: "+ex.getMessage());
          ex.printStackTrace();
          }

          4. For jboss server's initial context, you can either user jndi.properties file or as detailed above in the code use the following method:

          private static Context getContext(String serverURL) throws NamingException {
          Properties p = new Properties();
          p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
          p.put(Context.PROVIDER_URL, serverURL);
          return new InitialContext(p);
          }

          Hope this works for you.

          Vivek Srivastav

          • 2. Re: JBoss as a RMI Server
            Chris Newbie

            It did!
            Thanks a lot for your reply!
            Now I need to dig a bit deeper to see how to set that up at deployement time (for now, I've just tested from the Duke's Bank Sample client app, by launching the configuration of my server app via a call to a StatelessSessionBean...)
            Thanks again
            Cheers
            Chris