Monday, March 2, 2009

Portlets EJB calling

The architecture Jee (Java Enterprise Edition) provides for the use of EJB's for the treatment of logic and business logic of persistence.

The portles, being specialized in the presentation layer can use this type of component for the presentation of data.

In this scenario an architecture is recommended to use EJB's in a different JVM from the JVM used to run the portlets.To implement this architecture is to perform a configuration in Websphere to prevent CSIv2 send credentials to the client stub. The full procedure for this configuration can be seen on the link below:

The code to call the EJB in the portlet is below:

Hashtable env= new Hashtable(); Hashtable env = new Hashtable ();
env.put(Context.INITIAL_CONTEXT_FACTORY, ""); env.put (Context.INITIAL_CONTEXT_FACTORY, "");
env.put(Context.PROVIDER_URL, "iiop://servidorEJB:10031"); env.put (Context.PROVIDER_URL, "iiop: / / servidorEJB: 10031");

InitialContext context= new InitialContext(env); InitialContext context = new InitialContext (env);
String jndiName= "ejb/aplicacao/ComponentFacade"; String jndiName = "EJB / Application / ComponentFacade";

Object objRef = context.lookup(jndiName); Object objRef = context.lookup (jndiName);
ComponentFacadeHome ejbHome= (ComponentFacadeHome) PortableRemoteObject.narrow(objRef, ComponentFacadeHome.class); ComponentFacadeHome ejbHome = (ComponentFacadeHome) PortableRemoteObject.narrow (objRef, ComponentFacadeHome.class);
ComponenttFacade remote= (ComponentFacade)ejbHome.create(); ComponenttFacade remote = (ComponentFacade) ejbHome.create ();

ParametersTO netParameter = remote.getVerDados(valor); ParametersTO netParameter = remote.getVerDados (value);