1 17 package org.apache.servicemix.tck; 18 19 import javax.jbi.component.ComponentLifeCycle; 20 import javax.jbi.messaging.MessageExchange; 21 import javax.jbi.messaging.MessagingException; 22 import javax.jbi.messaging.NormalizedMessage; 23 import javax.xml.namespace.QName ; 24 25 import org.apache.servicemix.MessageExchangeListener; 26 import org.apache.servicemix.components.util.CopyTransformer; 27 import org.apache.servicemix.components.util.MessageTransformer; 28 import org.apache.servicemix.components.util.PojoSupport; 29 import org.apache.servicemix.jbi.NoInMessageAvailableException; 30 31 37 public class ReceiverPojo extends PojoSupport implements ComponentLifeCycle, MessageExchangeListener, Receiver { 38 39 public static final QName SERVICE = new QName ("http://servicemix.org/example/", "receiver"); 40 public static final String ENDPOINT = "receiver"; 41 42 private MessageList messageList = new MessageList(); 43 private MessageTransformer messageTransformer = CopyTransformer.getInstance(); 44 45 public ReceiverPojo() { 46 this(SERVICE, ENDPOINT); 47 } 48 49 public ReceiverPojo(QName service, String endpoint) { 50 super(service, endpoint); 51 } 52 53 public void onMessageExchange(MessageExchange exchange) throws MessagingException { 56 NormalizedMessage inMessage = getInMessage(exchange); 57 NormalizedMessage copyMessage = exchange.createMessage(); 60 getMessageTransformer().transform(exchange, inMessage, copyMessage); 61 messageList.addMessage(copyMessage); 62 done(exchange); 63 } 64 65 68 protected NormalizedMessage getInMessage(MessageExchange exchange) throws NoInMessageAvailableException { 69 NormalizedMessage message = exchange.getMessage("in"); 70 if (message == null) { 71 throw new NoInMessageAvailableException(exchange); 72 } 73 return message; 74 } 75 76 public MessageTransformer getMessageTransformer() { 77 return messageTransformer; 78 } 79 80 public MessageList getMessageList() { 83 return messageList; 84 } 85 } 86 | Popular Tags |