I have a client side that takes input from a JSP page and then gives it to a thread, the thread is added to a thread pool and when it executes the thread contacts the RMI server to get the remote object and then should return the results which will be displayed on a new JSP page, the problem is once the runnable code is executed I get the following error:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: servertest.DictionaryInterface (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at Client.LookupWorker.run(LookupWorker.java:27)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: servertest.DictionaryInterface (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)Thread didnt finish its job properly, error: java.lang.NullPointerException
Heres the Java code behind the JSP page
if (request.getParameter("word") != null) {
String word = request.getParameter("word");
String res;
System.out.println("The word to find: "+word);
// Get handle on our pool
WorkerPool pool = WorkerPool.getInstance( );
// Create Job
LookupWorker wordWork = new LookupWorker(word);
// Add job to pool
res = pool.addJob(wordWork);
request.getSession().setAttribute("result", res);
response.sendRedirect("/SearchResults");
}
Here is the thread class:
package Client;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import DictionaryInterface.DictionaryInterface;
public class LookupWorker implements WorkerPlan {
private String word;
private String jobName;
private String serverResult;
private long threadId;
public LookupWorker(String w) {
super();
this.word = w;
jobName = "Lookup Job";
}
@Override
public void run(){
DictionaryInterface Dictonary = null;
try {
Dictonary = (DictionaryInterface) Naming.lookup("rmi://127.0.0.1:1099/DictionaryService");
} catch (MalformedURLException | RemoteException | NotBoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
serverResult = Dictonary.lookup(word);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(serverResult);
threadId = Thread.currentThread().getId();
}
public String getServerResult() {
return serverResult;
}
public String getWord() {
return word;
}
public String getJobName() {
return jobName;
}
@Override
public String toString() {
return jobName + " [Id= " + threadId + "word= " + word + ", serverResult= " + serverResult + "]";
}
}
The pool code involded in executing the thread:
public String addJob(WorkerPlan job) {
String result;
threadCounter++;
// Adding new lookup job to our queue
System.out.println("Adding a " + job.getJobName() + " to the queue. Searching for: " + job.getWord() + " Job number: " + threadCounter);
executor.execute(job);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // sleep so we can wait for rmi object to come in
System.out.println(job.toString());
result = job.getServerResult();
return result;
}
Ive tried different paths for the VM arguments but cant get it to work, any help is greatly appreciated.