The context service is responsible for propagating the context (including the protocol headers, such as the JMS header, and the user context, such as account ID) along a Service Component Architecture (SCA) invocation path. The context service offers a set of APIs and configurable settings.
When the context service propagation is bi-directional, the response context will always overwrite the current context. When you are running an invocation from one SCA component to another, a response will contain a different context. A service component will have an incoming context, but when you invoke another service, the other service will overwrite the original outgoing context. The response context becomes the new context.
When the context service propagation is one-way, the original context remains the same.
The lifecycle of the context service is associated with an invocation. A request has associated context, and the lifecycle of that context is bound to the processing of that particular request. When that request is finished processing, then the lifecycle of that context ends.
//Import the necessary classes; import com.ibm.bpm.context.ContextService; import com.ibm.websphere.sca.ServiceManager; import com.ibm.bpm.context.cobo.ContextObject; import com.ibm.bpm.context.cobo.ContextObjectFactory; import com.ibm.bpm.context.cobo.HeaderInfoType; import com.ibm.bpm.context.cobo.UserDefinedContextType; //Locate ContextService; ContextService contextService = (ContextService)ServiceManager.INSTANCE.locateService ("com/ibm/bpm/context/ContextService"); // Get header info HeaderInfo headerInfo = contextService.getHeaderInfo(); // Get user defined context in current execution context UserDefinedContextType userDefinedContext = contextService.getUserDefinedContext(); if(userDefinedContext == null){ // create a new context if context is null userDefinedContext = ContextObjectFactory.eINSTANCE.createUserDefinedContextType() } // Do some modification to header info and userDefinedContext // Set user defined context back to the current execution context. contextService.setUserDefinedContext(userDefinedContext); // Set header info back to the current execution context. contextService.setHeaderInfo(headerInfo);
Context services have configurable rules and tables that dictate the binding behavior. For more information, see the Generated API and SPI documentation that is available in the Reference section. During development in WebSphere® Integration Developer, you can set the context service on import-export properties. For more details, see the import and export bindings information in the WebSphere® Integration Developer information center.