Posted by dlindsay_roamdata_com
on March 19, 2008 at 8:24 AM PDT
I have an EAR with an single EJB module and a couple of WARs. One of the WARs is a web application using Java Server Faces, and the @EJB injection for a Local EJB deployed within the EAR works fine.
The other WAR contains a single WebService. It is deployed alongside the other web application. When I reference that same Local EJB using identical @EJB notation, the injection works and I get my result fine, but ONLY if I test via the Admin Console's Web Services test GUI. The following snippet is from the Admin Console:
<?xml version="1.0" encoding="UTF-8"?>
If I run a separate HTTP client that sends a SOAP message that is identical to what the Admin Console sent, the same WebService is invoked as from the Admin Console, but the @EJB injection into the local field fails.
What I get is a NullPointerException when I call that object. Here is a small snippet form the stack trace:
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
If I drop the @EJB injection and replace it with and call to retrieve the Remote interface form the InitialContext, the calls from both the remote HTTP client and the Admin Console work fine.
However, this is major problem. Calls to a Remote Interface will always return serialized object data. In this case, a rather lengthy object hierarchy. For example, changing the JSF application by replacing the @EJB injection to use the the Remote EJB interface caused response time to change from a few milliseconds to a few seconds!
Both web applications (WebService and JSF) are calling the same identical SessionBean. Why is it that the JSF application is working fine and the WebService application only works fine form the Admin Console?
Here is a snippet form my WebService:
@WebService(targetNamespace = "http://com.roamdata.gateway/webservice/types")
public class RoamGatewayImpl
private static Logger log = Logger.getLogger(RoamGatewayImpl.class);
GatewaySessionRemote gateway = GatewaySessionBean.getRemoteGateway();
// //TODO: Why isn't injection working
// public GatewaySessionLocal gateway;
The call to GatewaySessionBean.getRemoteGateway() looks like this:
public static GatewaySessionRemote getRemoteGateway()
InitialContext ctx = new InitialContext();
return (GatewaySessionRemote) ctx.lookup(GatewaySessionRemote.class.getName());
catch (Exception e)
I even tried to directly look up the Local inteface using a separate method identical to the one above with the exception of using the class GatewaySessionLocal instead.