Business context service
The business context service manages contextual information used by business components. The information is encapsulated within different types of business contexts, this process formalizes the context infrastructure and fosters reuse between different business models.The abstraction of user contextual information permits:
- Enablement of generic components
- Tailored content and experience
- Precisely targeted offers
- Enforcement of business policies
- Appropriate prices, entitlements, and terms for a particular user
Before the logic to process the operation is invoked, contextual information is set up and managed by the business context service. After the processing is complete, business context service is invoked to handle any post processing of the context information such as persistence. In the business context model, a client invokes a service to perform an operation. Optionally, the client might receive a response. An example of a business service is a service that helps a company fulfill the needs of its customers. Multiple services can be logically grouped into business components. A component specializes in a function such as catalog management or tax calculation.
The following diagram shows the artifacts in the business context model.
- Solution controller
- A solution controller is responsible for managing the activity or activities of a user. In the WebSphere Commerce Struts framework the solution controller exists as part of the base action. In the Sales Center the solution controller exist as part of the rich client application. The client performs a limited set of actions while the solution controller provides the additional BCS process hooks.
- Activity token
- An identifier for an activity which spans multiple requests and transactions. An activity usually begins when a user logs on to the site and ends when a user logs off. The activity token is unique for each caller, run-as user, and store.
The activity token groups the set of contexts effective during a particular client's request to the various business components. The client supplies this activity token on every request to indicate the experience that it would like from the business components. Usually, the solution controller initiates a request to business context service to request for an activity token.
- Business components
- A business component groups a set of related services together and a service provides a specialized function. It interacts with business context service to signifies the beginning and the end of a request such that any pre and post processing on business contexts can be done. Also, components can retrieve and update various business context during the execution of a request.
- Business Context Engine
- The business context engine (BCE) provides contexts that dictate the behavioral characteristics of business components over the lifetime of the session. The business context engine is comprised of the Business Context Service and Business Contexts.
- Business Context Service
- The solution controller uses the business context service (BCS) to manage contexts required by business components. BCS is also an interface used by the components to obtain contexts they need. Multiple unique contexts, used by various business components, are associated under a single identifier, known as an activity, for a limited lifetime. The lifetime of an activity spans multiple requests and transactions. The contexts associated with an activity maintain their state for the lifetime of the activity. BCS also manages a cache of the business contexts associated with an activity within a request. This cache saves resources that would otherwise be used to initialize and destroy multiple business contexts used in the same request.
- Business Contexts
- Business contexts have the following characteristics:
- A context establishes an execution environment that affects the output of a business component for the equivalent input based on the solution needs.
- The output produced by a component for a given input is always identical for the same set of contexts.
- Contexts are not directly invoked by clients of the business processes. Instead it is the business component that uses the services provided by the contexts during the execution of a request.
- A context provides a set of service methods and may optionally store session data that does not change very often over an activity lifespan.
- The lifespan of a context starts with the creation of an activity and ends with the completion of the activity.
- Each business context implements two interfaces:
- ContextSPI
- The ContextSPI interface defines methods for business context service to indicate events such as the beginning of an activity, the start and end of a request.
- Context
- The Context interface is extended by each business context which defines methods for business logic to use to retrieve context specific information.
WebSphere Commerce predefines the following contexts:
- BaseContext
- This context contains the basic attributes that an activity needs, such as store ID, caller ID, and the run-as ID.
- EntitlementContext
- This context holds information about entitlement criteria, such as reduced prices for gold club membership.
- GlobalizationContext
- This context helps components determine locale-specific information such as what language a message should be rendered in, or what currency should be used in the calculation of a price.
- ContentContext
- If Workspaces are enabled, this context determines the content or business objects that can be displayed or edited based on versioning information.
- TaskContext
- If Workspaces are enabled, this context determines which task an administrator is currently performing.
- AuditContext
- This context is usually provided by third party components. You might want to bridge the gap to the third party interface instead of programming to it directly. This context enables you to connect to a different vendor's implementation of the service in the future without the need to rewrite your component.
- PreviewContext
- The preview context is the attempt to solve both problems by allowing multi-users to validate independent content without influencing other users and ensuring the content does not required additional changes after validation. In order to achieve this, a context object will be associated with the preview operation that will represent the state information that will be used when deciding the content to preview along with other external events. By associating a preview context with an activity, operations can use this content state information as a basis to decide what content to display. To solve the date issue, the preview context will contain the preview date which will be used to render the content to be display. By having activities having a unique preview context, this will allow multiple users to preview independent content without having to change content data or global system state information.
- ExperimentContext
- ExperimentContext is used to store the result of all active experiments for individual users, where result is a system-generated number which determines the control or test element to be selected in the experiment. This information is persisted throughout the user session, so the same result will be used in the same session without re-generation of the number.
- Business Context Sets
- Business contexts are grouped together in business context sets. A business context set is a logical grouping of business contexts for a particular type of request. Different context sets can be configured for requests coming from different Web applications. For example, requests that are initiated from the Accelerator web application need to include content and task contexts for authoring purposes, while requests from the store web application do not have this requirement. This implementation provides these advantages:
- It improves performance, unneeded business contexts do not need to be initialized. For example, when customers browse the catalog in the storefront, they do not need the presence of the PreviewContext which is for previewing purposes in the authoring environment.
- It provides security benefits. For example, requests from the Stores Web application do not need to enable the PreviewContext which removes the preview functionality from the customer.
- Sequence diagram: Initiating an activity
To invoke a method on a business component, a client or a solution controller obtains an activity token by calling BCS begin method. In the process of obtaining this activity token the client may optionally supply initialization data. This initialization data is used to populate the contexts that are preloaded when a new activity is created. When a particular service method is invoked on a Business Component Service interface the client must pass the activity token.- Sequence diagram: Creating a new activity based on an existing one
This diagram shows the interactions between BCS and the Context SPI when the Solution Controller creates an activity based on an existing activity. Creating a new activity could be initiated when a user switches from one store to another, or when an administrator performs a task on behalf of a customer.- Sequence diagram: Terminating an activity
This diagram shows the interaction between the Solution Controller and BCS when an activity is terminated. Usually, an activity terminates when a user logs out of the site.- Sequence diagram: Pre-request and post-request processing
This diagram shows the interaction between the BCS and Context SPI. Either interface can indicate that is about to start execution or has completed execution.- Sequence diagram: Retrieving and updating business contexts
This diagram illustrates how a business component retrieves and updates context information. The following example shows how the preferred language of a user is set on the GlobalizationContext.- Business Context configuration file
Default business contexts are defined in the xml/config/businessContext.xml file. The location of the file is defined in the BusinessContextService/BusinessContextConfigFile attribute in WebSphere Commerce configuration file. Multiple file locations separated by commas are allowed for this attribute to support componentization. That is, when creating a new business context, instead of modifying the default configuration file, you can define it in a separate file and append it to the end of the BusinessContextConfigFile attribute. This implementation allows for future upgrade to the businessContext.xml file without affecting the business context that you have registered.- Define business context sets for a Web application
Business contexts establish an execution environment that affects the output of a business component for the equivalent input based on the solution needs. The output produced by a component for a given input is always identical for the same set of contexts. Contexts are not directly invoked by clients of the business processes. Instead it is the business component that uses the services provided by the contexts during the execution of a request. A context provides a set of service methods and may optionally store session data that does not change very often over an activity lifespan. The lifespan of a context starts with the creation of an activity and ends with the completion of the activity.- Create a new business context
All business contexts are registered in a business context configuration file. In the file, you have to specify a business context factory class to create the business context. If the SimpleBusinessContextFactory class, the default factory class, is used to create the business context, provide the name of the implementation class as one of the parameters to the factory. To register a business context in the system, refer to the business context configuration file.Related tasks
Define business context sets for a Web applicationRelated reference
Business Context configuration file
Sequence diagram: Creating a new activity based on an existing one
Sequence diagram: Initiating an activity
Sequence diagram: Pre-request and post-request processing
Sequence diagram: Retrieving and updating business contexts
Sequence diagram: Terminating an activity