1 22 package org.objectweb.petals.binding.axis2.listener.soap; 23 24 import java.io.ByteArrayOutputStream ; 25 import java.util.Iterator ; 26 27 import javax.jbi.messaging.DeliveryChannel; 28 import javax.jbi.messaging.InOnly; 29 import javax.jbi.messaging.InOut; 30 import javax.jbi.messaging.MessageExchange; 31 import javax.jbi.messaging.MessagingException; 32 import javax.jbi.messaging.NormalizedMessage; 33 import javax.xml.namespace.QName ; 34 import javax.xml.transform.Source ; 35 36 import org.apache.axiom.om.OMElement; 37 import org.apache.axiom.om.OMNamespace; 38 import org.apache.axiom.soap.SOAPBody; 39 import org.apache.axiom.soap.SOAPEnvelope; 40 import org.apache.axis2.context.MessageContext; 41 import org.apache.axis2.description.AxisService; 42 43 import org.objectweb.petals.binding.axis2.SOAPHelper; 44 import org.objectweb.petals.component.common.util.SourceHelper; 45 46 51 public class Axis2ReceiverUtil { 52 53 60 public Source createSourceContent(MessageContext message) throws Exception { 61 String source = getBodyElement(message); 62 return SourceHelper.createSource(source); 63 } 64 65 73 public String createStringContent(NormalizedMessage message) 74 throws Exception { 75 return SourceHelper.createString(message.getContent()); 76 } 77 78 @SuppressWarnings ("unchecked") 79 public String getBodyElement(MessageContext message) throws Exception { 80 String result = new String (); 81 SOAPEnvelope env = message.getEnvelope(); 82 SOAPBody body = env.getBody(); 83 OMNamespace namespace = env.getNamespace(); 84 Iterator <OMNamespace> envNS = env.getAllDeclaredNamespaces(); 85 Iterator <OMNamespace> bodyNS = body.getAllDeclaredNamespaces(); 86 OMElement element = body.getFirstElement(); 87 if (element != null) { 88 element.declareNamespace(namespace); 89 while (envNS.hasNext()) { 90 element.declareNamespace(envNS.next()); 91 } 92 while (bodyNS.hasNext()) { 93 element.declareNamespace(bodyNS.next()); 94 } 95 ByteArrayOutputStream os = new ByteArrayOutputStream (); 96 element.serialize(os); 97 result = os.toString(); 98 } 99 return result; 100 } 101 102 103 111 public QName getOperationName(MessageContext message) { 112 return message.getOperationContext().getAxisOperation().getName(); 113 } 114 115 123 public QName getServiceName(MessageContext message) { 124 QName name = null; 125 AxisService axisService = message.getServiceContext().getAxisService(); 126 name = SOAPHelper.getServiceName(axisService); 127 return name; 128 } 129 130 131 151 protected MessageExchange createMessageExchange(DeliveryChannel channel, QName operationName, 152 QName serviceName, Source content, boolean inOnly) 153 throws MessagingException { 154 MessageExchange messageExchange = null; 155 156 if (channel != null) { 157 if (inOnly) { 158 messageExchange = channel.createExchangeFactory() 159 .createInOnlyExchange(); 160 } else { 161 messageExchange = channel.createExchangeFactory() 162 .createInOutExchange(); 163 } 164 NormalizedMessage nm = messageExchange.createMessage(); 165 nm.setContent(content); 166 if (inOnly) { 167 ((InOnly) messageExchange).setInMessage(nm); 168 } else { 169 ((InOut) messageExchange).setInMessage(nm); 170 } 171 messageExchange.setService(serviceName); 172 messageExchange.setOperation(operationName); 173 } else { 174 throw new MessagingException( 175 "Can't retrieve the delivery channel of the component"); 176 } 177 178 return messageExchange; 179 } 180 } 181 | Popular Tags |