Sending HTTP transport headers
You can enable an existing Web services client to send values in HTTP transport headers. By modifying your client code to send transport headers, you can send specific information within the HTTP transport headers of outgoing requests. We need a Web services client that you can enable to send HTTP transport headers.
Sending transport headers is supported by Web services clients only, and over the HTTP transport only. 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.
Overview
The client must set a property on the Stub to send values in HTTP transport headers. Once the property is set, the values are set in all the HTTP requests for subsequent remote method invocations against the Stub until the associated property is set to null or the Stub is discarded. To send values in the HTTP transport headers on outbound requests, modify the client code as follows:
Procedure
- Create a java.util.HashMap that contains the HTTP header identifiers.
- Add an entry to the HashMap for each header that you want the client to send.
- Set the HashMap entry key to a string that exactly matches the HTTP header identifier. The header identifier can be one that is 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 as to 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 does not need to be set; it is ignored. An empty HashMap (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 value to a string that contains the header value to send in the HTTP header.
- Set the HashMap on the Stub by using the property com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES. When the REQUEST_TRANSPORT_PROPERTIES property value is set, that HashMap is used on subsequent invocations to set the header values in the outgoing requests. If the REQUEST_TRANSPORT_PROPERTIES property value is set to null, no HashMap is used on subsequent invocations to set header values in outgoing requests. To learn more about the HTTP transport header properties see HTTP transport header properties best practices.
- Issue the remote method calls against the Stub. The headers and the associated values from the HashMap are added to the outgoing HTTP request for each method invocation.A JAXRPCException can occur if the property is not set correctly. The following requirements must be met:
- The property value set on the Stub must be a HashMap object or null.
- The HashMap must not be empty.
- Each key in the HashMap must be a String object.
- Each value in the HashMap must be a String object.
Results
You have a Web service client that is configured to send HTTP transport headers.
Implementing extensions to the JAX-RPC and Web Services for J2EE client programming models
Related Reference
HTTP transport header properties best practices