I have a XMPP binding component that receives messages from a Jabber client.
Now I am going to make a service engine (another service unit) that returns
the received message to the binding component, which means an echo
application.
I created a class extending XMPPMarshaler class.
Now I am going to create MessageExchange to deliver the received message
from the binding component to the service engine in toNMS method. However, I
don't find any clue on how to create MessageExchange in the extention of
XMPPMarshaler class.
Here is my source code.
package org.apache.servicemix.jbi;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.client.ServiceMixClient;
import org.apache.servicemix.jbi.jaxp.SourceMarshaler;
import org.apache.servicemix.xmpp.XMPPMarshaler;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
public class LSJabberMarshaler extends XMPPMarshaler {
private static Log log = LogFactory.getLog(LSJabberMarshaler.class);
/**
* Marshals the Jabber message into an NMS message
*
* @throws javax.jbi.messaging.MessagingException
*
*/
public void toNMS(NormalizedMessage normalizedMessage, Packet packet)
throws MessagingException {
addNmsProperties(normalizedMessage, packet);
QName qname = new QName("xmpp://johnrail/xmpp-echo",
"lionsharexmpphandler");
if (packet instanceof Message) {
Message message = (Message) packet;
String text = message.getBody();
if (text != null) {
Source source =
getSourceMarshaler().asSource(getMessageBodyOpenTag() + text +
getMessageBodyCloseTag());
normalizedMessage.setContent(source);
}
}
normalizedMessage.setProperty("org.apache.servicemix.xmpp.packet",
packet);
}
/**
* Marshals from the Jabber message to the normalized message
*
* @param message
* @param exchange
* @param normalizedMessage @throws
javax.xml.transform.TransformerException
*/
public void fromNMS(Message message, MessageExchange exchange,
NormalizedMessage normalizedMessage) throws TransformerException {
// lets create a text message
String xml = messageAsString(normalizedMessage);
message.setBody(xml);
addJabberProperties(message, exchange, normalizedMessage);
}
}
--
View this message in context:
http://www.nabble.com/How-to-create-a-service-engine-behind-XMPP-binding-component-tp22605733p22605733.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.