Using a Message Handler to alter the SOAP Header in a Web Service Client

Sometimes you need to insert information in the soap header when calling a web service. Perhaps the service needs authentication information that needs to be set.
This example shows how to set the security information for a Web Service that is deployed on a Weblogic server using JAX-WS and SAAJ.

First we need to create the actual handler which implements the SOAPHandler interface.
Next we need to create the class that implements the HandlerResolver interface. This class decides what handlers should be called and in what specific order. The handler above is added to this class.
Finally we need to add the HandlerResolver instance to the Web Service Client.

Continue reading

Create a Web Service Client with JAX-WS

This example shows how to create a web service client using JAX-WS reference implementation and its tool ‘wsimport’.
JAX-WS RI can be downloaded from Sun (

To create the web service client we need an existing web service, so we will use the one created in the example ‘Create a simple Web Service’:

Click here to go to the ‘Create a simple Web Service’ example

So we assume the web service is deployed on our local computer and it listens to port 8080.
Go to the bin directory in the jax-ws ri installation directory and run the command wsimport.bat (if Windows, else and pass the url to the wsdl-file as a parameter.

Continue reading

Create a simple Web Service

This code example shows how to create a simple web service. We use the annotation @WebService to declare the class as a such.
The annotation @WebMethod is provided at method level to declare it as an operation for the web service.
The operation getTime of the JavadbWebService simply returns the current time.

Continue reading