Java Reference
In-Depth Information
Using Header References with Holder<T>
Problem
You want to define an operation that requires SOAP headers and invoke it from a client.
Solution
In the service, use the @WebParam annotation with your operation parameter. Specify header-
=true , and wrap your parameter in a Holder<T> , where T is the actual type of the parameter
you want. On the client, use a Holder<T> to set the values of the parameter elements and get
the return values with a reference.
Discussion
The following examples illustrate how to use a Holder to handle the SOAP headers required
for using a web service. This is a command-line client for the web service, and it is totally
portable; it doesn't rely on proprietary extensions within Glassfish or another container. The
web service and WSDL are shown as well to help aid your understanding the process.
First, you'll create a web service using the “Start from Java” approach. This is easy to do, and
lets you generate a WSDL with wsgen that indicates the required header values. Most con-
tainers will automatically generate a WSDL for you on deployment, so all you should need
to do is create the Java class as part of a WAR project within your favorite IDE, and package
the class in WEB-INF/classesas you would any other regular Java class. The web service is
shown in Example 7-19 .
Example7-19.Email verifier web service requiring credentials in SOAP headers
package com.soacookbook;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.Holder;
/*
* Very simple web service that shows how to define a service
* that accepts SOAP headers. This is frequently useful for user
* credentials, an authorization token, or some other
* identifier.
*
* Making param mode INOUT means your type must be a Holder.
Search WWH ::




Custom Search