Reputation: 96
I want to deploy a RMI using the Jboss RMI(or JNDI) port 1099. Every thing is working fine when Jboss server is not in picture(i.e using main program). For deployment on server, I tried 2 approaches.
1) Getting the Jboss registry port and binding the RMI registry to that port.
Following is the code which i have written in the init method of servlet
(Here Server is my interface which extends Remote,ServerImplementor is class implementing Server)
public void init() throws ServletException { { Server implementor=new ServerImplementor(); Remote obj = UnicastRemoteObject.exportObject(implementor, 0); Registry r=LocateRegistry.getRegistry(); System.out.println("Registry post::"+r.REGISTRY_PORT); r.bind("TestRMI", obj); } catch(Exception e) { e.printStackTrace(); } }
The problem with this approach is when i run the client with following code:
registry = LocateRegistry.getRegistry("localhost",1099); hello = (Server) (registry.lookup("TestRMI"));
The error which i get is: java.rmi.ConnectIOException: non-JRMP server at remote endpoint
2) The 2nd approach which i tried is using JNDI, exposing a RMI(This is one approach which i came to know through googling)
Following is the code for the init method of servlet.Here the protocol used is jnp
try { Server remoteObj=new ServerImplementor(); Properties properties=new Properties(); properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.provider.url", "jnp://localhost:1099"); properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); InitialContext initialContext=new InitialContext(properties); initialContext.rebind("TestRMI", remoteObj); System.out.println("server up"); } catch (RemoteException e) { e.printStackTrace(); } catch(NamingException n) { n.printStackTrace(); }
When i run the client for the 2nd approach it gives error "TestRMI is not bound"
Client code is:
main(){ Properties properties=new Properties(); properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.provider.url", "jnp://localhost:1099"); properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); InitialContext initialContext=new InitialContext(properties); Server server=(Server)PortableRemoteObject.narrow(initialContext.lookup("TestRMI"), Server.class); }
So, i am not able to figure out what is the correct approach for deploying RMI in Jboss. Is it correct to write code in Servlet init method and create a registry.Or we have to use EJB,etc.. If any one have done this before please help me.
Thanks
Upvotes: 0
Views: 3956
Reputation: 141
You can check if the port 1099 is existing. May be, the port be tied up already. Try to appoint a port by:
LocateRegistry.createRegistry(port);
Upvotes: -1