Session EJB and Servlet Collocated in Same WAR, JNDI Lookup: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 17: Line 17:
=EJB Lookup=
=EJB Lookup=


<pre>
try {
  InitialContext  ic = new InitialContext();
  SimpleStateless bean = (SimpleStateless)ic.lookup("java:global/wrapper-servlet/SimpleStatelessBean");
}
catch(Exception e) {
    ...
}
</pre>


=EJB Invocation=
=EJB Invocation=


Once the EJB reference is obtained from JNDI
Once the EJB reference is obtained from JNDI

Revision as of 16:31, 24 March 2017

Internal

Overview

This example describes the look up of an EJB and subsequent invocation, when the EJB and the calling component (a servlet, in this case) are part of the same WAR deployment artifact. The lookup is done via JNDI.

GitHub Example

https://github.com/NovaOrdis/playground/tree/master/jee/ejb/stateless-and-servlet-same-war-jndi

Business Interface Type Access

The EJB code and the calling component code are part of the same deployment unit, so the calling component has implicit access to the business interface class. No special configuration is needed here.

EJB Lookup

try {

   InitialContext  ic = new InitialContext();
   SimpleStateless bean = (SimpleStateless)ic.lookup("java:global/wrapper-servlet/SimpleStatelessBean");
}
catch(Exception e) {
    ...
}

EJB Invocation

Once the EJB reference is obtained from JNDI