Skip to main content

@EJB injection for an @WebService object only works from the Admin Console

11 replies [Last post]
dlindsay_roamda...
Offline
Joined: 2008-03-19

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"?>

HaHaHa

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

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
binhthai
Offline
Joined: 2008-06-24

Hi Bhakti,

Do you also experience that it works with WebServiceProvider implementation?
Instead of @WebService @WebServiceProvider and the implementation of invoke().

Best regards,

Binh

powerhouse_b
Offline
Joined: 2008-03-02

Hi

I was unable to replicate the problem on a demo project I set up; injection worked on the servlet web service, both @EJB and @Resource. So it shouldn't be a bug, more like a misconfiguration of my project. The problem is I don't know what could be wrong, maybe a NetBeans bug.
My project could be a little harder to set up, because it uses a database, wss and jdbc real. If you want/have time, I could sent it.

Thanks!
P.S The project you showed is for EJB Web Service, we were refering to a servlet Web Service.

dlindsay_roamda...
Offline
Joined: 2008-03-19

Hi,

If you read my prior post, you'll find the answer.

A published webserivce is accessible via 2 distinct and different outwardly facing URLs (?!?!)

The web.xml file defines one URL where @EJB injection fails. The admin console refers to a completely different URL, where Injection works.

In other words:

web.xml == /ws/RoamGateway == WWW accessible == Injection Failure
admin console == /ws/RoamGatewayImplService == WWW accessible == Injection works

I never define the "/ws/RoamGatewayImplService", the admin console/ GF deployment just makes it up. I see this as a hazard. What is the point in defining a URL in web.xml if it is just a dud, and why have 2 outwardingly facing service for the same endpoint?

I would thing that the web.xml should work (with Injection support) and the service referenced by the admin console should not even exist.

David

palma_it
Offline
Joined: 2009-02-23

Hi,

I am running into this same problem almost one year later. I have just downloaded and tried it on GlassFish2.1 but the problem still exists.

My service is not working with my configured url but is is when I use the url that is used by the admin console.

David, were you able to solve it in your situation? If so, can you post how you did it?

Does someone else know if this is a unresolved bug in Glassfish?

palma_it
Offline
Joined: 2009-02-23

Here are some code snippets to show the problem:

In the WebService implementation class I have:
@WebService(targetNamespace = "http://www.pascalalma.net/EchoIt",
portName="EchoItPort",
serviceName="EchoItService",
endpointInterface="net.pascalalma.echoit.EchoItPortType")
public class EchoItPortTypeImpl {

@EJB
private CustomerServiceLocal cs;

public String echoIt(String it)
{

return "Echo " + it +": " + cs;
}
}

In the Admin tester with URL 'http://localhost:8080/my-ws/EchoItService?tester' I get:
SOAP Request






12



SOAP Response





Echo 12: net.pascalalma.myservices.CustomerServiceLocal_16516284


In SoapUI with test url 'http://localhost:8080/my-ws/services/echoit' (based on content of web.xml):
Request:




12



Response:



Echo 12: null


Why does Glassfish behave differently when using the expected URl instead of its internal constructed one ?

palma_it
Offline
Joined: 2009-02-23

Okay,

Just found the 'solution' here: http://blogs.sun.com/arungupta/entry/deployment_descriptor_free_web_serv...

When deploying annotated webservices (JAX-WS) to glassfish no descriptor files are used/ necessary, so I guess they are ignored and/or at least lead to the described behaviour.

I can live with the descriptor-less deployment, now I know how it works ;-), so I consider this issue as solved.

bhaktimehta
Offline
Joined: 2004-03-18

This seems like a bug. Pls can you send your NB project/sources so I can look at it. You can also file a bug at glassfish.dev.java.net under webservices
Thanks,
Bhakti

dlindsay_roamda...
Offline
Joined: 2008-03-19

Hi,

I have further researched the issue and may have some more insight. Please see:

http://forums.java.net/jive/thread.jspa?threadID=38399&tstart=0

There I have included some additional snippets and xml files in that thread. It appears that there is not an issue with the WAR inside the EAR using injection to get a Local interface because it can do so with an ordinary HTTPServlet that gets deployed alongside the WebService.

It is more clearly a problem with @EJB dependency injection failing for web services when called from outside of the Admin Console, which is what happens 99.99% of the time.

I can't provide the full project or source files because they are proprietary to my company. If you need more information, I can perhaps provide more or come up with a sample project.

David

bhaktimehta
Offline
Joined: 2004-03-18

I would appreciate if you could come up with a sample. I tried another bug where someone reported @EJB not working with WebserviceProvider but that worked for me so if you could provide a testcase would be easier to track it down
Regards,
Bhakti

bhaktimehta
Offline
Joined: 2004-03-18

FWIW I tried the following case where I could get @EJB to work. Thought would attach it for you. Not sure how different your config is but hope this could help
Regards,
Bhakti

dlindsay_roamda...
Offline
Joined: 2008-03-19

Hi,

I found out the cause of the problem, but I would still consider registering this as either a bug or an RFE.

In my web.xml file, I am defining the servlet associated to the web service as /RoamGateway:


RoamGatewayService
/RoamGateway

The web application is named ws and the, so therefore the URL that all of my client are using is "ws/RoamGateway". We have PHP, J2ME, Java and MS applications hitting this service with this URL. The web service will work, but local EJB injection fails. So the remote interface had to be called, with made for a miserable performance hit.

I then looked closer at what the Admin Console was using for a URL, and it was using a completely different URL to access the web service. It was using "ws/RoamGatewayImplService". When I rewrote my test clients to use this URL instead, injection began working.

The problem I have is that my service is accessible via 2 completely separate URLs, the later one being unconfigurable by the author and completely disassociated with the URL defined in the web.xml. In other works, I need to refer to the admin console for every WS I author in order to see what the heck the REAL endpoint URL is.

I'd be hard pressed to believe that this is functioning as designed.

David