首页 文章

Jboss服务器中的RMI部署

提问于
浏览
0

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

1)获取Jboss注册表端口并将RMI注册表绑定到该端口 . 以下是我在servlet的init方法中编写的代码(这里Server是我的扩展Remote的接口,ServerImplementor是实现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();
            }
        }

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

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

1 回答

  • -1

    您可以检查端口1099是否存在 . 可能是,港口已被束缚 . 尝试通过以下方式指定端口:

    LocateRegistry.createRegistry(port);
    

相关问题