users@glassfish.java.net

_at_EJB injection for an _at_WebService object only works from the Admin Console

From: <glassfish_at_javadesktop.org>
Date: Wed, 19 Mar 2008 07:24:49 PST

Hi,

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:

SOAP Response:

    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
        <S:Body>
            <ns2:echoResponse xmlns:ns2="http://com.roamdata.gateway/webservice/types">
                <result>
                    <message>HaHaHa</message>
                </result>
            </ns2:echoResponse>
        </S:Body>
    </S:Envelope>

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:

java.lang.NullPointerException
        at com.roamdata.gateway.web.WebUtil.createCrypto(WebUtil.java:39)
        at com.roamdata.gateway.webservice.RoamGatewayImpl.initiateSession(RoamGatewayImpl.java:110)
        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
// @EJB
// public GatewaySessionLocal gateway;

The call to GatewaySessionBean.getRemoteGateway() looks like this:

    public static GatewaySessionRemote getRemoteGateway()
    {
        try
        {
            System.gc();
            InitialContext ctx = new InitialContext();
            return (GatewaySessionRemote) ctx.lookup(GatewaySessionRemote.class.getName());
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }

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.


David
[Message sent by forum member 'dlindsay_roamdata_com' (dlindsay_roamdata_com)]

http://forums.java.net/jive/thread.jspa?messageID=264790