1 10 11 package org.mule.providers.soap.axis.extensions; 12 13 import org.apache.axis.AxisFault; 14 import org.apache.axis.MessageContext; 15 import org.apache.axis.handlers.BasicHandler; 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.mule.config.MuleProperties; 19 import org.mule.providers.soap.MuleSoapHeaders; 20 import org.mule.umo.UMOEvent; 21 22 import javax.xml.soap.SOAPEnvelope ; 23 import javax.xml.soap.SOAPMessage ; 24 25 32 public class MuleSoapHeadersHandler extends BasicHandler 33 { 34 37 private static final long serialVersionUID = 1813393257662701953L; 38 39 42 protected static Log logger = LogFactory.getLog(MuleSoapHeadersHandler.class); 43 44 public void invoke(MessageContext msgContext) throws AxisFault 45 { 46 boolean setMustUnderstand = msgContext.isPropertyTrue("MULE_HEADER_MUST_UNDERSTAND"); 47 48 try 49 { 50 if (msgContext.isClient()) 51 { 52 if (!msgContext.getPastPivot()) 53 { 54 processClientRequest(msgContext, setMustUnderstand); 55 if (logger.isDebugEnabled()) 56 { 57 logger.debug("After Client Request, Message is:\n" 58 + msgContext.getRequestMessage().getSOAPPartAsString()); 59 } 60 } 61 else 62 { 63 processClientResponse(msgContext); 64 if (logger.isDebugEnabled()) 65 { 66 logger.debug("After Client Response, Message is:\n" 67 + msgContext.getRequestMessage().getSOAPPartAsString()); 68 } 69 } 70 } 71 else 72 { 73 if (!msgContext.getPastPivot()) 74 { 75 processServerRequest(msgContext); 76 if (logger.isDebugEnabled()) 77 { 78 logger.debug("After Server Request, Message is:\n" 79 + msgContext.getRequestMessage().getSOAPPartAsString()); 80 } 81 } 82 else 83 { 84 processServerResponse(msgContext, setMustUnderstand); 85 if (logger.isDebugEnabled()) 86 { 87 logger.debug("After Server Response, Message is:\n" 88 + msgContext.getRequestMessage().getSOAPPartAsString()); 89 } 90 } 91 } 92 } 93 catch (Exception e) 94 { 95 throw AxisFault.makeFault(e); 96 } 97 } 98 99 104 protected synchronized void processClientRequest(MessageContext msgContext, boolean setMustUnderstand) 105 throws Exception 106 { 107 SOAPMessage msg = msgContext.getMessage(); 108 if (msg == null) 109 { 110 return; 111 } 112 UMOEvent event = (UMOEvent)msgContext.getProperty(MuleProperties.MULE_EVENT_PROPERTY); 113 114 if (event == null) 115 { 116 return; 117 } 118 else 119 { 120 synchronized (msgContext) 121 { 122 MuleSoapHeaders headers = new MuleSoapHeaders(event); 123 headers.addHeaders(msgContext.getMessage().getSOAPPart().getEnvelope()); 124 } 125 } 126 } 127 128 133 protected void processClientResponse(MessageContext msgContext) throws Exception 134 { 135 SOAPMessage msg = msgContext.getMessage(); 136 if (msg == null) 137 { 138 return; 139 } 140 SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); 141 MuleSoapHeaders headers = new MuleSoapHeaders(env.getHeader()); 142 143 if (headers.getCorrelationId() != null) 144 { 145 msgContext.setProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY, headers.getCorrelationId()); 146 } 147 if (headers.getCorrelationGroup() != null) 148 { 149 msgContext.setProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, 150 headers.getCorrelationGroup()); 151 } 152 if (headers.getCorrelationSequence() != null) 153 { 154 msgContext.setProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, 155 headers.getCorrelationSequence()); 156 } 157 158 if (headers.getReplyTo() != null) 159 { 160 msgContext.setProperty(MuleProperties.MULE_REPLY_TO_PROPERTY, headers.getReplyTo()); 161 } 162 } 163 164 170 protected void processServerRequest(MessageContext msgContext) throws Exception 171 { 172 SOAPMessage msg = msgContext.getMessage(); 173 if (msg == null) 174 { 175 return; 176 } 177 MuleSoapHeaders headers = new MuleSoapHeaders(msg.getSOAPPart().getEnvelope().getHeader()); 178 msgContext.setProperty(MuleSoapHeaders.ENV_REQUEST_HEADERS, headers); 179 } 180 181 186 protected void processServerResponse(MessageContext msgContext, boolean setMustUnderstand) 187 throws Exception 188 { 189 SOAPMessage msg = msgContext.getMessage(); 190 if (msg == null) 191 { 192 return; 193 } 194 MuleSoapHeaders headers = (MuleSoapHeaders)msgContext.getProperty(MuleSoapHeaders.ENV_REQUEST_HEADERS); 195 196 if (headers == null) 197 { 198 return; 199 } 200 else 201 { 202 headers.addHeaders(msgContext.getMessage().getSOAPPart().getEnvelope()); 203 } 204 } 205 206 } 207 | Popular Tags |