If you have Ejb Client Jar: (code needs weblogic.jar and Client Jar for yours EJB) :
import java.rmi.RemoteException;
import java.util.Hashtable;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import com.epam.ejb.SomeEjbRemoteHome;
public class Main {
public static void main(String[] args) throws NamingException, RemoteException, CreateException{
Hashtable
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
env.put(Context.SECURITY_CREDENTIALS, "weblogic");
env.put(Context.PROVIDER_URL,"t3://localhost:7001/Errors_ejb");
Context context = new InitialContext(env);
Object homeObject = context.lookup("ejb.SomeEjbRemoteHome");
SomeEjbRemoteHome home = (SomeEjbRemoteHome)PortableRemoteObject.narrow(homeObject, SomeEjbRemoteHome.class);
home.create().someMethod("some string");
}
}
There is also abiliti to invoke as simple class (needs to have Ejb Class in classpath)
import com.epam.ejb.MyException;
import com.epam.ejb.SomeEjb;
public class Main {
public static void main(String[] args) throws MyException {
SomeEjb ejb = new SomeEjb();
System.out.println(ejb.someMethod("555"));
}
}
No comments:
Post a Comment