WebSphere WebSphere Enterprise Service Bus, Version 6.0.1 Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Example custom binding for a JMS MapMessage

The following example shows how you can create a custom binding for a JMS MapMessage.

Example Java code

import javax.jms.MapMessage;

import com.ibm.websphere.sca.jms.data.JMSDataBinding;
import com.ibm.websphere.sca.sdo.DataFactory;

import commonj.connector.runtime.DataBindingException;
import commonj.sdo.DataObject;

/*
 * MapMessage Format:
 * 	Symbol (string)
 *  CompanyName (string)
 *  StockValue (double)
 * 
 */

public class CustomMapMsgBindingImpl implements JMSDataBinding {


private String symbol = null;
private String companyName = null;
private double stockValue = 0;

private boolean businessException = false;
private DataObject jmsData = null;

/*
 * Store the passed in DataObject, and retrieve the values for use when creating the message. 
 */
public void setDataObject(DataObject jmsMapData) throws DataBindingException {
	jmsData = jmsMapData;
	symbol =  (String)  jmsData.get("Symbol");
	companyName =  (String)  jmsData.get("CompanyName");
	stockValue =  jmsData.getDouble("StockValue");
}
/*
 * Construct a message from the values previously set.
 */
  public void write(javax.jms.Message message) throws javax.jms.JMSException {
	MapMessage mm = (MapMessage) message;
	mm.setString("Symbol", symbol);
	mm.setString("CompanyName", companyName);
	mm.setDouble("StockValue",stockValue);
	mm.setBooleanProperty("IsBusinessException",businessException);
  }

public DataObject getDataObject() throws DataBindingException {
    return jmsData;
}

/*
 * The method will be called when the message is received, and needs to be
 * converted to a DataObject. The getDataObject method will be called to retrieve the
 * business object.
 */
public void read(javax.jms.Message message) throws javax.jms.JMSException {
	//Handle business exception
	if(message.propertyExists("IsBusinessException")){
		businessException = message.getBooleanProperty("IsBusinessException");
		//If this is a business exception, then likely payload will be fault.
		//Load fault data from message , set in jmsData and return		
	}
	symbol = ((MapMessage) message).getString("Symbol");
	companyName = ((MapMessage) message).getString("CompanyName");
	stockValue = ((MapMessage) message).getDouble("StockValue");
	/*
	 * Create the data object from the DataFactory. The Business object can be 
	 * determined from the export details view. The export specifies the Interface 
	 * and operation, and from the definition of the operation, the expected input/output
	 * type can be seen.  
	 * 
	 * The first parameter is the namespace of the operation input type, and the
	 * second parameter is the name of the type.  
	 */
	jmsData = DataFactory.INSTANCE.create("http://TradingDeskLibrary","TradingDeskBO");
	/* 
	 * The DataObject in this case has been defined with 2 string fields, and 1 double
	 * field.
	 * 
	 * These fields can now be populated using the set methods. 
	 */
	if (jmsData != null) {
		jmsData.set("Symbol",symbol);
		jmsData.set("CompanyName",companyName);
		jmsData.setDouble("StockValue",stockValue);
	}
}

 public int getMessageType() {
 	/*
 	 * One of:
 	 * JMSDataBinding.BYTES_MESSAGE
 	 * JMSDataBinding.MAP_MESSAGE
 	 * JMSDataBinding.OBJECT_MESSAGE
 	 * JMSDataBinding.STREAM_MESSAGE
 	 * JMSDataBinding.TEXT_MESSAGE
 	 */
 	return JMSDataBinding.MAP_MESSAGE;
}

 public boolean isBusinessException() {
        return businessException;
    }

 public void setBusinessException(boolean isBusinessException) {
	this.businessException = isBusinessException;
 } 
    
}

Example XSD

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://TradingDeskLibrary">
  <xsd:complexType name="TradingDeskBO">
    <xsd:sequence>
      <xsd:element minOccurs="0" name="Symbol" type="xsd:string"/>
      <xsd:element minOccurs="0" name="CompanyName" type="xsd:string"/>
      <xsd:element minOccurs="0" name="StockValue" type="xsd:double"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Example WSDL

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:bons1="http://TradingDeskLibrary" xmlns:tns="http://TradingDeskLibrary/TradingDeskInterface" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TradingDeskInterface" targetNamespace="http://TradingDeskLibrary/TradingDeskInterface">
  <wsdl:types>
    <xsd:schema targetNamespace="http://TradingDeskLibrary/TradingDeskInterface" xmlns:bons1="http://TradingDeskLibrary" xmlns:tns="http://TradingDeskLibrary/TradingDeskInterface" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import namespace="http://TradingDeskLibrary" schemaLocation="TradingDeskBO.xsd"/>
      <xsd:element name="TradingDeskOperation">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="input1" nillable="true" type="bons1:TradingDeskBO"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
    <wsdl:message name="TradingDeskOperationRequestMsg">
    <wsdl:part element="tns:TradingDeskOperation" name="TradingDeskOperationParameters"/>
  </wsdl:message>
    <wsdl:portType name="TradingDeskInterface">
    <wsdl:operation name="TradingDeskOperation">
      <wsdl:input message="tns:TradingDeskOperationRequestMsg" name="TradingDeskOperationRequest"/>
    </wsdl:operation>
  </wsdl:portType>
</wsdl:definitions>

Reference topic

Terms of Use | Rate this page

Timestamp iconLast updated: 13 Dec 2005
http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wesb.doc\ref\rwesb_jmscustombindings.html

(C) Copyright IBM Corporation 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)