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 7 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 6 : Configuring the JMS Export for the "TimerMediationModule"

We will now implement the final step of configuring the JMS export for the TimerMediationModule, so the trigger message can be picked up and the SampleWebServiceModule can be invoked periodically for updates.

Before we create the JMS export to pick up the messages, we need to create two simple classes, "SampleJMSFunctionSelector" and "SampleJMSTextDatabinding", just to illustrate writing custom function selector and the custom data binding classes for the JMS export. The data binding class would take care of converting the JMS Text message from the JMS message to the TimerMediationSDO and the function selector would invoke the "invokeTimerMediation" function on the TimerMediationInterface.

We use J2EE perspective to create a package called "timermediation.utils" as shown in the figure and create two classes called "SampleJMSFunctionSelector.java" and "SampleJMSTextDataBinding.java", with the code snippets below.



Figure 23. timermediation.utils package
timermediation.utils package

Code snippet for SampleJMSTextDataBinding.java


Listing 7. SampleJMSTextDataBinding
        
     package timermediation.utils;

import java.util.Date;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;

import com.ibm.websphere.bo.BOFactory;
import com.ibm.websphere.sca.ServiceManager;
import com.ibm.websphere.sca.jms.data.JMSDataBinding;
import commonj.connector.runtime.DataBindingException;
import commonj.sdo.DataObject;

public class SampleJMSTextDataBinding implements
		JMSDataBinding {

	private String payload = null;
	private String presentTimeStamp = "";
	

	private DataObject jmsData = null;
	
	

	public boolean isBusinessException() {
		// TODO Auto-generated method stub
		return false;
	}

	public void setBusinessException(boolean arg0) {
		// TODO Auto-generated method stub
		
	}

	public int getMessageType() {

		return JMSDataBinding.TEXT_MESSAGE;
	}

	public void read(Message message) throws JMSException {
		//Throws an exception if message is not an instance of
		// javax.jms.TextMessage
		if (!(message instanceof TextMessage)) {
			System.out.println("Unexpected Message Type met!");
			throw new JMSException("Wrong Message Type - "
					+ message.getClass().getName() + "Error");
		}

		TextMessage textMessage = (TextMessage) message;
		payload = textMessage.getText();
		
        Date date = new Date(textMessage.getJMSTimestamp());
		presentTimeStamp = date.toString();
		
	}

	/**
	 * returns a DataObject that represents the JMS TextMessage payload
	 * 
	 * @return the DataObject bearing the JMS TextMessage payload
	 */
	public DataObject getDataObject() throws DataBindingException {
		
		ServiceManager serviceManager = new ServiceManager();
		BOFactory boFactory = (BOFactory)serviceManager.
		  locateService ("com/ibm/websphere/bo/BOFactory"); 
		DataObject timerMediationSDO = boFactory.
		  create("http://TimerMediationLib", "TimerMediationSDO");
		timerMediationSDO.setString("currentTimeStamp", presentTimeStamp);
		
		return timerMediationSDO;
	}
	
	public void write(Message message) throws JMSException {}

	public void setDataObject(DataObject jmsData) throws DataBindingException {}
}
        
        

Code Snippet for SampleJMSFunctionSelector.java


Listing 8. SampleJMSFunctionSelector
       package timermediation.utils;

      import commonj.connector.runtime.FunctionSelector;

       public class SampleJMSFunctionSelector implements FunctionSelector {
	
	      public String generateEISFunctionName(Object[] arguments) {
			String functionName = "invokeTimerMediation";
			return functionName;
	      }
        }
       
       

Now, create the JMS Export for the TimerMediationModule.

Go to the Business Integration perspective and open the assembly diagram for TimerMediationModule. Right click the "TimerMediation" component and from the menu, select Generate Export > Messaging Binding > JMS binding. Choose the following configuration as shown in the figure.

JMS Messaging domain: Point-to-point

End-point configuration: Configure new messaging provider resources



Figure 24. Configuring JMS Export
Configuring JMS Export

For the Data binding configuration, click on Browse. Choose "New" with the radio button clicked for "Show data binding configurations" and accept the defaults, as in the following figure.



Figure 25. Data binding configuration for the JMS Export
Data binding configuration for the JMS Export

Click "Next", click on "Browse" next to the "Data binding class name" and by choosing the "Show data binding classes" radio button, locate the "SampleJMSTextDataBinding" class, we created above, as shown in Figure 26.



Figure 26. Attaching SampleJMSTextDataBinding class
Attaching SampleJMSTextDataBinding class

Click "Ok", then "Finish" and "Ok" again, to choose the Data binding configuration. Repeat the same for the Function selector configuration and choose the "SampleJMSFunctionSelector", as shown in Figure 27.



Figure 27. Attaching SampleJMSFunctionSelector class
Attaching SampleJMSFunctionSelector class

Click "Ok" for the JMS Export Binding window. We have now created the JMS Export for the TimerMediationModule. The assembly diagram should look like the following.



Figure 28. TimerMediationModule Assembly Diagram
TimerMediationModule Assembly Diagram

As the last step, before we test our module, we need to configure the activation spec and the queue name, from where the JMS export would pick up the trigger messages.

Review the "Properties" pane of the TimerMediationExport (our JMS export) and select Binding > End-point configuration. Select the "Specify JNDI Name for pre-configured messaging provider resource" radio button and specify the value "jms/SampleActivationSpec" for the Activation spec properties JNDI lookup name input box as shown in Figure 29.



Figure 29. TimerMediationExport(JMS Export) : Setting ActivationSpec properties
TimerMediationExport(JMS Export) : Setting ActivationSpec properties

Similarly for the JMS Destinations tab, choose the "Specify JNDI name for pre-configured messaging provider resource" radio button and enter the value "jms/SampleTriggerQ" for the JNDI Lookup name, as shown below.



Figure 30. TimerMediationExport(JMS Export) : Setting Receive Destination properties
TimerMediationExport(JMS Export) : Setting Receive Destination properties

Save the TimerMediationModule’s assembly diagram.

Make certain that the SampleStartupBeanEJB is added as part of the TimerMediationModuleApp. To cross-check, switch to the J2EE perspective and check the "Deployment Descriptor" for the TimerMediationModuleApp.The deployment descriptor should look exactly as it does in the following figure.



Figure 31. Adding SampleStartupBeanEJB to the TimerMediationModule
Adding SampleStartupBeanEJB to the TimerMediationModule

We are now done with the implementation and are ready to test our TimerMediationModule! We will do this in the next section.



Back to top



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