Skip to content

WebLogic EJB testing and JNDI lookup

Testing Enterprise Java Beans (EJB) deployed on a WebLogic Server programmatically typically involves establishing a remote connection via JNDI (Java Naming and Directory Interface). This process requires configuring the initial context with WebLogic-specific properties and performing a lookup to retrieve the remote service interface.^[600-developer__java__application-server__weblogic__weblogic-ejb.md]

JNDI Configuration

To connect to the WebLogic Server, the client code must initialize an InitialContext with a Properties object. The following properties are essential for establishing the connection^[600-developer__java__application-server__weblogic__weblogic-ejb.md]:

  • Context.INITIAL_CONTEXT_FACTORY: Must be set to weblogic.jndi.WLInitialContextFactory to use WebLogic's JNDI implementation.
  • Context.PROVIDER_URL: The address of the server, using the t3 protocol (e.g., t3://localhost:8080).
  • Context.SECURITY_PRINCIPAL: The username for authentication (e.g., weblogic).
  • Context.SECURITY_CREDENTIALS: The corresponding password.

EJB Lookup

Once the context is initialized, the EJB can be retrieved using its JNDI name. The lookup string generally follows the format [mapped-name]#[full-interface-name] to distinguish between different implementations or interfaces^[600-developer__java__application-server__weblogic__weblogic-ejb.md].

For example, to lookup a remote EJB service, the code might look like this:

Object obj = ctx.lookup("bpm/ejb/WorkflowEngineService#core.bpm.service.workflow.engine.WorkflowEngineServiceRemote");

After retrieving the object, it must be narrowed or cast to the appropriate remote interface type before invoking its business methods^[600-developer__java__application-server__weblogic__weblogic-ejb.md].

  • [[Java Naming and Directory Interface]]
  • [[Enterprise Java Beans]]
  • WebLogic Server

Sources

^[600-developer__java__application-server__weblogic__weblogic-ejb.md]