Accessing RMI Server using an EJB as a Client
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andreas_Deege
Posted On:   Wednesday, June 2, 2004 03:01 AM

The Problem looks very simple. I like to access a RMI Server via an EJB. The reason for this is that I need to load a native library within a Java API. I know that this is not allowed within an EJB. So I would like to create a RMI Server which handles this task. Since I'm an EJB newbee I first created a small helloWorld example. But when I want to access the HelloImpl RMI Server I get the following exeption (I'm using JBOSS 3.2.3): ERROR [STDERR] javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: No ClassLoaders found for: hello.server.HelloImpl_Stub (no security manager: RMI class loader disabled)]    More>>

The Problem looks very simple. I like to access a RMI Server via an EJB. The reason for this is that I need to load a native library within a Java API. I know that this is not allowed within an EJB. So I would like to create a RMI Server which handles this task.

Since I'm an EJB newbee I first created a small helloWorld example. But when I want to access the HelloImpl RMI Server I get the following exeption (I'm using JBOSS 3.2.3):

			
ERROR [STDERR] javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: No ClassLoaders found for: hello.server.HelloImpl_Stub (no security manager: RMI class loader disabled)]

19:48:50,937 ERROR [STDERR] at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:92)

19:48:50,937 ERROR [STDERR] at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:98)
19:48:50,937 ...

I don´t understand this, since I am able to access the RMI Server with a "normal" Java client.

Now here is the code of the EJB Client. The exeption is generated by the loolup (obj = remoteContext.lookup("hello-server"):
			


try {

InitialContext serverContext = new InitialContext();

Object obj = serverContext.lookup("java:comp/env/NamingFactory"); //NamingFactory is an env variable

if (obj != null) {

this.namingFactory = obj.toString();

}

obj = serverContext.lookup("java:comp/env/NamingURL");

if (obj != null) {

this.namingUrl = obj.toString(); //NamingUrl is an env variable

}


Hashtable lTable = new Hashtable();

lTable.put(Context.INITIAL_CONTEXT_FACTORY, this.namingFactory);

lTable.put(Context.PROVIDER_URL, this.namingUrl);

Context remoteContext = new InitialContext(lTable);

obj = remoteContext.lookup("hello-server");//the Problem occures here

HelloServer helloServer = (HelloServer) PortableRemoteObject.narrow(obj, HelloServer.class);

String result = helloServer.sayHello();

System.out.println(result);

}

catch(Exception ex) {

ex.printStackTrace();

}


Here is the code of the RMI Server:


			
package hello.server;

import java.rmi.server.*;

import java.rmi.*;

import hello.HelloServer;

public class HelloImpl extends UnicastRemoteObject implements HelloServer {

public HelloImpl() throws RemoteException {
}

public String sayHello() {

return "Hello World";

}

public static void main(String args[]) {

try {

Naming.rebind("//localhost:2001/hello-server", new HelloImpl());
}
catch(Exception ex) {

ex.printStackTrace();
}

}


As I mentioned I´m an EJB newbee and so I hope this question is not addressed at the wrong place. If someone knew the answer or where I can find it, I would be very happy. I´m searching for the answer a long time. Thanks    <<Less

Re: Accessing RMI Server using an EJB as a Client

Posted By:   Daniele_Bufarini  
Posted On:   Friday, June 11, 2004 06:51 AM

As the exception message tells you, you're missing HelloImpl_Stub.class file in your EJB .jar file.
Note: you've to put that file in the right package, in your case hello.server

I've just done this in my j2ee app (with jboss 3.2.3) and all goes well.

Hope this helps you.

Daniele
About | Sitemap | Contact