File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes JAX-WS @Resrouce injection still not working Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "JAX-WS @Resrouce injection still not working" Watch "JAX-WS @Resrouce injection still not working" New topic
Author

JAX-WS @Resrouce injection still not working

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
If you want the underlying information of who's calling your web service (say, the remote IP), the only way I know how to do it is to enable "Resource injection".

However, no matter what I do, it will not work.

Here's the setup code:

// Enable dependency injection on web service context.
@Resource
WebServiceContext wsContext;

at the top of a JAX-WS web service.

----------------------------------

Then, later in the web service code, inside a @WebMethod:

public String getLatest()
{

/* NullPointerException happens here ---> */ MessageContext context = wsContext.getMessageContext();

.
.
.

}

???

When I run the client web service, I always get a NullPointerException as shown at the line above.

Web.xml seems to have the correct information in it so I'm totally stumped.

Has anyone gotten this working?

Thanks in advance.

Mike
Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2160
Hi again!
Have you tried to deploy your web service to GlassFish (I recall you said you used Tomcat last time we discussed this issue)?
This way, you can hopefully determine if your web service really has problems or if the problem is the Tomcat environment.
Best wishes!
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Hey,

I downloaded GF3, but MyEclipse doesn't yet support it (until 8.5 which is due almost anytime). I've actually been trying to switch to Intellij IDEA for development (their tech support is incredible!), but, unfortunately, their 9.0.1 product has a bug with web services too! This bug will (hopefully) be fixed in 9.0.2...due out maybe Mar, 2010.

Therefore, I remain in "stuck-ville" for the moment.

I appreciate all your replies!

Thanks.

Mike
Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2160
Hi!
You could build a WAR and deploy it manually to the GlassFish server.
Deploying is done by copying the WAR to the following directory in the GlassFish v3 installation directory: glassfish/domains/domain1/autodeploy
The name "domain1" may be different depending on your configuration.
Best wishes!
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Could I use the same client program if I just changed the port to 8001 (the one I used for GF)?

Mike
Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2160
Hi!
Mike London wrote:Could I use the same client program if I just changed the port to 8001 (the one I used for GF)?

The same web service client program?
Yes, providing there are no changes in the WSDL (except for the endpoint address), there should be no problems.
Best wishes!
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Cool, thanks Ivan!

I'll post back with updates.

This message was edited 1 time. Last update was at by Mike London

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Glassfish gives this main error (part of an error stack) when I try to deploy to autodeploy folder:

Caused by: java.lang.IllegalArgumentException: Servlet [MyWSPortImpl] and Servlet [MyWSDelegate] have the same url pattern: [/MyWSService]

???
Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2160
Can you post the complete code?
I must admit that I have never seen that kind of error before.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Hi Ivan,

I'll try to post an example that reproduces the same problem shortly.

Thanks very much for your continuing replies!



Mike
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Hello,

I've now created a very simple JAX-WS Web Service with this code:



The web service deploys and I can get to its WSDL in the browser.

************
HOWEVER....
************

As with my production web service, as soon as the client web service hits the line above where the wsContext.get UserPrincial() is, I get a NullPointerException....as with my previous postings.

My really-simple Web Service Client is this:



=========

The WSDL is this:



===============

The web.xml is this:



============

And the log error dump is:



I now have two projects (the service and the client) I can post if there's someway to post binary files.

Look forward to any possible reasons why I keep getting NullPointerExceptions.

Thanks very much.

-- Mike

This message was edited 3 times. Last update was at by Mike London

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
I've now reproduced this behavior (bug?) on two Tomcat installations?

Can anyone see what the problem might be?

Thanks.

Mike
Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2160
Hi!
Try adding a file named "sun-jaxws.xml" next to the web.xml deployment descriptor with the following contents:

Best wishes!

This message was edited 1 time. Last update was at by Ivan Krizsan

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
Hi Ivan,

Here's the sun-jaxws.xml file that MyEclipse already created in the web-inf directory:



I'm using the MyEclipse IDE (now version 8) and it's (supposedly) generating everything.

My best guess at this point is that MyEclipse is not putting in a required library or something like that (yet I can run the web service if I remove the attempt to access the context).

I can send you a WAR file if you want to see if a generated client you create successfully runs against this service.

Let me know.

Thanks.

Mike
Ivan Krizsan
Bartender

Joined: Oct 04, 2006
Posts: 2160
Hi!
NetBeans also generate the Sun webservice deployment descriptor behind the scenes, while the standard version of Eclipse do not.
I would really like to take a look at that WAR, so please send it to me. Note that you do not accept private messages, so I cannot contact you using private messages.
Best regards!
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 867
The solution to this @Resource NullPointerProblem, for me anyway, was to create a setter and getter method to apply the @Resource WebServiceContext wsContext variable.

Something like:

@Resource WebServiceContext wsContext

.
.
.

private void setWsContext(WebServiceContext wsContext)
{
// do stuff with the context here....
}

// I also created a public getter, but I'm not sure this is needed.

-----------

Clearly the @Resource was being injected by the Tomcat 6.0.26 container so I'm not sure why code like that in "Java Web Services, Up and Running" simply did not work.

This was all quite confusing.

Also, MyEclipse 8.5 (and earlier versions) doesn't seem to like to re-create an existing web service when you add new methods or change the service's interface. I had nothing but problems using it. The only way around this was to create a brand new project each time I modified the project and copy everything into it. MyEclipse refused (for me) to re-create/update the delegate class for an existing service.

Hope this update is useful.

- M

 
 
subject: JAX-WS @Resrouce injection still not working
 
MyEclipse, The Clear Choice