Java Reference
In-Depth Information
Service Locator
Problem
The EJB session beans and message-driven beans are used to implement business
workflows. These components on deployment are registered on the JNDI tree of the
application server. The JNDI provides a directory service, which external clients can use
to discover and look up objects by name. Hence, the JNDI makes EJBs accessible to
remote clients. Besides EJBs, JMS queues, topics, connection factories, and JDBC, data
sources are also bound in the JNDI. Listing 4-1 shows the JNDI lookup code used by the
magic JSP controller of the eInsure application.
Listing 4-1. UnderwritingController.jsp
<%!
final String JNDI_URL = "t3://localhost:7001";
public UnderwritingHome getEJBHome() {
UnderwritingHome home
= null;
try{
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,"");
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, JNDI_URL);
Context ctx = new InitialContext(h);
Object homeObj = ctx.lookup("uwrbusinessslsb");
home = (UnderwritingHome)PortableRemoteObject.narrow(homeObj,
UnderwritingHome.class);
}
catch(Exception e){
e.printStackTrace();
home = null;
}
return home;
}
%>
<%
String eventCode = request.getParameter("eventCode");
 
Search WWH ::




Custom Search