Java Reference
In-Depth Information
</port>
</service>
</definitions>
This WSDL allows headers to be passed as method parameters, using the SOAP headers ele-
ment. Just as you might add HTTP headers in a regular HTTP request when using a servlet,
this WSDL specifies that the username and password headers are to be added as child ele-
ments of the SOAP
<header>
element in the envelope.
Note the
verify
operation on the
EmailCheck portType
. It specifies an attribute called
para-
meterOrder
. This attribute indicates what order the
Holder
will assign to the parameters
within its array, following any regular parameters to the method. In this example, the
para-
meters
message will come first, followed by the username header and then the password
header.
This WSDL was generated using the following web service implementation class:
public String verify(
@WebParam(mode=WebParam.Mode.IN,
name="email")String email,
@WebParam(mode=WebParam.Mode.INOUT, header=true,
name="username") Holder<String> username,
@WebParam(mode=WebParam.Mode.INOUT, header=true,
name="password") Holder<String> password){
This is perhaps the easiest way to define a web service that requires headers. You need to do a
few things to make this work. First, define the parameters as regular parameters on the meth-
od using
@WebParam
, set
header=true
, and then indicate the headers as method parameters
of type
Holder<T>
, where
T
is the type that you want clients to define. Finally, indicate that
the headers are inbound using the
Mode
enum. This is easy for clients to work with because
a standard
wsimport
will do all of the right things, making it very straightforward to include
the appropriate header values.
This can work because in JAX-WS 2.1, the
wsdl:part
s from the abstract part of the WSDL
(that is, those defined within the
portType
) are mapped to Java method parameters. But not
all WSDLs are defined this way, so you may need to do a little extra work to deal with differ-
ent kinds of WSDLs. We'll examine these different methods now.