Wednesday, July 16, 2008

Mediation flow

Mediation Flow How to

Websphere Integration Developer v612

Contact us...

Table of Contents

How to design effective mediation flows

How to Implement error handling within a mediation

How to setup the Filter mediation primitive

How to set up Correlation Context

Related links

Database Lookup mediation primitive

Mediation primitives

Browse Correlation context

In the Mediation Flow Editor (mediation flow section), do the following:

  1. Click Input (start of request flow)
  2. Select Properties tab
  3. Select Details.

In the Correlation context field, click Browse.

Select Data Type

  1. In the Matching data types, select the required data type (i.e SubscriptionInformation).
  2. Click OK

Correlation context set

The correration context (i.e SubscriptionInformation) is set.

.

How to develop mediation flows using mediation primitives and Service Message Objects

Related links

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Properties of nodes and mediation primitives

Creating a mediation flow

Adding mediation primitives to the flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Introduction We will use the Stock Quote sample (available in IBM Websphere Integration Developer 6.1.2 runtime) to demonstrate how to develop mediation flows using mediation primitives and Service Message Objects.

Overview

We will assume that the Stock Quote sample is at the current stage as shown in the opposite diagram except that the mediation flow component (i.e StockQuote_MediationFlow) is not yet implemented.

We will implement a mediation flow component (i.e StockQuote_MediationFlow) by following the steps below:

  1. Generate a mediation flow component implementation
  2. Connect Source operations to Target operations
  3. Develop the Request Mediation flow
  4. Develop the Response Mediation flow

How to generate a Mediation Flow component implementation

Related links

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Creating a mediation flow

Adding mediation primitives to the flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Overview

Generating a mediation flow component is the first step in developing a mediation flow (i.e StockQuote_MediationFlow).

Generate Implementation

In the Assembly Diagram, right-click on the mediation flow component (i.e StockQuote_MediationFlow) that you want to implement and select Generate Implementation.

Select Folder

Select the folder (i.e StockQuote) where the Mediation Flow implementation will be generated.

Click OK. The Mediation Flow Editor opens (see below).

Mediation flow Editor

The Mediation Flow Editor opens up.
These are the 3 sections of the Mediation Flow editor:

  1. Operation connections
  2. Mediation flow
  3. Properties view

In the Operation connections section, the following are setup:

  1. Source interface
    One or more source interfaces (i.e StockQuoteService) that allow service requesters to access the mediation flow. These interfaces must match those of the exports that will be wired to the mediation flow component in the mediation module. Source interfaces are always created on the left side of the editor. A mediation flow must have a source interface.

  2. Target references
    Zero or more target references (i.e DelayedServicePortTypePartner, RealTimeServicePortTypePartner) that allow a mediation flow component to access a service provider through an import in the mediation module. The reference specifies the interface that is used by the import to invoke the service. Target references are always created on the right side of the editor. Service references of custom mediation primitives are shown as unconnected target references.

In the Mediation flow section, the following are setup:

  1. Input node
    The first element on the left in the request flow view, derived from the source operation. This is the starting point for the request flow, and sends the message into the request flow. A flow can have only one input node.
  2. Input response node
    If a source operation is not wired to a target, the request flow typically ends with this node, which returns the processed message as a response to the source operation.
Next Step Connect source operations to target operations

How to Connect Source Operation to Target Operations

Related links

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Creating a mediation flow

Adding mediation primitives to the flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Overview

draft....

When you connect source and target operations, a request flow and a response flow are created for each source operation that is connected. Select the source operation to view the request flow. The flow is represented from left to right. You will see an input node on the left. This is where the request message enters the flow. On the right are two callout nodes, one for each target operation. You will also see an ImmediateResponse node. This node is used when a message is to be returned to the client after the flow is executed. We will not use this node in our sample. You will add mediation primitives between the input and callout nodes and wire the flow. The completed request flow is shown below:

Unconnected Source and Target operations

The second step in developing a mediation flow implementation is to connect the source operation/s (i.e StockQuoteServicegetQuote) to the target operation/s (DelayedServicePortTypePartnergetQuote).

Connect Source Operation to Target operation

Select a source operation (i.e StockQuoteServicegetQuote) and connect it to a target operation (i.e DelayedServicePortTypePartnergetQuote).

  1. Hover the mouse over the StockQuoteService operation (getQuote) to display the connection handle.
  2. Grab the connection handle and drag it.
  3. Drop the connection handle into the target operation.
  4. Repeat the same procedure to make other connections.

1 - Hover the mouse over a source operation to display the connection handle
2 - Grab the connection handle and drag it

3 - Drop the connection handle into a target operation

Connected Source and Target operation (Request)

After connecting the source operation to the target operation, notice that a Callout node (getQuote: DelayedService) is created.

Callout node An end point in the request flow, derived from the target operations. It sends the processed message to the target operation. There is one callout node for each target operation.

Connected Source and Target operation (Response)

Input Response

The input response node is an end point in the request and response flows. It returns the processed message as a response to the source operation.

Callout Node

A callout response node is a starting point for the response flow. It forwards the message received from the target operation into the response flow.

How to develop the request mediation flow

Related links

Adding mediation primitives to the flow

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Creating a mediation flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Introduction We will use the Stock Quote sample (available in Websphere Integration Developer 6.1.2 runtime) to demonstrate how to develop mediation flows using meadiation primitives and Service Message Objects.

Overview

The request flow is executed from left to right, in the following order:

  1. The property subscriptionLevel is set in the correlation context of the message so that it will be available later in the response flow.
  2. The request is logged using the Message Logger mediation primitive named Log.
  3. A Database Lookup mediation primitive named Lookup uses the customerID element in the message body to determine whether the customer is entitled to the premium or standard service by looking this information up in the supplied CustomerDatabase. This information is added to the subscriptionLevel property in the correlation context of the message, for use later.
  4. The request is routed by a Message Filter called Filter, based on the subscriptionLevel information in the correlation context, to either the real-time or delayed stock quote service. The Filter's pattern property is promoted so that it can be changed at runtime to redirect the stock quote request to the delayed service if the premium service is unavailable.
  5. The message is transformed on the way to either service by XSLT primitives TransformToDelayed and TransformToRealtime so that it matches what the service expects.
  6. The response from each service is passed through an XSLT mediation primitive (DelayedToStockQuoteService & RealtimeToStockQuoteService) to match the format that is required by StockQuoteService.

Before

After

The Mediation Primitives

Transformation
  • The Custom Mediation primitive allows you to implement your own mediation logic using Java™ code.
  • The Database Lookup primitive enriches the message using data retrieved from a database.
  • The Message Element Setter primitive sets, copies, or deletes the content of message headers or bodies.
  • The Business Object Map primitive allows you to map between business objects with different internal structures.
  • The Set Message Type primitive 'overlays' message fields in the SMO with type information that is different from the type originally described in the business object definition.
  • The XSL Transformation primitive transforms message formats between source and target operations, or changes the content of a message. The primitive uses an XSL style sheet to map between the source and target message types.
Routing
  • The Message Filter primitive conditionally routes messages based on the results of pattern evaluation. A pattern is evaluated against the message, and if the result is true, the message is propagated to a terminal associated with the pattern.
  • The Endpoint Lookup mediation primitive queries the WebSphere® Service Registry and Repository and retrieves service endpoints, which it places in the message context. The retrieved endpoints can then be used to dynamically invoke a service
  • The Fan Out primitive can repeat all or part of a message based on properties set.
  • The Fan In primitive receives and aggregates messages until the condition for the firing of the output terminal is met. It can only be used in combination with a Fan out primitive.
  • The Service Invoke primitive allows you to call an operation on a partner reference inline within the flow. If the service returns a fault, you can retry the same service or call another service.
Tracing
  • The Message Logger primitive logs messages to a database.
  • The Event Emitter primitive emits a common base event at a point significant in the mediation flow.
Error Handling
  • The Stop mediation primitive silently stops the current path in the flow. This is an expected termination , and is not caused by a failure in the primitive.
  • The Fail mediation primitive stops the flow and throws an exception when there is a known run failure in the primitive. You can define your own exceptions for the Fail primitive.

Add mediation primitives

  1. Add the mediation flow primitives shown on the right. Rename each one as specified (Name column).
  2. Connect the mediation primitives as specified (Connect To column).
  3. Configure the mediation primitives as required.

Sequence Primitive/Folder Name Connect To (Name)
1 Message Logger/Tracing Log Lookup
2 Database Lookup/Transformation Lookup Filter
3 Message Filter/Routing Filter

TransformToDelayed

TransformToRealTime

4 XSL Transformation/Transformation TransformToDelayed Invoke - getQuote
4 XSL Transformation/Transformation TransformToRealtime Invoke - getQuote

Medition flow primitives Added

The following mediation flow primitives were added:

  1. Log
  2. Lookup
  3. Filter
  4. TransformToDelayed
  5. TransformToRealtime

Note:

There are errors!!

Medition flow primitives connected

The following mediation flow primitives were connected:

  1. Log
  2. Lookup
  3. Filter
  4. TransformToDelayed
  5. TransformToRealtime

Note:

There are still errors!!

Next steps

How to develop the response mediation flow

Related links

Adding mediation primitives to the flow

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Creating a mediation flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Introduction We will use the Stock Quote sample (available in Websphere Integration Developer 6.1.2 runtime) to demonstrate how to develop mediation flows using meadiation primitives and Service Message Objects.

Overview

The diagram on the right shows the response flow that defines the mediation logic applied to the returning message as it flows through the StockQuote_MediationFlow component from the target service provider to the client.

  1. A Message Element Setter is used to copy the value of subscriptionLevel from the correlation context to the property qualityOfService in the message.
  2. The qualityOfService text indicates "Premium" to a response that is returned from the real-time service, and "Standard" to a response that is returned from the delayed service.
  3. The qualityOfService text is displayed in the client to indicate the service provider that was used.

Before

After

The Mediation Primitives

Transformation
  • The Custom Mediation primitive allows you to implement your own mediation logic using Java™ code.
  • The Database Lookup primitive enriches the message using data retrieved from a database.
  • The Message Element Setter primitive sets, copies, or deletes the content of message headers or bodies.
  • The Business Object Map primitive allows you to map between business objects with different internal structures.
  • The Set Message Type primitive 'overlays' message fields in the SMO with type information that is different from the type originally described in the business object definition.
  • The XSL Transformation primitive transforms message formats between source and target operations, or changes the content of a message. The primitive uses an XSL style sheet to map between the source and target message types.
Routing
  • The Message Filter primitive conditionally routes messages based on the results of pattern evaluation. A pattern is evaluated against the message, and if the result is true, the message is propagated to a terminal associated with the pattern.
  • The Endpoint Lookup mediation primitive queries the WebSphere® Service Registry and Repository and retrieves service endpoints, which it places in the message context. The retrieved endpoints can then be used to dynamically invoke a service
  • The Fan Out primitive can repeat all or part of a message based on properties set.
  • The Fan In primitive receives and aggregates messages until the condition for the firing of the output terminal is met. It can only be used in combination with a Fan out primitive.
  • The Service Invoke primitive allows you to call an operation on a partner reference inline within the flow. If the service returns a fault, you can retry the same service or call another service.
Tracing
  • The Message Logger primitive logs messages to a database.
  • The Event Emitter primitive emits a common base event at a point significant in the mediation flow.
Error Handling
  • The Stop mediation primitive silently stops the current path in the flow. This is an expected termination , and is not caused by a failure in the primitive.
  • The Fail mediation primitive stops the flow and throws an exception when there is a known run failure in the primitive. You can define your own exceptions for the Fail primitive.

Add mediation primitives

  1. Add the mediation flow primitives shown on the right. Rename each one as specified (Name column).
  2. Connect the mediation primitives as specified (Connect To column).
  3. Configure the mediation primitives as required.

Sequence Primitive/Folder Name Connect To (Name)
1 XSL Transformation /Transformation DelayedToStockQuoteService SetQualityOfService
2 Fail/Error Handling DelayedStockQuoteFail None
3 XSL Transformation /Transformation RealtimeToStockQuoteService SetQualityOfService
4 Fail/Error Handling RealtimeStockQuoteFail None
5 Message Element Setter/Transformation SetQualityOfService Input - Response

Medition flow primitives Added

The following mediation flow primitives were added:

  1. DelayedToStockQuoteService

  2. DelayedStockQuoteFail
  3. RealtimeToStockQuoteService
  4. RealtimeStockQuoteFail
  5. SetQualityOfService

Note:

There are errors!!

Medition flow primitives connected

The following mediation flow primitives were connected:

  1. DelayedToStockQuoteService

  2. DelayedStockQuoteFail
  3. RealtimeToStockQuoteService
  4. RealtimeStockQuoteFail
  5. SetQualityOfService

Note:

There are still errors!!

Next steps

How to add a mediation primitive

Related links

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Creating a mediation flow

Adding mediation primitives to the flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Select a mediation flow primitive from the Palette

In the mediation flow editor (mediation flow section), do the following:

  1. Expand the Palette folders (Favorites, Routing, Transformation, Tracing, Error handling).
  2. Click on the mediation flow primitive that you want to add (i.e Message Logger).

Drop the mediation flow primitive

Move and click the mouse where you want to drop the mediation flow primitive.

Rename the mediation flow primitive

You can rename the mediation flow primitive as required (i.e Log).

How to connect mediation flow primitives

Related links

Mediation flows overview

Mediation flow

Mediation flows
Mediation primitives

Mediation Flow editor

Creating a mediation flow

Adding mediation primitives to the flow

Building mediation flows
Mediation services overview

Service message objects A

Service message objects B

Service message objects C

Making primitive connections

In the mediation flow editor (mediation flow section), do the following:

  1. Hover your mouse on the output or fail terminal of a primitive to display the connection handle
  2. Grab the connection handle and drag it to the input terminal of another primitive.
  3. Drop the connection
Step 1 Step 2 Step 3

Primitives connected

How to Setup a Database Lookup Mediation Primitive

Related links

Database Lookup mediation primitive

Mediation primitives

Setup Database Lookup properties

The Database Lookup primitive is not properly set up as shown by the errors below (right column).

In the Mediation Flow Editor (mediation flow section), setup the following properties to fix the errors:

  1. Click Lookup (DB Lookup mediation primitive)
  2. Select Properties tab
  3. Select Details.

In the Details section, enter the following property values:

Property Value
Data source name jdbc/sample/CustomerDatabase
Table name CUSTOMERTABLE
Key column name CUSTOMERID
Key path

/body/getQuote/request/customerID

(See below on how Key path is derived)

Errors

Derive Key path

Click on the Edit... button (right of the Key path entry field) to display the XPath Expression Builder.

In the XPath Expression Builder, do the following:

  1. Navigate to /body/getQuote/request/customerID and double click on customerID. The path appears in the XPath Expression section of the builder.
  2. Click Finish.

Add Data Elements

After setting the properties and key path, add data elements as required.

In the Data elements table, click Add... and continue below.

Add/Edit Properties

When you click the Add button above, the Add/Edit properties window shows up.

In the Add/Edit properties window, enter the following values:

Column Value
Value column name SUBSCRIPTIONLEVEL
Message value type String
Message element

/context/correlation/subscriptionLevel

(See below on how Message element is derived)

Derive Message Element

Click on the Edit... button (right of the Message element entry field) to display the XPath Expression Builder.

In the XPath Expression Builder, do the following:

  1. Navigate to

    /context/correlation/
    subscriptionLevel

    and double click on subscriptionLevel. The path appears in the XPath Expression section of the builder.
  2. Click Finish.

Database Lookup setup is complete

The database lookup setup is complete. Thus, the errors are gone.

How to implement a Java component in a Mediation Module

In the Assembly Diagram, right-click on the Java component that you want to implement and select Generate Implementation.

Select the package where the Java implementation will be generated.

You can select the default package or New Package.

Click OK.

If you selected New Package, enter Package name and click OK.

A new package is created (ccambil.java).

Select the package (ccambil.java) and click OK.

This is the generated Java source code.

Notice that you have to implement the public DataObject getTimeOfDay(DataObject input1) method.

package ccambil.java;

import commonj.sdo.DataObject;
import com.ibm.websphere.sca.ServiceManager;

public class CCambil_JavaComponent1Impl {
/**
* Default constructor.
*/
public CCambil_JavaComponent1Impl() {
super();
}

/**
* Return a reference to the component service instance for this implementation
* class. This method should be used when passing this service to a partner reference
* or if you want to invoke this component service asynchronously.
*
* @generated (com.ibm.wbit.java)
*/
private Object getMyService() {
return (Object) ServiceManager.INSTANCE.locateService("self");
}

/**
* Method generated to support implemention of operation "getTimeOfDay" defined for WSDL port type
* named "interface.CCambil_DateTime_I".
*
* The presence of commonj.sdo.DataObject as the return type and/or as a parameter
* type conveys that its a complex type. Please refer to the WSDL Definition for more information
* on the type of input, output and fault(s).
*/
public DataObject getTimeOfDay(DataObject input1) {
//TODO Needs to be implemented.
return null;
}

}

How to add a Custom Mediation Primitive

The completed etc.

  1. In the Business Integration view, expand the CustomMediation module.
  2. Open the Assembly Editor by double-clicking on the CustomMediation module assembly icon.
  3. The Assembly Diagram will be displayed.


In the module assembly diagram, right-click on the CustomMediationFlow component and choose Generate Implementation.

Click OK.

An initial mediation flow implementation is generated and the Mediation Flow Editor is automatically opened.

In the Operation Connections section, the source and the target operations are shown.

In the Mediation Flow section, the input and input response nodes are shown.

Input Node:

Request - getQuote : StockQuoteService

The input node is the starting point for the request flow. It sends the message from the source operation into the request flow.

Input Response Node:

Immediate Response

The input response node is an end point in the request and response flows. It returns the processed message as a response to the source operation.

In the Operation connections section, wire StockQuoteService interface's getQuote operation to StockQuoteServicePartner interface's getQuote operation.

After wiring the source to the target operation, a callout node appears.

Callout Node:

Invoke - getQuote : StockQuoteServicePartner

A callout node is an end point in the request flow. It sends the processed message to the target operation.

Add the PreferenceInformation business object to the correlation context of Request - getQuote : StockQuoteService. This will allow the property isPreferred to persist in the message flow.

  1. Click on Request - getQuote : StockQuoteService and switch to the Details tab in the Properties view.
  2. In the Correlation Context field, click Browse.

Select PreferenceInformation under matching data types, and double click.

{http://CustomMediation}

PreferenceInformation now appears in the Correlation Context field.

  1. Click on the Request tab.
  2. Select a Custom Mediation primitive from the palette.
  3. Drop it onto the request flow canvas, and rename it to Custom.

This mediation primitive allows the use of an existing SCA component operation within the mediation flow.

  1. Wire the output terminal of Request - getQuote : StockQuoteService to the input terminal of Custom.
  2. Wire the output terminal of Custom to the input terminal of Invoke - getQuote : StockQuoteServicePartner
  3. Click on the Define... button next to the Service operation field. The Define Custom Mediation wizard will be launched

In the Define Custom Mediation panel, leave the default selection to Create a new interface with implementation.

Click Next.

The Specify Message Types panel shows the input message type and output message type that will be used to create the new interface. Notice that the PreferenceInformation business object set in the correlation context is also shown in the Defined Contexts section.

  1. Change the Message Root field to /.
  2. Click Next

In the Create a new interface panel, change the Name field to NewCustomInterface.

Click Next.

In the Define Custom Mediation panel, leave the default selection to Generate a default Java implementation class and define it using the embedded visual snippet editor.

Click Finish.

Notice that a new reference NewCustomInterfacePartner has been created in the operation connections section

To add the Java code, do the following:

  1. Select Custom
  2. Select Properties/Implementation
  3. Paste the following code and save your changes:

// Get the symbol from the body of the message
String symbol = input1.getString("body/getQuote/symbol");

// If symbol is on the user's preferred list, set the isPreferred flag in the correlation context to 'true'
if (symbol.equals("ibm")) {

// Create the preferenceInformation business object and set the isPreferred flag to true
com.ibm.websphere.bo.BOFactory factory = (com.ibm.websphere.bo.BOFactory) new com.ibm.websphere.sca.ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
DataObject preferenceInformation = factory.create("
http://CustomMediation", "PreferenceInformation");
preferenceInformation.setBoolean("isPreferred", true);

// Set the business object in the correlation context
input1.setDataObject("context/correlation", preferenceInformation);

}
// Return the DataObject
return input1;

Synchronize interfaces and references and merge the java implementation in the assembly editor to create and wire the java component associated with the custom mediation.

  1. In the Assembly Editor, type Ctrl-S to save the changes. Right-click on the CustomMediationFlow component and select Synchronize Interfaces and References > from Implementation. Click OK in the dialog that asks whether you want to save all dirty editors and continue.

A Merge Implementation dialog is launched to show that the NewCustomInterfacePartner reference will be added using the interface NewCustomInterface. In addition, a corresponding Java™ component will be created.

Click OK.

Layout the contents by right-clicking inside the Assembly Diagram and selecting Layout Contents from the context menu.

Related links

1-Open the Assembly Diagram

Double-click the assembly diagram icon in the Business Integration view to open the Assembly Diagram.

Notice that a mediation flow component (Mediation1) is automatically created. You can rename this component as required.

Note:

You can only have one mediation flow component in a mediation module. In other words, a mediation module can only have one mediation flow component.

2-Add additional Components/Node

In addition to one Mediation Flow component, you can also add the following components (Nodes) in the Assembly Diagram (see Figure at right).

Right-click inside the Assembly Diagram and select Add Node > ???.

  1. Java
    Implement custom mediation primitives invoked by the mediation flow component
  2. Import
    Identify service providers and their interfaces
  3. Export
    Expose the mediation module to service requesters
  4. Stand-alone References
    Enables a Non-SCA component (i.e JSP) to invoke a mediation service

No comments: