Skip to main content

skip to main content

developerWorks  >  SOA and Web services | WebSphere  >

Proactive WebSphere Enterprise Service Bus (WESB) Mediation: Timing a Mediation Module

developerWorks
Go to the previous pagePage 3 of 12 Go to the next page

Document options
PDF format - Fits A4 and Letter

PDF - Fits A4 and Letter
1615 KB (37 pages)

Get Adobe® Reader®

Sample code


My developerWorks needs you!

Connect to your technical community


Rate this tutorial

Help us improve this content


Part 2 : Creating and connecting the "TimerMediationModule" and the "SampleWebServicemodule" (Service Provider)

First, open a new workspace in WebSphere Integration Developer (WID). Create a new library called "TimerMediationLib" and a new mediation module called "TimerMediationModule" as shown in Figure 4:



Figure 4. TimerMediationModule
TimeMediationModule

Create a new service data object (SDO) within the "TimerMediationLib" called "TimerMediationSDO", with a string field called "currentTimeStamp", as shown in Figure 5:



Figure 5. TimerMediationSDO
TimerMediationSDO

Create a new interface within the "TimerMediationLib", called "TimerMediationInterface", with a one-way operation called "invokeTimerMediation", with the input parameter as "timerMediationSDO" of TimerMediationSDO type, as shown in Figure 6.



Figure 6. TimerMediationInterface
TimerMediationInterface

Note: Normally, the service providers in a scenario like this accept a timestamp with which they determine the updates that need to be provided for the invoking mediation module.

Given a particular run of the invocation, the timestamp of the previous run is considered. As an example, if T1 and T2 are the timestamps, within an interval of "d" hours, the timer mediation module would pass T1 to the Web service at the time T2, so that the service provider responds back with all the updates that happened after the timestamp T1. To achieve this, the older timestamp (T1) needs to be persisted, so it can be used during instance T2, for the query.

To make this scenario simple, we will skip this persistence logic and simply use the current timestamp, to query the service provider. We will pick the current timestamp from the trigger message.

Now, create a new library called "SampleWebServiceLib" and a new mediation module called "SampleWebServiceModule" (this would simulate our Web service of the service provider), as shown in Figure 7.



Figure 7. SampleWebServiceModule
SampleWebServiceModule

Create a new interface within the SampleWebServiceLib called "SampleWebServiceInterface" with a two-way operation called "getUpdates" with the input parameter as "timestamp" (string type) and the output parameter as "updates" (string type), as shown in Figure 8.



Figure 8. SampleWebServiceInterface
SampleWebServiceInterface

Add the SampleWebServiceLib as a dependency to the SampleWebServiceModule. Open the assembly diagram for the SampleWebServiceModule and create a new Java component called "SampleWebService" implementing the interface "SampleWebServiceInterface". Also create a Web services export for the Java component. The assembly diagram should look like what we see in Figure 9.



Figure 9. SampleWebServiceModule Assembly Diagram
SampleWebServiceModule Assembly Diagram

Implement the operation "getUpdates" using the following code snippet:


Listing 1. getUpdates()
        public String getUpdates(String timestamp) {
		 System.out.println("++ Received request for 
		   updates with timestamp :"+timestamp);
		 return "UPDATES";
	    }
		


Now, create a new mediation flow called "TimerMediation" in the "TimerMediationModule" attached to the interface ‘TimerMediationInterface". Add the "SampleWebServiceLib" as a dependency to the "TimerMediationModule" and create a Web services import for the "SampleWebServiceInterface", wiring it to the "TimerMediationModule". The assembly diagram for the "TimerMediationModule" should now look like this:



Figure 10. TimerMediationModule Assembly Diagram
TimerMediationModule Assembly Diagram

We can now implement the TimerMediation request flow. In the Mediation flow editor, wire the two operations "invokeTimerMediation" and "getUpdates" and implement the connection using a "Business Object Map" primitive "BOMapper1" as shown below.



Figure 11. TimerMediation Mediation Flow
TimerMediation Mediation Flow

Implement the BOMapper1, by mapping the "currentTimeStamp" attribute of timerMediationSDO to "timestamp" attribute of the getUpdates, as shown in Figure 12.



Figure 12. BOMap
BOMap

Implement the response flow for the invokeTimerMediation with a simple custom mediation primitive like the following.



Figure 13. Customer Mediation
Customer Mediation

Add the following code snippet in the custom mediation primitive, to indicate the end of the mediation flow, once the response is received from the sample Web service.


Listing 2. Custom Mediation snippet
        //out.fire(smo);
        System.out.println("++ End of Flow");
		


Note: In a real situation, this response flow would be implemented to post the updates as a topic, so as to notify the subscribers for these updates.

Run a quick test on the TimerMediation component of the TimerMediationModule. You should see the output of the test controller as in the following figure and the print statements on the console.



Figure 14. Test Controller - TimerMediationModule
Test Controller - TimerMediationModule

We now move on to the next section, where we create the SampleStartupBeanEJB module, which hosts our startup bean.



Back to top



Go to the previous pagePage 3 of 12 Go to the next page