1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.axis.message.addressing.handler;
17
18 import org.apache.axis.AxisFault;
19 import org.apache.axis.Handler;
20 import org.apache.axis.Message;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.message.addressing.AddressingHeaders;
23 import org.apache.axis.message.addressing.Constants;
24 import org.apache.axis.message.addressing.EndpointReference;
25 import org.apache.ws.addressing.handler.ServerSideAddressingHandler;
26 import org.w3c.dom.Document;
27 import org.w3c.dom.Element;
28
29 import javax.xml.namespace.QName;
30 import javax.xml.rpc.Call;
31 import javax.xml.rpc.JAXRPCException;
32 import javax.xml.rpc.Service;
33 import javax.xml.rpc.ServiceException;
34 import javax.xml.rpc.handler.soap.SOAPMessageContext;
35 import javax.xml.soap.SOAPBody;
36 import javax.xml.soap.SOAPException;
37
38 import java.io.IOException;
39 import java.util.Hashtable;
40 import java.util.List;
41
42
43
44
45
46
47
48
49 public class AxisServerSideAddressingHandler extends ServerSideAddressingHandler
50 implements Handler {
51
52
53
54
55 private static final long serialVersionUID = 7912643926095186786L;
56
57
58
59
60 private GenericAxisHandler axisHelperHandler = new GenericAxisHandler(this);
61
62
63
64
65 public void init() {
66 axisHelperHandler.init();
67 }
68
69
70
71
72 public void cleanup() {
73 axisHelperHandler.cleanup();
74 }
75
76
77
78
79 public boolean canHandleBlock(QName qname) {
80 return (axisHelperHandler.canHandleBlock(qname));
81 }
82
83
84
85
86 public void setOption(String name, Object value) {
87 axisHelperHandler.setOption(name, value);
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102 public boolean setOptionDefault(String name, Object value) {
103 return axisHelperHandler.setOptionDefault(name, value);
104 }
105
106
107
108
109 public Object getOption(String name) {
110 return axisHelperHandler.getOption(name);
111 }
112
113
114
115
116 public Hashtable<?, ?> getOptions() {
117 return axisHelperHandler.getOptions();
118 }
119
120
121
122
123 public void setOptions(Hashtable opts) {
124 axisHelperHandler.setOptions(opts);
125 }
126
127
128
129
130 public void setName(String name) {
131 axisHelperHandler.setName(name);
132 }
133
134
135
136
137 public String getName() {
138 return axisHelperHandler.getName();
139 }
140
141
142
143
144 public Element getDeploymentData(Document doc) {
145 return axisHelperHandler.getDeploymentData(doc);
146 }
147
148
149
150
151 public List<?> getUnderstoodHeaders() {
152 return axisHelperHandler.getUnderstoodHeaders();
153 }
154
155
156
157
158 public void generateWSDL(MessageContext msgContext) throws AxisFault {
159 axisHelperHandler.generateWSDL(msgContext);
160 }
161
162
163
164
165 public void invoke(MessageContext msgContext) throws AxisFault {
166 axisHelperHandler.invoke(msgContext);
167 }
168
169
170
171
172 public void onFault(MessageContext msgContext) {
173 axisHelperHandler.onFault(msgContext);
174 }
175
176
177
178
179
180
181 protected String generateUUId() {
182 return axisHelperHandler.generateUUId();
183 }
184
185
186
187
188 protected void forwardMessage(SOAPMessageContext soapMsgContext,
189 EndpointReference endpointRef) {
190
191 try {
192 Service service = getService(soapMsgContext);
193 Call call = service.createCall();
194 call.setTargetEndpointAddress(endpointRef.getAddress().toString());
195 ((org.apache.axis.client.Call) call).setRequestMessage((Message) soapMsgContext
196 .getMessage());
197 AddressingHeaders addrHeaders = buildAddressingHeadersForMessageForward(
198 soapMsgContext, endpointRef);
199 call.setProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS, addrHeaders);
200 configureCall(call, soapMsgContext);
201 call.invoke(new Object[0]);
202 SOAPBody responseBody = soapMsgContext.getMessage().getSOAPPart().getEnvelope()
203 .getBody();
204 removeAllChildElements(responseBody);
205 } catch (IOException e) {
206 throw new JAXRPCException("Failed to forward SOAP message", e);
207 } catch (ServiceException e) {
208 throw new JAXRPCException("Failed to forward SOAP message", e);
209 } catch (SOAPException e) {
210 throw new JAXRPCException("Failed to forward SOAP message", e);
211 }
212
213 }
214
215
216
217
218 @Override
219 protected void setTargetService(SOAPMessageContext soapMsgContext,
220 AddressingHeaders headers) throws Exception {
221 org.apache.axis.MessageContext axisMsgContext
222 = (org.apache.axis.MessageContext) soapMsgContext;
223
224
225 if (axisMsgContext.getService() == null
226 && axisMsgContext.getTargetService() == null) {
227 axisMsgContext.setTargetService(getTargetServiceName(headers));
228
229
230 if (axisMsgContext.getTargetService() != null) {
231 ((Message) axisMsgContext.getMessage()).getSOAPPartAsString();
232 }
233 }
234 }
235
236
237
238
239
240
241
242
243 private AddressingHeaders buildAddressingHeadersForMessageForward(
244 SOAPMessageContext soapMsgContext, EndpointReference endpointRef) {
245 AddressingHeaders headers = null;
246 if (soapMsgContext != null) {
247 headers = (AddressingHeaders) soapMsgContext
248 .getProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS);
249 }
250 if (headers == null) {
251 headers = new AddressingHeaders(endpointRef);
252 }
253 return headers;
254 }
255
256 }