2011-11-29 179 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

它拋出了相同的異常。 –

相關問題