1 17 package org.apache.servicemix.components.activesoap; 18 19 import java.io.StringWriter ; 20 21 import javax.jbi.messaging.MessageExchange; 22 import javax.jbi.messaging.NormalizedMessage; 23 import javax.xml.stream.XMLStreamReader; 24 import javax.xml.stream.XMLStreamWriter; 25 26 import org.apache.servicemix.components.util.OutBinding; 27 import org.codehaus.activesoap.RestService; 28 29 35 public class ASInOutBinding extends OutBinding { 36 37 private RestService service; 38 private ASMarshaler marshaler = new ASMarshaler(); 39 40 public ASInOutBinding(RestService service) { 41 this.service = service; 42 } 43 44 47 public ASMarshaler getMarshaller() { 48 return marshaler; 49 } 50 51 54 public void setMarshaller(ASMarshaler marshaler) { 55 this.marshaler = marshaler; 56 } 57 58 61 public ASMarshaler getMarshaler() { 62 return marshaler; 63 } 64 65 68 public void setMarshaler(ASMarshaler marshaler) { 69 this.marshaler = marshaler; 70 } 71 72 protected void process(MessageExchange messageExchange, NormalizedMessage inMessage) throws Exception { 75 XMLStreamReader in = marshaler.createStreamReader(inMessage); 76 77 StringWriter buffer = new StringWriter (); 78 XMLStreamWriter out = marshaler.createStreamWriter(buffer); 79 80 org.codehaus.activesoap.MessageExchange asExchange = service.createMessageExchange(in, out); 81 marshaler.fromNMS(asExchange, inMessage); 82 83 service.invoke(asExchange); 84 85 NormalizedMessage outMessage = messageExchange.createMessage(); 86 87 marshaler.setContent(outMessage, buffer.toString()); 88 marshaler.toNMS(outMessage, asExchange); 89 90 answer(messageExchange, outMessage); 91 } 92 } 93 | Popular Tags |