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:
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
Glassfish gives this main error (part of an error stack) when I try to deploy to autodeploy folder:
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
The solution to this @Resource NullPointerProblem, for me anyway, was to create a setter and getter method to apply the @Resource WebServiceContext wsContext variable.
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