IBM® WebSphere® Enterprise Service Bus (hereafter called WebSphere ESB) enables loosely coupled connectivity between service requesters and service providers in service-oriented solutions. Loose coupling creates a clean separation of concerns between solution components, enabling flexibility and agility in both business processes and IT systems.
This article shows you how to implement mediation policies in WebSphere ESB that retrieve policy information to make runtime decisions from WebSphere Service Registry and Repository (hereafter called Service Registry). In order to control service requests using mediation policies, you need to have suitable Service Component Architecture (SCA) modules and mediation policy documents in Service Registry.
Mediation policy definitions in Service Registry
Policies specify the requirements that must be met so that a service can be consumed by a client. WS-Policy standard provides a simple language for describing policies in XML. Each policy consists of one or more policy assertions, which do not really follow any predefined format, other than the fact that they use XML. Service Registry supports the loading, retrieving, and editing of policies. The implementation of service policy management in Service Registry is based on the following standards:
- Web Services Policy 1.5 -- Framework (WS-Policy)
- Defines an abstract model and an XML-based expression grammar for declaring policies.
- Web Services Policy 1.2 -- Attachment (WS-PolicyAttachment)
- Defines mechanisms for associating policies with the subjects to which they apply.
A company provides a credit score service to its customers and charges them based on certain parameters, such as whether customer age is under 18 and whether it is an online application. The pricing policies are stored in the service registry. Here is the assembly diagram for the credit score service:
Figure 1. SCA assembly module

This article will show how you to define the pricing policies in Service Registry and how to use them in the mediation flow through the following steps:
- Create a mediation module in WebSphere ESB with the policy resolution primitive.
- Load an SCA module and the associated mediation policies in Service Registry.
- Create a mediation policy for the SCA module.
- Attach a mediation policy to the SCA module.
- Create a conditional mediation policy.
Creating a mediation module in WebSphere ESB with the policy resolution primitive
Figure 2. Mediation module

Figure 2 shows the mediation module for the credit score service. The pricing policy primitive retrieves the appropriate pricing policy from Service Registry based on the request parameters shown in Figure 3 below, and the assertion amount is obtained from the policy and is set in the dynamicProperty context field, as shown in Figure 4:
Figure 3. Policy resolution primitive

Figure 4. Dynamic property context in SMO

Any property promoted from a primitive in the top-level request, response, or fault flow is a dynamic property, which can be overridden at runtime using a mediation policy. In Figure 5, the promoted property amount is overridden at runtime and set using the values of the corresponding assertion field:
Figure 5. Promoted properties

Depending on the policy chosen at runtime from Service Registry, the amount will be different depending on the requestor age and channel. The Policy Details Table shows the amounts that will be set in the dynamicProperty context field:
Policy details
| Policy Group | Condition for the policy | Assertion Field |
|---|---|---|
| Group A | customer age < 18 and channel = web | Amount = 100 |
| Group B | customer age > 18 and channel = web | Amount = 200 |
| Group C | customer age < 18 and channel = other | Amount = 200 |
| Group D | customer age > 18 and channel = other | Amount = 500 |
Loading an SCA module and associated mediation policies in Service Registry
Export SCA module as an EAR file to the local file system. When the SCA module is exported, WebSphere Integration Developer generates a default mediation policy for each property group in your SCA module. The default mediation policies represent the values given to all dynamic properties at development time. Although WebSphere Integration Developer generates default mediation policies, it does not attach them to the SCA module. After you load the EAR file containing the SCA module, Service Registry creates an SCA module document and also loads any system-generated mediation policies:
Figure 6. Credit module in Service Registry

Creating a mediation policy for an SCA module
- In the navigation pane of the Service Registry Web UI, click Service Documents => Policy Documents => New.
- Select WS Policy Framework 1.5 and click Next.
- Enter the name of the mediation policy and description (optional):
Figure 7. Create mediation policy

- Click Policy.
- Click Add Property. The Optional Properties Policy Identifier is selected.
- Click Add and enter a unique identifier.
- Click Select Policy Domain. The policy domains are listed and the relevant mediation domain of Price is selected:
Figure 8. Selecting the policy domain

- Click Apply.
- Click Select Policy Type. The policy type relates to the property group that you defined in WebSphere Integration Developer.
- Click Select.
- Click Add Assertion.
- Select a mediation policy assertion for a property that you want to override. Each assertion relates to a dynamic property in a particular property group, so you can select an assertion for any dynamic property
in a particular property group. Choose the Assertion amount, as shown in Figure 9:
Figure 9. Policy Assertion field

- Click Add and enter a value for the assertion.
- Click Publish.
The mediation policies for GroupA, GroupB, GroupC, and GroupD are defined in the Service Registry, as shown in Figure 10:
Figure 10. Pricing policies for different customer groups

Attaching a mediation policy to an SCA module
When an SCA integration module is loaded into Service Registry, any default mediation policies are loaded along with the SCA module. The default mediation policies are not attached to the SCA module, so use the following steps to attach the policy:
- In the navigation pane of the Service Registry Web UI, click Service Documents => SCA Integration Modules => SCA Module Documents. The SCA Module Documents page opens.
- Select CreditModule in the SCA module document. The details of the SCA module document are displayed.
- Click Relationships => Modules => CreditModule. The module details are displayed.
- Click Policy. The mediation policy details are displayed.
- Click Edit Policy Attachments.
- Click Attach Policy. The Add Policy Attachment information is displayed.
- Click Search.
- Select a mediation policy that you want to attach to your SCA module, such as urn:GroupA.
- Click Apply and then click Finish.
Repeat the steps above for the other policies urn:GroupB, urn:GroupC, and urn:GroupD. Four different policies are linked to the CreditModule, as shown in Figure 11:
Figure 11. Pricing policies attached to CreditModule

Creating a conditional mediation policy
Gate conditions built using values from the message are used to associate with the specific policy, out of the four pricing policies attached to the CreditModule in Service Registry. The assertion in the policy in turn will set the correct amount in the dynamicProperty context field. To create the gate condition for each policy:
- In the navigation pane of the Service Registry Web UI, click Service Documents => Policy Documents => Documents with Policy Attachments.
- To update, select one of the mediation policy attachment documents, such as CreditModule_Module_CreditModule_urn:GroupA.xml. The details of the attachment document are displayed.
- Under Relationships => Attachments, select the attachment CreditModule_Module_CreditModule_urn:GroupA.xml.
- Click Edit Properties.
- Click Add Property. You can now add a property name.
- Enter the custom property name as
medGate_Condition1, which is the gate condition name. Gate condition names must start withmedGate_followed by a user-defined string. - Click Add.
- Enter the gate condition value -- in this case
< 18. The variable name age is the policy condition name in the Policy Resolution primitive, as shown in Figure 2 above. - Similarly, add the name
medGate_Condition2and value ofchannel = web. - Click Apply.
The policy is updated by adding two properties that hold the condition to select this policy. Repeat the steps above for the other policies and add the relevant medGate_Conditions.
For CreditModule_Module_CreditModule_urn:GroupB.xml time, add a property medGate_Condition1
holding the values age <= 18 and channel = web.
Using the Xpath in Figure 2, the policy resolution primitive retrieves the value of age and channel from the request message and calls Service Registry. Based on the gate conditions, the specific pricing policy is chosen.
This article showed that mediation policies control the message content and mediation flow. WebSphere Service Registry and Repository supports loading, changing, and retrieving policy documents, which can then be used by a runtime component such as an ESB to retrieve policies for a particular service or operation based on the gate conditions built using values from the message.
The author would like to thank Muhammed Yaseen of IBM India for reviewing this article.
| Description | Name | Size | Download method |
|---|---|---|---|
| Code sample | creditMod.zip | 62 KB | HTTP |
Information about download methods
- Establish a policy-driven SOA using WebSphere Service Registry and Repository and WebSphere ESB
This article shows how you can utilize standard WS-Policy documents stored in a registry to impact runtime behavior in an ESB -- and then change that behavior on the fly with no code changes or redeployment. - WebSphere ESB developer resources page
Technical resources to help you use WebSphere ESB as a flexible connectivity infrastructure for integrating applications and services to support an SOA. - WebSphere ESB product page
Product descriptions, product news, training information, support information, and more. - WebSphere ESB information center
A single Web portal to all WebSphere ESB documentation, with conceptual, task, and reference information on installing, configuring, and using WebSphere ESB. - WebSphere ESB documentation library
WebSphere ESB product manuals. - WebSphere ESB FAQs
Basic questions and answers about the new WebSphere ESB product and its relationship to other WebSphere products. - WebSphere ESB support
A searchable database of support problems and their solutions, plus downloads, fixes, problem tracking, and more. - Redbook: Patterns: SOA Design Using WebSphere Message Broker and WebSphere ESB
Patterns for e-business are a group of proven, reusable assets that can be used to increase the speed of developing and deploying e-business applications. This Redbook shows you how to use WebSphere ESB together with WebSphere Message Broker to implement an ESB within an SOA. Includes scenario to demonstrate design, development, and deployment. - WebSphere Service Registry and Repository product page
Product descriptions, product news, training information, support information, and more. - WebSphere Service Registry and Repository information center
A single Web portal to all WebSphere Service Registry and Repository documentation, with conceptual, task, and reference information to help you install, configure, and use the product. - WebSphere Service Registry and Repository documentation library
WebSphere Service Registry and Repository announcement letters, demos, documentation, Redbooks, tutorials, Webcasts, and white papers. - WebSphere Service Registry and Repository requirements
Hardware and software requirements for WebSphere Process Server. - WebSphere Service Registry and Repository support
A searchable database of support problems and their solutions, plus downloads, fixes, problem tracking, and more. - WebSphere SOA solutions developer resources page
Get technical resources for WebSphere SOA solutions. - developerWorks SOA and Web services zone
Technical resources for evaluating, planning, designing, and implementing solutions that involve SOA and Web services. - developerWorks WebSphere application connectivity zone
Access to WebSphere application connectivity (formerly WebSphere business integration) how-to articles, downloads, tutorials, education, product info, and more. - developerWorks WebSphere business process management zone
Access to WebSphere BPM how-to articles, downloads, tutorials, education, product info, and other resources to help you model, assemble, deploy, and manage business processes. - WebSphere business process management products page
For both business and technical users, a handy overview of all business process management products. - WebSphere forums
Product-specific forums where you can get answers to your technical questions and share your expertise with other WebSphere users. - Most popular WebSphere trial downloads
No-charge trial downloads for key WebSphere products. - Trial downloads for IBM software products
No-charge trial downloads for selected IBM® DB2®, Lotus®, Rational®, Tivoli®, and WebSphere® products. - Technical books from IBM Press
Convenient online ordering through Barnes & Noble. - developerWorks technical events and Webcasts
Free technical sessions by IBM experts that can accelerate your learning curve and help you succeed in your most difficult software projects. Sessions range from one-hour Webcasts to half-day and full-day live sessions in cities worldwide.
Sobha R. Warrier is an SOA Architect on the WebSphere B2B team at the IBM India Software Lab in Bangalore. You can contact Sobha at sobharwa@in.ibm.com
Comments (Undergoing maintenance)





