1 17 package org.apache.servicemix.components.xfire; 18 19 import java.io.ByteArrayOutputStream ; 20 21 import javax.jbi.JBIException; 22 import javax.jbi.messaging.MessageExchange; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.xml.stream.XMLStreamReader; 25 26 import org.apache.servicemix.components.util.OutBinding; 27 import org.codehaus.xfire.MessageContext; 28 import org.codehaus.xfire.XFire; 29 import org.codehaus.xfire.exchange.InMessage; 30 import org.codehaus.xfire.transport.Channel; 31 import org.codehaus.xfire.transport.Transport; 32 import org.codehaus.xfire.transport.local.LocalTransport; 33 34 public class XFireBinding extends OutBinding { 35 private XMarshaler marshaler; 36 37 private XFire xfire; 38 39 public XFireBinding() 40 { 41 super(); 42 43 this.marshaler = new XMarshaler(); 44 } 45 46 protected void process(MessageExchange messageExchange, NormalizedMessage nm) throws Exception { 47 48 XMLStreamReader reader = marshaler.createStreamReader(nm); 49 if (reader == null) { 50 throw new JBIException("Could not get source as XMLStreamReader."); 51 } 52 53 InMessage in = new InMessage(reader, ""); 54 MessageContext context = new MessageContext(); 55 context.setXFire(xfire); 56 context.setService(xfire.getServiceRegistry().getService(getService().getLocalPart())); 57 58 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 59 context.setProperty(Channel.BACKCHANNEL_URI, buffer); 60 61 Transport transport = xfire.getTransportManager().getTransport(LocalTransport.BINDING_ID); 62 Channel channel = transport.createChannel(); 63 channel.receive(context, in); 64 65 NormalizedMessage outMessage = messageExchange.createMessage(); 66 67 marshaler.setContent(outMessage, buffer.toString()); 68 marshaler.toNMS(outMessage, context.getOutMessage()); 69 70 answer(messageExchange, outMessage); 71 } 72 73 public XFire getXfire() { 74 return xfire; 75 } 76 77 public void setXfire(XFire xfire) { 78 this.xfire = xfire; 79 } 80 } 81 | Popular Tags |