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