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