I have an ejb-3 compatible ejb, say
@Remote
interface Hai{
String sayHai();
}
Stateless(name = "xxx", mappedname="yyy")
public class HaiImpl implements Hai{
public String sayHai(){
return "Hai";
}
}
And I need to generate stub for this EJB. but I dont want to use websphere tool or maven tool. Is there any way to generate stub using jdk?
When you create remote client
Hai hai = (Hai)ctx.lookup("yyy#com.zz.Hai");
System.out.println(hai.sayHai());
will work in weblogic or jboss, but in websphere, even it is ejb 3 you need to write like this
Object o = ctx.lookup("yyy");
Hai hai = (Hai)javax.rmi.PortableRemoteObject.narrow(o,Hai.class);
System.out.println(hai.sayHai());
In this case, if the stub is not presents at the client it will throw exception, there is a way to generate stub using websphere ejb stub generater tool. But I dont want to use any platform specific tools.
Stub is used by the client to invoke methods on the remote EJB -- it is basically a proxy object that implements the remote interface. It is responsible for serializing the invocation into a byte stream and sending it to the server hosting the EJB.
An EJB 3.0 session bean is a POJO managed by the EJB container. The functionality of a session bean is defined by its service interface (a.k.a. business interface), which is a plain old Java interface. Using the interface class name, the session bean client retrieves a stub object of the bean from the server's JNDI.
Generate the stub class for one remote interface class and place it in the package-defined directory structure, starting at the current directory. The my_path directory is as the class path. If the remote interface class to process is in a JAR file, the -cp my_path/my_interfaces.
No, you must use WAS_HOME/bin/createEJBStubs. The rmic command included in the Java SDK, which would normally be used to generate stubs, cannot be used on "pure" EJB 3 remote interfaces that do not extend java.rmi.Remote.
Note that if you use the application client container (WAS_HOME/bin/launchClient) or your "client" is another server, then you do not need to generate stubs: the container will generate one for you. You only need to use createEJBStubs if you're using an unmanaged thinclient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With