Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JAX-WS @Resrouce injection still not working  RSS feed

 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could I use the same client program if I just changed the port to 8001 (the one I used for GF)?

Mike
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, thanks Ivan!

I'll post back with updates.
 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the complete code?
I must admit that I have never seen that kind of error before.
 
Mike London
Ranch Hand
Posts: 1476
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've now reproduced this behavior (bug?) on two Tomcat installations?

Can anyone see what the problem might be?

Thanks.

Mike
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Try adding a file named "sun-jaxws.xml" next to the web.xml deployment descriptor with the following contents:

Best wishes!
 
Mike London
Ranch Hand
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1476
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!