Library Link To Toggle Frames Print Feedback

Working with Consumer Connection Properties

You can use JAX-WS contexts to customize the properties of a consumer proxy. In particular, contexts can be used to modify connection properties and to send data in protocol headers. For example, you could use contexts to add a SOAP header, either to a request message or to a response message. The following types of context are supported on the client side:

Setting a request context

To set a particular request context property, ContextPropertyName, to the value, PropertyValue, use the code shown in Example 8.1, “Setting a Request Context Property on the Client Side”.

Example 8.1. Setting a Request Context Property on the Client Side

// Set request context property.
java.util.Map<String, Object> requestContext =
  ((javax.xml.ws.BindingProvider)port).getRequestContext();
requestContext.put(ContextPropertyName, PropertyValue);

// Invoke an operation.
port.SomeOperation();

You have to cast the port object to javax.xml.ws.BindingProvider in order to access the request context. The request context itself is of type, java.util.Map<String, Object>, which is a hash map that has keys of String and values of arbitrary type. Use java.util.Map.put() to create a new entry in the hash map.

Reading a response context

To retrieve a particular response context property, ContextPropertyName, use the code shown in Example 8.2, “Reading a Response Context Property on the Client Side”.

Example 8.2. Reading a Response Context Property on the Client Side

// Invoke an operation.
port.SomeOperation();

// Read response context property.
java.util.Map<String, Object> responseContext =
  ((javax.xml.ws.BindingProvider)port).getResponseContext();
PropertyType propValue = (PropertyType) responseContext.get(ContextPropertyName);

The response context is of type, java.util.Map<String, Object>, which is a hash map that has keys String and values of arbitrary type. Use java.util.Map.get() to access an entry in the hash map of response context properties.

Supported contexts

Celtix Enterprise supports the following context properties:

Table 8.1. Context Properties

Package
Property Name Property Type
org.apache.cxf.ws.addressing.JAXWSAConstants
CLIENT_ADDRESSING_PROPERTIES org.apache.cxf.ws.addressing.AddressingProperties