LibraryLink ToToggle FramesPrintFeedback

Working with Contexts in a Consumer Implementation

Consumer implementations have access to context information through the BindingProvider interface. The BindingProvider instance holds context information in two separate contexts:

[Important]Important

Only information that is placed in the application scope of a message context can be accessed by the consumer implementation.

Contexts are obtained using the javax.xml.ws.BindingProvider interface. The BindingProvider interface has two methods for obtaining a context:

getRequestContext()

The getRequestContext() method, shown in Example 20.7, returns the request context as a Map object. The returned Map object can be used to directly manipulate the contents of the context.


getResponseContext()

The getResponseContext(), shown in Example 20.8, returns the response context as a Map object. The returned Map object's contents reflect the state of the response context's contents from the most recent successful request on a remote service made in the current thread.


Since proxy objects implement the BindingProvider interface, a BindingProvider object can be obtained by casting a proxy object. The contexts obtained from the BindingProvider object are only valid for operations invoked on the proxy object used to create it.

Example 20.9 shows code for obtaining the request context for a proxy.


Consumer contexts are stored in java.util.Map<String, Object> objects. The map has keys that are String objects and values that contain arbitrary objects. Use java.util.Map.get() to access an entry in the map of response context properties.

To retrieve a particular context property, ContextPropertyName, use the code shown in Example 20.10.


Consumer contexts are hash maps stored in java.util.Map<String, Object> objects. The map has keys that are String objects and values that are arbitrary objects. To set a property in a context use the java.util.Map.put() method.

[Tip]Tip

While you can set properties in both the request context and the response context, only the changes made to the request context have any impact on message processing. The properties in the response context are reset when each remote invocation is completed on the current thread.

The code shown in Example 20.11 changes the address of the target service provider by setting the value of the BindingProvider.ENDPOINT_ADDRESS_PROPERTY.


[Important]Important

Once a property is set in the request context its value is used for all subsequent remote invocations. You can change the value and the changed value will then be used.

FUSE Services Framework supports the following context properties in consumer implementations: