This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

JAX-WS @WebServiceRef injection NullPointerException solution in NetBeans

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I get a NullPointerException when attempting to use dependency injection in a web service Client program. I have been trying to figure out this problem for a while now. The article Unmanaged JAX-WS clients do not allow injection of @WebServiceRef or @WebServiceRefs resources on IBM's support website provides a clue.

After searching all over the place for a solution, I could not find it ... until I started reading the Java EE 5 tutorial. Its on Page 488 of the Java EE 5 tutorial PDF. After some guessing, the following works.

This is using NetBeans IDE 6.8 (needless to say, I don't know how to do the same thing in Eclipse)

Project structure looks like this:

HelloWs (Create a project of type Java Web->Web Application)-->Web Services-->HelloWebService

Create the web service project
Create a web service called HelloWebService in the project, and make a note of the service name you provide.

@WebService(serviceName="GreeterWs")
@WebMethod(operationName = "sayHello")
public String sayHello(@WebParam(name = "name") String name) {return "Hello" + name;}

Create a client project

HelloWsClient (Project type is Java EE->Enterprise Application Client)

// note that HelloWs is the project and GreeterWs is the exposed service name
@WebServiceRef(wsdlLocation="http://localhost:8080/HelloWs/GreeterWs?wsdl";)
GreeterWs service; // will be injected. note the data type of the variable. its the service name provided in the @WebService annotation

HelloWebService ws = service.getHelloWebServicePort();
System.out.println ("HelloWebService returned: " + ws.sayHello("Saying hello!"));

Make sure that you can see the wsdl. Right-click the client project and select Run File, and it should work.

Hope this is helpful to someone!

Now a question if you are still reading this. I am assuming that we just created a "managed" JAX-WS client. This works because I have Glassfishv3 on my local machine. What if the web service were on a remote server and the local machine running the client did not have Glassfish installed? So there is nothing on the client side to "manage" it. Would the client still work?

Regards,

Srini
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
To launch a managed client independent of any IDE, you use the appclient command in the GlassFish distribution: http://docs.sun.com/app/docs/doc/820-7701/appclient-1m?a=view
You only need an Application Client Container, in order for this to work, not the entire GlassFish container. I haven't used a standalone Application Client Container yet, though.
Best wishes!
 
R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Ivan, for the pointer to the appclient man page!

I noticed that NetBeans generates two jars for project HelloWsConsumerClient:
a) HelloWsConsumerClient.jar
b) HelloWsConsumerClientClient.jar

I am able to run the client in two ways now from the <netbeans project directory>\dist directory:
1. <glassfishv3 install dir>\glassfish\bin\appclient -jar .\HelloWsConsumerClient.jar
2. <glassfishv3 install dir>\glassfish\bin\appclient -client .\HelloWsConsumerClientClient.jar

Thanks for your help!

Regards,

Srini
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic