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