2011-11-29 182 views
0

我想使用Jboss RMI(或JNDI)端口1099部署RMI。当Jboss服务器不在图片中时(即使用主程序),每件事情都正常工作。为了部署在服务器上,我尝试了两种方法。

1)获取Jboss注册表端口并将RMI注册表绑定到该端口。 以下是我已经写在servlet的 的init方法的代码(这里服务器是我的接口,扩展Remote,ServerImplementor是类实现服务器)Jboss服务器中的RMI部署

 

    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(); 
      } 
     } 

这种方法的问题是,当我运行客户端用下面的代码:

 

    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 
+0

您是否在(i)'bind()'上发生了该错误? (ii)'lookup()'? (ii)调用远程方法? – EJP

回答

-1

您可以检查端口1099是否存在。 也许,港口已经被捆绑起来了。 尝试通过以下方式指定端口:

LocateRegistry.createRegistry(port); 
+0

我已经尝试使用createRegistry(port)和getRegistry()。而且我也检查过它的值,它是越来越1099. –

+0

什么异常抛出?这是一个例子:server:reg = LocateRegistry.createRegistry(1099); reg.bind(“TestRMI”,c); client:reg = LocateRegistry.getRegistry(“localhost”,1099); c =(计算器)reg.lookup(“TestRMI”); –

+0

它抛出了相同的异常。 –

相关问题