Outbound Marshalling Code Example
Code for a simple outbound marshaller is shown in the example below. If the message is a TextMessage, the text is changed to uppercase and a counter field is added, using the Counter object passed in UserData, and the message is published to the same destination (event type) as the message. If the message is not a TextMessage, a value of null is returned and the webMethods Broker used as a JMS provider will send the message as if no marshaller was present.
class SimpleMarshalOut implements WmMarshalOut
{
public WmBrokerEventWrapper mapMessageToEvent(Message msg, Object
userData) throws Exception
{
try {
if (msg instanceof TextMessage) {
WmDestination destination=(WmDestination) msg.getJMSDestination();
BrokerEvent event =
new BrokerEvent(null,destination.getEventType());
TextMessage textMsg = (TextMessage) msg;
event.setUCStringField("myField", textMsg.getText().toUpperCase());
event.setIntegerField("counter", ((Counter) userData).getValue());
event.setIntegerField("_env.tag", 10);
((Counter) userData).increment();
return WmBrokerEventWrapper.create(event);
}
return null;
} catch (Exception exc) {
throw exc;
}
}
}