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