Java Reference
In-Depth Information
Example5-9.A web service operation that defines headers
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace="urn:soacookbook.saaj")
public class CalculatorWS {
@WebMethod(operationName="add", action="add")
public int add(@WebParam(name = "i") int i,
@WebParam(name="j") int j,
@WebParam(header=true, name="passwordHeader",
m ode=WebParam.Mode.IN) String passwordHeader) {
System.out.print("Header value was: " + passwordHeader);
System.out.print("i=" + i + ". j=" + j);
return i + j;
}
}
The highlighted code shows how you are adding the header to your web service definition.
Using the @WebParam annotation, you specify header=true , and then give the parameter a
name and a Java type. The Java type will get translated to an XML schema type when the
WSDL is generated. This method of creating a header is quick and easy, but can have certain
implications for services and clients. We'll examine this more later, when we look at how to
deal with headers in JAX-WS.
For now, you'll just package this service in a WAR's WEB-INF/classesdirectory, deploy, and
the WSDL will be generated for you. You can then examine the WSDL to determine how you
need to structure a SOAP message that will comply with the interface.
Examining the WSDL
Now that you've deployed your service, here is the WSDL that wsgen generates for you in the
JAX-WS reference implementation (in Glassfish) at deploy time:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/
2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="urn:soacookbook.saaj"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="urn:soacookbook.saaj"
Search WWH ::




Custom Search