You can enable an existing Web services client to retrieve values
from HTTP transport headers. By modifying your client code, you can retrieve
information from incoming HTTP headers responses.
Before you begin
You need a Web services client that you can enable to retrieve HTTP
transport headers.
Retrieving transport headers is supported only by Web
services clients, and only over the HTTP transport. The Web services client
must call the Java API for XML-based RPC (JAX-RPC) APIs directly and not through
any intermediary layers, such as a gateway-like function. Sending and retrieving
HTTP transport headers on the Web services server-side is done through non-Web
services APIs.
About this task
The client must set a property on the Stub in order to retrieve
values from the HTTP transport headers. Once the property is set, values are
read from HTTP responses for the subsequent method invocations against that
Stub until the associated property is set to null or the Stub is
discarded. To retrieve values from the HTTP transport headers on inbound responses,
modify the client code as follows:
Procedure
- Create a java.util.HashMap that contains the HTTP header identifier
values to retrieve and the values for those headers on responses.
- Add an entry to the HashMap for each header that you want the client
to retrieve a value from.
- Set the HashMap entry key to a string that exactly matches the
HTTP header identifier. The header identifier can be defined for
HTTP, such as Cookie, or it can be user-defined, such as MyHTTPHeader. Certain
header identifiers are processed in a special manner, but no other checks
are made to confirm the header identifier value. To learn more about the header
identifiers that have special consideration, see HTTP transport header properties best practices. Common
header identifier string constants, such as HTTP_HEADER_SET_COOKIE can be
found in the com.ibm.websphere.webservices.Constants class. The HashMap entry
value is ignored and does not need to be set. An empty HashMap, for example,
one that is non-null, but does not contain keys, causes values from all headers
in the HTTP response to be received.
- Set the HashMap entry on the Stub using the com.ibm.websphere.webservices.Constants.RESPONSE_TRANSPORT_PROPERTIES property.
When the HashMap is set, the RESPONSE_TRANSPORT_PROPERTIES property
is used in subsequent invocations to retrieve the headers from the responses.
If you set the property to null, no headers are retrieved from the
response. To learn more about the properties used, see HTTP transport header properties.
- Issue remote method calls against the Stub. The values
from the HTTP response headers are placed in the HashMap.
You might experience
API usage errors that result in a JAXRPCException. The following items are
checked for during invocation and cause an exception to be thrown if there
is an error:
- The property value that is set on the Stub is either null or
a HashMap.
- All the HashMap keys are not non-null and an instance of a String.
Results
You have a Web service that is able to receive HTTP transport headers.