Chapter 40. Working with Contexts
40.1. Understanding Contexts
Handlerimplementations have direct access to the contexts and can access all properties that are set in them. Service implementations access contexts by having them injected, and can only access properties that are set in the
APPLICATIONscope. Consumer implementations can only access properties that are set in the
Figure 40.1. Message Contexts and Message Processing Path
How properties are stored in a context
MessageContextinterface extends the
java.util.Map<String key, Object value>interface.
Mapobjects store information as key value pairs.
Stringthat identifies the property. The value of a property can be any value stored in any Java object. When the value is returned from a message context, the application must know the type to expect and cast accordingly. For example, if a property's value is stored in a
UserInfoobject it is still returned from a message context as an
Objectobject that must be cast back into a
- Properties scoped as
APPLICATIONare available to JAX-WS
Handlerimplementations, consumer implementation code, and service provider implementation code. If a handler needs to pass a property to the service provider implementation, it sets the property's scope to
APPLICATION. All properties set from either the consumer implementation or the service provider implementation contexts are automatically scoped as
- Properties scoped as
HANDLERare only available to JAX-WS
Handlerimplementations. Properties stored in a message context from a
Handlerimplementation are scoped as
setScope()method. Example 40.1, “The
MessageContext.setScope()Method” shows the method's signature.
Example 40.1. The
void setScope(String key,
Overview of contexts in handlers
Handlerinterface have direct access to a message's context information. The message's context information is passed into the
Handlerimplementations have access to all of the properties stored in the message context, regardless of their scope. In addition, logical handlers use a specialized message context called a
LogicalMessageContextobjects have methods that access the contents of the message body.
Overview of contexts in service implementations
APPLICATIONfrom the message context. The service provider's implementation object accesses the message context through the
Overview of contexts in consumer implementations
- Request context — holds a copy of the properties used for outgoing requests
- Response context — holds a copy of the properties from an incoming response
APPLICATIONin its message context to the consumer implementation's response context.