You are on page 1of 20

1

Oracle Mediator Routing Rule Use Cases


The following two tutorials give you step-by-step instructions for creating two of the Mediator sample projects provided on the Oracle SOA Suite samples page. They illustrate how to define routing rules for the Mediator components you create. This document includes the following scenarios:
I

Creating a Mediator for Routing Messages Creating an Asynchronous Request and Response Using Mediator

1.1 Creating a Mediator for Routing Messages


The CustomerRouter use case provides an overview of how to use a Mediator in a SOA composite sample application to route messages. The files are provided in the Basic Routing Sample for Mediator. The CustomerRouter use case consists of the following steps:
1. 2. 3.

Legacy customer files are retrieved from a directory by an adapter service named ReadCust. The ReadCust adapter service sends the file data to the CustomerRouter Mediator. The CustomerRouter Mediator applies a filter to the XML message payload to determine whether the message should be routed to the USCustomer reference or CanadaCustomer reference. The CustomerRouter Mediator then transforms the message to the structure required by the adapter reference. The external reference delivers the message to its associated external application.

4. 5.

Figure 11 provides an overview of the CustomerRouter use case.

Creating a Mediator for Routing Messages

Figure 11 Overview of CustomerRouter Use Case

1.1.1 How to Create the CustomerRouter Use Case


This section provides the design-time tasks for creating, building, and deploying the use case. Task 1 Create an Oracle JDeveloper Application and a Project 1. In Oracle JDeveloper, click File and select New. The New Gallery dialog appears.
2. 3.

In the New Gallery, expand the General node, and select the Applications category. In the Items list, select SOA Application and click OK. The Create SOA Application wizard appears.

4.

In the Application Name field, enter CustomerRouter and then click Next. The Name your project page appears.

5.

In the Project Name field, enter CustomerRouterProject and click Next. The Configure SOA settings page appears.

6.

From the Composite Template list, select Empty Composite and then click Finish. The Application Navigator of Oracle JDeveloper is populated with the new application and the project, and the SOA Composite Editor contains a blank palette.

7.

From the File menu, select Save All.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

Task 2 Create the CustomerRouter Mediator Service Component 1. From the Component Palette, select SOA.
2.

Drag and drop a Mediator icon in the Components section. The Create Mediator dialog is displayed.

3. 4. 5.

In the Name field, enter CustomerRouter. From the Templates list, select Define Interface Later. Click OK. A Mediator with name CustomerRouter is created.

Task 3 Create a File Adapter Service You must create a file adapter service named ReadCust to read the XML files from a directory.
Note: Mediator may process the same file twice when run against

Oracle Real Application Clusters (Oracle RAC) planned outages. This is because a file adapter is a non-XA compliant adapter. Therefore, when it participates in a global transaction, it may not follow the XA interface specification of processing each file only once.
1. 2.

From the Component Palette, select SOA. Select File Adapter and drag it to the Exposed Services swimlane. The Adapter Configuration wizard Welcome page is displayed.

3.

Click Next. The Service Name page is displayed.

4. 5.

In the Service Name field, enter ReadCust. Click Next. The Adapter Interface page is displayed.

6.

Select Define from operation and schema (specified later) and click Next. The Operation page is displayed.

7. 8. 9.

In the Operation Type field, select Read File. In the Operation Name field, replace Read with ReadFile. Click Next. The File Directories page is displayed.

10. In the Directory for Incoming Files (physical path) field, enter the directory from

which you want to read the files. For example, enter C:\Customer\In.
11. Click Next.

The File Filtering page is displayed.


12. In the Include Files with Name Pattern field, enter *.xml, and then click Next.

The File Polling page is displayed.


13. Change the Polling Frequency field value to 10 seconds, and then click Next.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

The Messages page is displayed.


14. To the right of the URL field, click Search.

The Type Chooser dialog is displayed.


15. Click Import Schema File.

The Import Schema File dialog is displayed.


16. To the right of the URL field, click Search and select the LegacyCustomer.xsd file

present in the Samples folder.


17. Click OK. 18. Expand the navigation tree to Type Explorer\Imported

Schemas\LegacyCustomer.xsd and select CustomerData, as shown in Figure 12.


Figure 12 Type Chooser - CustomerData

19. Click OK.

The Adapter Configuration wizard appears, as shown in Figure 13.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

Figure 13 Adapter Configuration Wizard Messages page

20. Click Next.

The Finish page is displayed.


21. Click Finish. 22. From the File menu, select Save All.

Task 4 Create a File Adapter Reference 1. From the Component Palette, select SOA.
2.

Select File Adapter and drag it to the External References swimlane. The Adapter Configuration wizard Welcome page is displayed.

3.

Click Next. The Service Name page is displayed.

4. 5.

In the Service Name field, enter USCustomer. Click Next. The Adapter Interface page is displayed.

6.

Select Define from operation and schema (specified later) and click Next. The Operation page is displayed.

7.

Click Next. The Operation page is displayed.

8. 9.

In the Operation Type field, select Write File. In the Operation Name field, enter WriteFile.

10. Click Next.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

The File Configuration page is displayed.


11. In the Directory for Outgoing Files (physical path) field, enter the name of the

directory in which you want to write the files. For example, C:\Customer\out.
12. In the File Naming Convention field, enter customer_%SEQ%.xml and click

Next. The Messages page is displayed.


13. To the right of the URL field, click Search.

The Type Chooser dialog is displayed.


14. Click Import Schema File.

The Import Schema File dialog is displayed.


15. To the right of the URL field, click Search and select the USCustomer.xsd file

present in the Samples folder.


16. Click OK. 17. Expand the navigation tree to Type Explorer\Imported

Schemas\USCustomer.xsd, and then select Customer.


18. Click OK. 19. Click Next.

The Finish page is displayed.


20. Click Finish. 21. From the File menu, click Save All. 22. Create another file adapter reference named CanadaCustomer in a similar way

by using the CanCustomer.xsd file. Figure 14 shows how the SOA Composite Editor appears after performing this task.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

Figure 14 Mediator Service Component with Adapter Services and References

Task 5 Specify Routing Rules You must specify the path that messages take from the ReadCust adapter service to external references.
1.

Connect the ReadCust service to the CustomerRouter Mediator, as shown in Figure 15. This specifies the file adapter service to invoke the CustomerRouter Mediator while reading a file from the input directory.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

Figure 15 Connecting the ReadCust Service to the CustomerRouter Mediator

2. 3.

Double-click the CustomerRouter Mediator in the Mediator Editor. In the Routing Rules section, click Add to the extreme right side of ReadFile, and then click static routing rule. The Target Type dialog is displayed.

4.

Click Service. The Target Services dialog is displayed.

5.

Navigate to CustomerRouterProject > References > USCustomer and select WriteFile, as shown in Figure 16.

Figure 16 Target Services Dialog

6.

Click OK. The Routing Rules section is displayed.

7.

Next to the <<Filter Expression>> field, click the filter icon to create a filter expression for this routing rule. The Expression Builder dialog is displayed.

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

8. 9.

In the Variables field, navigate to Variables> in > body > imp1:CustomerData, and then select Country. Double-click Country. The Country node is added in the Expression field, as shown in Figure 17.

Figure 17 Expression Builder Dialog

10. Modify the expression as follows: $in.CustomerData/imp1:CustomerData/Country=US 11. Click OK.

The <<Filter Expression>> field of the Routing Rules section is populated with the expression.
12. To the right of the Transform Using field, click the icon.

The Request Transformation Map dialog is displayed, as shown in Figure 18.


Figure 18 Request Transformation Map

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

13. Select Create New Mapper File and click OK.

A CustomerData_To_Customer.xsl file is added, as shown in Figure 19.


Figure 19 CustomerData_To_Customer.xsl File Initially

14. Drag and drop the imp1:CustomerData source element to the imp1:Customer

target element. The Auto Map Preferences dialog is displayed.


15. From the During Auto Map options, deselect Match Elements Considering their

Ancestor Names. The Auto Map Preferences dialog is shown in Figure 110.
Figure 110 Auto Map Preferences Dialog

Oracle Mediator Routing Rule Use Cases

Creating a Mediator for Routing Messages

16. Click OK.

The CustomerData_To_Customer.xsl file appears, as shown in Figure 111.


Figure 111 CustomerData_To_Customer.xsl Tab Auto Mapped Connections

17. From the File menu, select Save All. 18. Repeat the procedures mentioned in Step 3 through Step 17 to create a

CanadaCustomer reference as the target service. In the Expression Builder dialog, specify the following expression:
Note: For repeating the steps, you must re-enter the Mediator Editor

by closing it or by clicking the CustomerRouter.mplan tab above the editor.


$in.CustomerData/imp1:CustomerData/Country=CA

After performing all the steps described in this section, the SOA Composite Editor appears, as shown in Figure 11. Task 6 Create an Application Server Connection An application server connection is required for deploying your SOA composite application. Task 7 Deploy the CustomerRouterProject Deploying the CustomerRouterProject composite application to an application server consists of following steps:
I

Creating an application deployment profile Deploying the application deployment profile to an application server

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

Task 8 Run and Monitor the CustomerRouterProject Application After deploying the CustomerRouterProject application, you can run it by copying the input XML files to the input folder. The payload files are written to the specified output directories. For monitoring the running instance, you can use Oracle Enterprise Manager Fusion Middleware Control at the following URL:
http://hostname:port_number/em

where hostname is the host on which you installed the Oracle SOA Suite infrastructure and port_number is the port of the server on which Oracle Enterprise Manager Fusion Middleware Control is installed.

1.2 Creating an Asynchronous Request and Response Using Mediator


This sample demonstrates an asynchronous request response scenario using Mediator. This composite has a client BPEL process invoking a Mediator, which invokes a server BPEL process. All the invocations are done as an asynchronous request response. Figure 112 provides an overview of the AsyncMediator use case.
Figure 112 Overview of AsyncMediator Use Case

1.2.1 How to Create the AsyncMediator Use Case


This section provides the design-time tasks for creating, building, and deploying the use case. These tasks should be performed in the order in which they are presented. Task 1 Create an Oracle JDeveloper Application and Project 1. In Oracle JDeveloper, click File and select New. The New Gallery dialog appears.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

2. 3.

In the New Gallery, expand the General node, and select the Applications category. In the Items list, select SOA Application and click OK. The Create SOA Application wizard appears.

4.

In the Application Name field, enter AsyncMediator and then click Next. The Name your project page appears.

5.

In the Project Name field, enter AsyncMediatorSample and click Next. The Configure SOA settings page appears.

6.

In the Composite Template list, select Empty Composite and then click Finish. The Application Navigator of Oracle JDeveloper is populated with the new application and the project, and the SOA Composite Editor contains a blank palette.

7.

From the File menu, click Save All.

1. 2. 3.

Task 2 Create a Server BPEL Process In the Application Navigator, double-click composite.xml. The SOA Composite Editor is displayed. From the Component Palette, select SOA. Drag and drop a BPEL Process into the Components section. The Create BPEL Process dialog is displayed.

4. 5. 6.

In the Name field, enter ServerBPELProcess. From the Template list, select Asynchronous BPEL Process. Deselect Expose as a SOAP service and click OK. The ServerBPELProcess is created in the SOA Composite Editor.

Task 3 Create a Mediator Service Component 1. From the Component Palette, select SOA.
2.

Drag and drop a Mediator into the Components section. The Create Mediator dialog is displayed.

3. 4. 5. 6.

In the Name field, enter Mediator. From the Template list, select Asynchronous Interface. Deselect Create Composite Service with SOAP Bindings. Click OK. A Mediator with name Mediator is created, as shown in Figure 113.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

Figure 113

Mediator and ServerBPELProcess in the Composite Window

7.

Double-click the Mediator Mediator. The Mediator Editor is displayed.

8.

In the Routing Rules section, click Add to the far right side of execute and then select static routing rule. The Target Type dialog is displayed.

9.

Select Service. The Target Services dialog is displayed.

10. Navigate to AsyncMediatorSample > BPEL Processes > ServerBPELProcess >

Services > serverbpelprocess_client > process, as shown in Figure 114.


Figure 114 Target Services Dialog

11. Click OK.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

12. Below the <<Filter Expression>> field, click the icon to the right of the Transform

Using field. The Request Transformation Map dialog is displayed.


13. Select Create New Mapper File and click OK.

The XSLT Mapper is displayed and a target file named singleString_To_ process.xsl is added.
14. Drag and drop the cb1:input source element to the client:input target element.

The Auto Map Preferences dialog is displayed.


15. From the During Auto Map options, deselect Match Elements Considering their

Ancestor Names and click OK. The XSLT Mapper displays, as shown in Figure 115.
Figure 115 singleString_To_process.xsl Window

16. In the Routing Rules section, under Callback, click the icon to the right of the

Transform Using field. The Request Transformation Map dialog is displayed.


17. Select Create New Mapper File and click OK.

The XSLT Mapper is displayed and a target file named processResponse_To_ singleString.xsl is added.
18. Drag and drop the client:processResponse source element to the cb1:singleString

target element. The Auto Map Preferences dialog is displayed.


19. From the During Auto Map options, deselect Match Elements Considering their

Ancestor Names and click OK. Task 4 Create a Client BPEL Process 1. In the Application Navigator, double-click composite.xml. The SOA Composite Editor is displayed.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

2. 3.

From the Component Palette, select SOA. Drag and drop a BPEL Process to the Components section. The Create BPEL Process dialog is displayed.

4. 5. 6.

In the Name field, enter ClientBPELProcess. From the Template list, select Asynchronous BPEL Process. Click OK. ClientBPELProcess is created in the SOA Composite Editor.

7.

Drag and drop the ClientBPELProcess BPEL process to the Mediator Mediator. The SOA Composite Editor appears, as shown in Figure 112.

Task 5 Create the Invoke Activity 1. Double-click ClientBPELProcess. The Oracle BPEL Designer is displayed.
2. 3. 4. 5. 6. 7. 8. 9.

Drag and drop an Invoke activity from the Component Palette to the design area. Double-click the Invoke activity. The Invoke dialog is displayed. In the Name field, enter InvokeMediator. Next to the Partner Link field, click Browse Partner Links. The Partner Link Chooser dialog is displayed. Select Operation - execute, and click OK. To the right of the Variable field in the Invoke dialog, click the Auto-Create Variable icon. The Create Variable dialog is displayed. In the Variable field, enter InvokeMediator_execute_InputVariable_1 and click OK. The Invoke dialog is displayed. Click OK. The Oracle BPEL Designer appears.

Task 6 Create the Receive Activity 1. Drag and drop a Receive activity from the Component Palette to the design area.
2. 3. 4. 5. 6. 7. 8.

Double-click the Receive activity. The Receive dialog is displayed. In the Name field, enter ReceiveFromMediator. Next to the Partner Link field, click Browse Partner Links. The Partner Link Chooser dialog is displayed. Select Operation - callback, and click OK. To the right of the Variable field in the Receive dialog, click the Auto-Create Variable icon. The Create Variable dialog is displayed. Select the default variable name and click OK. The Variable field is populated with the default variable name. Check Create Instance, and click OK. The Oracle BPEL Designer appears.

Task 7 Create the Assign Activity 1. Drag and drop an Assign activity from the Component Palette between the ReceiveFromMediator and InvokeMediator activities in the design area.
2. 3.

Double-click the Assign activity. The Assign dialog is displayed. In the Name field, enter AssignRequest.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

4. 5. 6.

Click the Copy Operation tab. The Assign dialog is displayed. Select Copy Operation. The Create Copy Operation dialog is displayed. Create the copy operation between the triggers file name and the file variable, as shown in Figure 116.
The Create Copy Operation Dialog

Figure 116

7. 8.

Click OK in the Create Copy Operation dialog. Click OK to return to the Oracle BPEL Designer, as shown in Figure 117.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

Figure 117

The Oracle JDeveloper - ClientBPELProcess.bpel

9.

From the File menu, select Save All.

Task 8 Create the Assign Activity in the ServerBPELProcess 1. Double-click the ServerBPELProcess BPEL process. The Oracle BPEL Designer is displayed.
2. 3. 4. 5. 6.

Drag and drop an Assign activity from the Component Palette between the receiveInput and callbackClient activities in the design area. Double-click the Assign activity. The Assign dialog is displayed. Click the Copy Operation tab. Select Copy Operation. The Create Copy Operation dialog is displayed. Create the copy operation between the triggers file name and the file variable, as shown in Figure 118.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

Figure 118

The Create Copy Operation Dialog

7. 8.

Click OK in the Create Copy Operation dialog. Click OK to return to the Oracle BPEL Designer, as shown in Figure 119.
The Oracle JDeveloper - ServerBPELProcess.bpel

Figure 119

9.

From the File menu, select Save All.

Oracle Mediator Routing Rule Use Cases

Creating an Asynchronous Request and Response Using Mediator

Task 9 Configure an Application Server Connection An application server connection is required for deploying your SOA composite application. Task 10 Deploy the SOA Composite Application Deploying the EventMediatorApp composite application to Oracle WebLogic Server consists of following steps:
I

Creating an application deployment profile Deploying the application to an application server

Oracle Mediator Routing Rule Use Cases

You might also like