Client Contexts  Locate

Overview  Locate

In WSO2 SOA Enablement Server, there are a number of execution contexts, some of which overlap. Every execution context provides data that is accessible and shared by all instances in the same context. Every execution context also contains a generic map into which application data may be stored.

The two possible contexts on the client side are Service Client Context, below, and Call Context, which may also be a Service Context.

Service Client Context  Locate

Every service client has a context, accessible using the method getContext() on the class org.systinet.wasp.webservice.ServiceClient. Inside a client proxy invocation, this context is accessible by calling the getServiceClientContext() method found in org.systinet.wasp.webservice.Current.

The ServiceClient context may be used for data that pertains to the proxy. For example: a user ID and password under which this proxy is authenticated into its service

This context is persistent, so it is NOT cleared after service call.

Hierarchy of Contexts  Locate

The Service Client context represents the unique context for a service client while the Call Context represents the context valid through one call. There is a hierarchical relation between these contexts. All data from the Service Client context map is accessible from the Call Context context map. Thus you can access data form both maps using the Call Context only.

When you need to have data accessible during all calls you should add this data to the Service Client Context. On the other hand, put data in the Call Context when you need it to be accessible during one call only.

When there is an identical key in both contexts, the value in the Call Context map has higher priority. Due to this functionality, Service Client Context can contain default data valid for all calls and some of this data can be overridden in the Call Context for particular calls only.

The code fragment in Example 93 shows how to take advantage of client context hierarchy:

Example 93. Client Context Hierarchy

ServiceClient serviceClient = ServiceClient.create("http://localhost:6060/" + 
                                  "demo/basic/HelloService/wsdl");

serviceClient.getContext().getContextData().put("MY_KEY", "DefaultValue");

HelloService helloService = (HelloService) serviceClient.createProxy(
                                               HelloService.class);

// During the following two calls, "DefaultValue" value is accessible under the
// "MY_KEY" key, from both the ServiceClientand CallContext data.
helloService.hello("World");
helloService.hello("World");

// override default value
serviceClient.getCallContext().getContextData().put("MY_KEY", "PerCallValue");

// During the following call, the value helloService.hello("World");
// is accessible under "MY_KEY" key, " PerCallValue "
helloService.hello("World");
// During the following call, the "DefaultValue" value is accessible
// under "MY_KEY" key,
helloService.hello("World");