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