Reputation: 2424
I am Using a method in a session bean that is surrounded by a try and catch bloc with an IOException and it looks like it is making a problem as when i try to call a method from a java project client so here is my bean code
package com.et;
import com.gestionfichier.gestion.*;
import java.io.IOException;
import javax.ejb.ApplicationException;
import javax.ejb.Stateless;
@Stateless
public class PremierEJB3Bean implements PremierEJB3 {
public String envoicode(String Code) {
String s = null;
try {
s = GestionFichier.CopierCode(Code);
} catch (IOException e) {
e.printStackTrace();
}
CompilerFichierC.CompilerFichier(s,s);
return "Compilation réussie !";
}
}
and here is my client bean code:
package com.et;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class PremierEJB3Client {
public static void main(String[] args) {
try {
Context context = new InitialContext();
PremierEJB3 beanRemote = (PremierEJB3)
context.lookup("PremierEJB3Bean/remote");
System.out.println(beanRemote.envoicode("somthing"));
} catch (NamingException e) {
e.printStackTrace();
}
}
}
and here is what i get in the console
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at $Proxy0.envoicode(Unknown Source)
at com.et.PremierEJB3Client.main(PremierEJB3Client.java:15)
Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
And more....
so i am quiet sure that exceptions in my bean are causing me this problem but i have no idea how to fix that
Upvotes: 0
Views: 261
Reputation: 1562
This doesn't necessarily indicate that the EJB bean is not found - a possible case would be that the bean is found, and its initializer is called in the EJB container, and an exception is caused there.
Thus you might see ClassNotFound - java.lang.StackTraceElement
because somehow a serialized StackTraceElement
is returned back to the client which cannot be de-serialized (e.g. because of an incompatibility between the Java version used to compile the code in the server and the code in the client?)
This was happening in my own scenario, where the EJB was found, but later when I called some method on it, a similar stack trace was appearing - because of an exception happening on the EJB container/server side. I fixed the error in the EJB and stopped looking for the reason its stack trace cannot be passed safely to the client.
Upvotes: 0
Reputation: 46
In order to do JNDI lookup for the EJB from a standalone client, context properties needs to be added.
Something similar to below.
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
Context ct=new InitialContext(ht);
Upvotes: 1