1 17 package org.apache.servicemix.components.activesoap; 18 19 import org.codehaus.activesoap.transport.Invocation; 20 import org.codehaus.activesoap.transport.TransportClient; 21 import org.codehaus.activesoap.util.XMLStreamFactory; 22 23 import javax.jbi.messaging.DeliveryChannel; 24 import javax.jbi.messaging.Fault; 25 import javax.jbi.messaging.InOnly; 26 import javax.jbi.messaging.InOut; 27 import javax.jbi.messaging.MessageExchangeFactory; 28 import javax.jbi.messaging.NormalizedMessage; 29 import javax.xml.stream.XMLStreamReader; 30 import java.io.Reader ; 31 32 37 public class ASTransport implements TransportClient { 38 39 private ASMarshaler marshaler = new ASMarshaler(); 40 41 42 private DeliveryChannel channel; 43 private XMLStreamFactory streamFactory; 44 45 public ASTransport(DeliveryChannel channel) { 46 this(channel, new XMLStreamFactory()); 47 } 48 49 public ASTransport(DeliveryChannel channel, XMLStreamFactory streamFactory) { 50 this.channel = channel; 51 this.streamFactory = streamFactory; 52 } 53 54 public Invocation createInvocation() { 55 return new ASInvocation(this, streamFactory); 56 } 57 58 public void invokeOneWay(Invocation invocation, Reader request) throws Exception { 59 throw new UnsupportedOperationException ("Should never be invoked directly"); 60 } 61 62 public Reader invokeRequest(Invocation invocation, Reader request) throws Exception { 63 throw new UnsupportedOperationException ("Should never be invoked directly"); 64 } 65 66 public void close() throws Exception { 67 channel.close(); 68 } 69 70 public void invokeOneWay(ASInvocation invocation, String xml) throws Exception { 71 MessageExchangeFactory fac = channel.createExchangeFactory(); 72 InOnly exchange = fac.createInOnlyExchange(); 73 NormalizedMessage inMessage = exchange.createMessage(); 74 marshaler.setContent(inMessage, xml); 75 exchange.setInMessage(inMessage); 76 channel.send(exchange); 77 } 78 79 public XMLStreamReader invokeRequest(ASInvocation invocation, String xml) throws Exception { 80 MessageExchangeFactory fac = channel.createExchangeFactory(); 81 InOut exchange = fac.createInOutExchange(); 82 NormalizedMessage inMessage = exchange.createMessage(); 83 marshaler.setContent(inMessage, xml); 84 exchange.setInMessage(inMessage); 85 boolean answer = channel.sendSync(exchange); 86 if (answer) { 87 NormalizedMessage outMessage = exchange.getOutMessage(); 88 return marshaler.createStreamReader(outMessage); 89 } 90 else { 91 Fault fault = exchange.getFault(); 92 return marshaler.createStreamReader(fault); 93 } 94 } 95 } 96 | Popular Tags |