Sending HTTP transport headers

This task explains how to enable an existing Web services client to send values in HTTP transport headers. By modifying your client code to send transport headers, one can send specific information within the HTTP transport headers of outgoing requests.

 

Before you begin

You need a Web services client that one 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

  1. Create a java.util.HashMap that will contain the HTTP header identifiers and the associated values.

  2. Add an entry to the HashMap for each header that you want the client to send.

    1. 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.

    2. Set the HashMap value to a string that contains the header value to send in the HTTP header.

  3. 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.

  4. 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.

 

Result

You have a Web service client that is configured to send HTTP transport headers.


 

See Also


Extensions to the JAX-RPC and Web Services for J2EE programming models
HTTP transport header properties best practices