1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.soap.xfire; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.impl.MuleDescriptor; |
15 | |
import org.mule.impl.endpoint.MuleEndpoint; |
16 | |
import org.mule.impl.internal.notifications.ManagerNotification; |
17 | |
import org.mule.impl.internal.notifications.ManagerNotificationListener; |
18 | |
import org.mule.impl.internal.notifications.NotificationException; |
19 | |
import org.mule.impl.model.ModelHelper; |
20 | |
import org.mule.providers.AbstractConnector; |
21 | |
import org.mule.providers.http.HttpConnector; |
22 | |
import org.mule.providers.http.HttpConstants; |
23 | |
import org.mule.providers.soap.MethodFixInterceptor; |
24 | |
import org.mule.providers.soap.xfire.i18n.XFireMessages; |
25 | |
import org.mule.umo.UMOComponent; |
26 | |
import org.mule.umo.UMOException; |
27 | |
import org.mule.umo.endpoint.UMOEndpoint; |
28 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
29 | |
import org.mule.umo.lifecycle.InitialisationException; |
30 | |
import org.mule.umo.manager.UMOServerNotification; |
31 | |
import org.mule.umo.provider.UMOMessageReceiver; |
32 | |
import org.mule.util.ClassUtils; |
33 | |
import org.mule.util.StringUtils; |
34 | |
import org.mule.util.SystemUtils; |
35 | |
|
36 | |
import java.util.List; |
37 | |
import java.util.Map; |
38 | |
|
39 | |
import org.codehaus.xfire.DefaultXFire; |
40 | |
import org.codehaus.xfire.XFire; |
41 | |
import org.codehaus.xfire.aegis.AegisBindingProvider; |
42 | |
import org.codehaus.xfire.aegis.type.TypeMappingRegistry; |
43 | |
import org.codehaus.xfire.annotations.AnnotationServiceFactory; |
44 | |
import org.codehaus.xfire.annotations.WebAnnotations; |
45 | |
import org.codehaus.xfire.service.Service; |
46 | |
import org.codehaus.xfire.service.ServiceFactory; |
47 | |
import org.codehaus.xfire.service.binding.BindingProvider; |
48 | |
import org.codehaus.xfire.service.binding.ObjectServiceFactory; |
49 | |
import org.codehaus.xfire.soap.SoapConstants; |
50 | |
import org.codehaus.xfire.wsdl11.builder.WSDLBuilderFactory; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public class XFireConnector extends AbstractConnector |
56 | |
implements ManagerNotificationListener |
57 | |
{ |
58 | |
public static final String XFIRE_SERVICE_COMPONENT_NAME = "_xfireServiceComponent"; |
59 | |
public static final String DEFAULT_MULE_NAMESPACE_URI = "http://www.muleumo.org"; |
60 | |
public static final String XFIRE_PROPERTY = "xfire"; |
61 | |
public static final String XFIRE_TRANSPORT = "transportClass"; |
62 | |
|
63 | |
public static final String CLASSNAME_ANNOTATIONS = "org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations"; |
64 | |
private static final String DEFAULT_BINDING_PROVIDER_CLASS = "org.codehaus.xfire.aegis.AegisBindingProvider"; |
65 | |
private static final String DEFAULT_TYPE_MAPPING_REGISTRY_CLASS = "org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry"; |
66 | |
|
67 | |
protected MuleDescriptor xfireDescriptor; |
68 | |
|
69 | |
private XFire xfire; |
70 | |
|
71 | |
private ServiceFactory serviceFactory; |
72 | |
|
73 | 66 | private boolean enableJSR181Annotations = false; |
74 | |
|
75 | 66 | private List clientServices = null; |
76 | 66 | private List clientInHandlers = null; |
77 | 66 | private List clientOutHandlers = null; |
78 | 66 | private String clientTransport = null; |
79 | |
|
80 | 66 | private String bindingProvider = null; |
81 | 66 | private String typeMappingRegistry = null; |
82 | 66 | private String serviceTransport = null; |
83 | 66 | private List serverInHandlers = null; |
84 | 66 | private List serverOutHandlers = null; |
85 | |
|
86 | 66 | private Map extraProperties = null; |
87 | |
|
88 | |
public XFireConnector() |
89 | |
{ |
90 | 66 | super(); |
91 | 66 | registerProtocols(); |
92 | 66 | } |
93 | |
|
94 | |
protected void registerProtocols() |
95 | |
{ |
96 | 60 | registerSupportedProtocol("http"); |
97 | 60 | registerSupportedProtocol("https"); |
98 | 60 | registerSupportedProtocol("jms"); |
99 | 60 | registerSupportedProtocol("vm"); |
100 | 60 | registerSupportedProtocol("servlet"); |
101 | 60 | } |
102 | |
|
103 | |
public String getProtocol() |
104 | |
{ |
105 | 900 | return "xfire"; |
106 | |
} |
107 | |
|
108 | |
protected void doInitialise() throws InitialisationException |
109 | |
{ |
110 | |
|
111 | |
try |
112 | |
{ |
113 | 66 | MuleManager.getInstance().registerListener(this); |
114 | |
} |
115 | 0 | catch (NotificationException e) |
116 | |
{ |
117 | 0 | throw new InitialisationException(e, this); |
118 | 66 | } |
119 | |
|
120 | 66 | if (xfire == null) |
121 | |
{ |
122 | 66 | xfire = new DefaultXFire(); |
123 | |
} |
124 | |
|
125 | 66 | if (clientServices != null) |
126 | |
{ |
127 | 2 | ObjectServiceFactory factory = new ObjectServiceFactory(); |
128 | 2 | configureBindingProvider(factory); |
129 | |
|
130 | 4 | for (int i = 0; i < clientServices.size(); i++) |
131 | |
{ |
132 | |
try |
133 | |
{ |
134 | 2 | Class clazz = ClassUtils.loadClass(clientServices.get(i).toString(), this.getClass()); |
135 | 2 | Service service = factory.create(clazz); |
136 | 2 | xfire.getServiceRegistry().register(service); |
137 | |
} |
138 | 0 | catch (ClassNotFoundException e) |
139 | |
{ |
140 | 0 | throw new InitialisationException( |
141 | |
XFireMessages.couldNotInitAnnotationProcessor(clientServices.get(i)), e, this); |
142 | 2 | } |
143 | |
} |
144 | |
} |
145 | |
|
146 | 66 | if (serviceFactory == null) |
147 | |
{ |
148 | 66 | if (enableJSR181Annotations) |
149 | |
{ |
150 | |
|
151 | 0 | if (!SystemUtils.isJavaVersionAtLeast(150)) |
152 | |
{ |
153 | 0 | throw new InitialisationException( |
154 | |
XFireMessages.annotationsRequireJava5(), this); |
155 | |
} |
156 | |
try |
157 | |
{ |
158 | 0 | WebAnnotations wa = (WebAnnotations)ClassUtils.instanciateClass( |
159 | |
CLASSNAME_ANNOTATIONS, null, this.getClass()); |
160 | 0 | serviceFactory = new AnnotationServiceFactory(wa, xfire.getTransportManager()); |
161 | 0 | configureBindingProvider((ObjectServiceFactory)serviceFactory); |
162 | |
} |
163 | 0 | catch (Exception ex) |
164 | |
{ |
165 | 0 | throw new InitialisationException( |
166 | |
XFireMessages.couldNotInitAnnotationProcessor(CLASSNAME_ANNOTATIONS), ex, this); |
167 | 0 | } |
168 | |
} |
169 | |
else |
170 | |
{ |
171 | 66 | serviceFactory = new MuleObjectServiceFactory(xfire.getTransportManager()); |
172 | 66 | configureBindingProvider((ObjectServiceFactory)serviceFactory); |
173 | |
} |
174 | |
} |
175 | |
|
176 | 66 | if (serviceFactory instanceof ObjectServiceFactory) |
177 | |
{ |
178 | 66 | ObjectServiceFactory osf = (ObjectServiceFactory)serviceFactory; |
179 | 66 | if (osf.getTransportManager() == null) |
180 | |
{ |
181 | 0 | osf.setTransportManager(xfire.getTransportManager()); |
182 | |
} |
183 | |
|
184 | |
} |
185 | 66 | } |
186 | |
|
187 | |
protected void configureBindingProvider(ObjectServiceFactory factory) throws InitialisationException |
188 | |
{ |
189 | 68 | if (StringUtils.isBlank(bindingProvider)) |
190 | |
{ |
191 | 66 | bindingProvider = DEFAULT_BINDING_PROVIDER_CLASS; |
192 | |
} |
193 | |
|
194 | 68 | if (StringUtils.isBlank(typeMappingRegistry)) |
195 | |
{ |
196 | 66 | typeMappingRegistry = DEFAULT_TYPE_MAPPING_REGISTRY_CLASS; |
197 | |
} |
198 | |
|
199 | |
try |
200 | |
{ |
201 | 68 | Class clazz = ClassUtils.loadClass(bindingProvider, this.getClass()); |
202 | 68 | BindingProvider provider = (BindingProvider)ClassUtils.instanciateClass(clazz, new Object[] {} ); |
203 | |
|
204 | |
|
205 | |
|
206 | 68 | if (bindingProvider.equals(DEFAULT_BINDING_PROVIDER_CLASS) && !typeMappingRegistry.equals(DEFAULT_TYPE_MAPPING_REGISTRY_CLASS)) |
207 | |
{ |
208 | 0 | Class registryClazz = ClassUtils.loadClass(typeMappingRegistry, this.getClass()); |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | 0 | TypeMappingRegistry registry = (TypeMappingRegistry)ClassUtils.instanciateClass(registryClazz, new Object[] { } ); |
217 | 0 | ((AegisBindingProvider)provider).setTypeMappingRegistry(registry); |
218 | |
} |
219 | |
|
220 | 68 | factory.setBindingProvider(provider); |
221 | |
|
222 | 68 | String wsdlBuilderFactoryClass = null; |
223 | |
|
224 | |
|
225 | 68 | if (bindingProvider.equals("org.codehaus.xfire.service.binding.MessageBindingProvider")) |
226 | |
{ |
227 | 0 | factory.setStyle(SoapConstants.STYLE_MESSAGE); |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | 68 | if (wsdlBuilderFactoryClass != null) |
241 | |
{ |
242 | 0 | Class wsdlBuilderFactoryClazz = ClassUtils.loadClass(wsdlBuilderFactoryClass, this.getClass()); |
243 | 0 | WSDLBuilderFactory wsdlBuilderFactory = (WSDLBuilderFactory)ClassUtils.instanciateClass(wsdlBuilderFactoryClazz, new Object[] { } ); |
244 | 0 | factory.setWsdlBuilderFactory(wsdlBuilderFactory); |
245 | |
} |
246 | |
} |
247 | 0 | catch (Exception ex) |
248 | |
{ |
249 | 0 | throw new InitialisationException( |
250 | |
XFireMessages.unableToInitBindingProvider(bindingProvider), ex, this); |
251 | 68 | } |
252 | |
|
253 | 68 | } |
254 | |
|
255 | |
protected void doDispose() |
256 | |
{ |
257 | |
|
258 | 66 | } |
259 | |
|
260 | |
protected void doConnect() throws Exception |
261 | |
{ |
262 | |
|
263 | 52 | } |
264 | |
|
265 | |
protected void doDisconnect() throws Exception |
266 | |
{ |
267 | |
|
268 | 52 | } |
269 | |
|
270 | |
protected void doStart() throws UMOException |
271 | |
{ |
272 | |
|
273 | 52 | } |
274 | |
|
275 | |
protected void doStop() throws UMOException |
276 | |
{ |
277 | |
|
278 | 52 | } |
279 | |
|
280 | |
public XFire getXfire() |
281 | |
{ |
282 | 220 | return xfire; |
283 | |
} |
284 | |
|
285 | |
public void setXfire(XFire xfire) |
286 | |
{ |
287 | 0 | this.xfire = xfire; |
288 | 0 | } |
289 | |
|
290 | |
protected void registerReceiverWithMuleService(UMOMessageReceiver receiver, UMOEndpointURI ep) |
291 | |
throws UMOException |
292 | |
{ |
293 | |
|
294 | |
|
295 | |
|
296 | 84 | if (xfireDescriptor == null) |
297 | |
{ |
298 | |
|
299 | |
|
300 | |
|
301 | 44 | xfireDescriptor = (MuleDescriptor)MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL).getDescriptor( |
302 | |
XFIRE_SERVICE_COMPONENT_NAME + getName()); |
303 | 44 | if (xfireDescriptor == null) |
304 | |
{ |
305 | 44 | xfireDescriptor = createxfireDescriptor(); |
306 | |
} |
307 | |
else |
308 | |
{ |
309 | |
|
310 | |
|
311 | |
|
312 | 0 | MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL).unregisterComponent(xfireDescriptor); |
313 | |
} |
314 | |
|
315 | |
|
316 | 44 | if (xfireDescriptor.getProperties().get(XFIRE_PROPERTY) == null) |
317 | |
{ |
318 | 44 | xfireDescriptor.getProperties().put(XFIRE_PROPERTY, xfire); |
319 | |
} |
320 | 44 | if (serviceTransport != null |
321 | |
&& xfireDescriptor.getProperties().get(XFIRE_TRANSPORT) == null) |
322 | |
{ |
323 | 0 | xfireDescriptor.getProperties().put(XFIRE_TRANSPORT, serviceTransport); |
324 | |
} |
325 | 44 | xfireDescriptor.setContainerManaged(false); |
326 | |
} |
327 | 84 | String serviceName = receiver.getComponent().getDescriptor().getName(); |
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | 84 | String endpoint = receiver.getEndpointURI().getAddress(); |
333 | 84 | String scheme = ep.getScheme().toLowerCase(); |
334 | |
|
335 | |
|
336 | 84 | boolean sync = receiver.getEndpoint().isSynchronous(); |
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | 84 | if (scheme.equals("http") || scheme.equals("https") || scheme.equals("ssl") |
342 | |
|| scheme.equals("tcp") || scheme.equals("servlet")) |
343 | |
{ |
344 | 84 | endpoint += "/" + serviceName; |
345 | 84 | receiver.getEndpoint().getProperties().put(HttpConnector.HTTP_METHOD_PROPERTY, "POST"); |
346 | 84 | receiver.getEndpoint().getProperties().put(HttpConstants.HEADER_CONTENT_TYPE, |
347 | |
"text/xml"); |
348 | |
|
349 | |
|
350 | |
|
351 | 84 | if (!receiver.getEndpoint().isSynchronousSet()) |
352 | |
{ |
353 | 74 | sync = true; |
354 | |
} |
355 | |
} |
356 | |
|
357 | |
|
358 | 84 | UMOEndpoint serviceEndpoint = new MuleEndpoint(endpoint, true); |
359 | 84 | serviceEndpoint.setSynchronous(sync); |
360 | 84 | serviceEndpoint.setName(ep.getScheme() + ":" + serviceName); |
361 | |
|
362 | |
|
363 | 84 | serviceEndpoint.setTransformer(receiver.getEndpoint().getTransformer()); |
364 | 84 | receiver.getEndpoint().setTransformer(null); |
365 | |
|
366 | 84 | serviceEndpoint.setResponseTransformer(receiver.getEndpoint().getResponseTransformer()); |
367 | 84 | receiver.getEndpoint().setResponseTransformer(null); |
368 | |
|
369 | |
|
370 | 84 | serviceEndpoint.setFilter(receiver.getEndpoint().getFilter()); |
371 | |
|
372 | 84 | receiver.getEndpoint().setFilter(null); |
373 | |
|
374 | |
|
375 | |
|
376 | 84 | serviceEndpoint.setSecurityFilter(receiver.getEndpoint().getSecurityFilter()); |
377 | |
|
378 | 84 | receiver.getEndpoint().setSecurityFilter(null); |
379 | 84 | xfireDescriptor.getInboundRouter().addEndpoint(serviceEndpoint); |
380 | 84 | } |
381 | |
|
382 | |
protected MuleDescriptor createxfireDescriptor() |
383 | |
{ |
384 | 44 | MuleDescriptor xfireDescriptor = (MuleDescriptor)MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL) |
385 | |
.getDescriptor(XFIRE_SERVICE_COMPONENT_NAME + getName()); |
386 | 44 | if (xfireDescriptor == null) |
387 | |
{ |
388 | 44 | xfireDescriptor = new MuleDescriptor(XFIRE_SERVICE_COMPONENT_NAME + getName()); |
389 | 46 | xfireDescriptor.setImplementation(XFireServiceComponent.class.getName()); |
390 | |
} |
391 | 44 | return xfireDescriptor; |
392 | |
} |
393 | |
|
394 | |
public ServiceFactory getServiceFactory() |
395 | |
{ |
396 | 86 | return serviceFactory; |
397 | |
} |
398 | |
|
399 | |
public void setServiceFactory(ServiceFactory serviceFactory) |
400 | |
{ |
401 | 0 | this.serviceFactory = serviceFactory; |
402 | 0 | } |
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint) |
413 | |
{ |
414 | 426 | if (endpoint.getEndpointURI().getPort() == -1) |
415 | |
{ |
416 | 20 | return component.getDescriptor().getName(); |
417 | |
} |
418 | |
else |
419 | |
{ |
420 | 406 | return endpoint.getEndpointURI().getAddress() + "/" |
421 | |
+ component.getDescriptor().getName(); |
422 | |
} |
423 | |
} |
424 | |
|
425 | |
public boolean isEnableJSR181Annotations() |
426 | |
{ |
427 | 86 | return enableJSR181Annotations; |
428 | |
} |
429 | |
|
430 | |
public void setEnableJSR181Annotations(boolean enableJSR181Annotations) |
431 | |
{ |
432 | 0 | this.enableJSR181Annotations = enableJSR181Annotations; |
433 | 0 | } |
434 | |
|
435 | |
public List getClientServices() |
436 | |
{ |
437 | 0 | return clientServices; |
438 | |
} |
439 | |
|
440 | |
public void setClientServices(List clientServices) |
441 | |
{ |
442 | 2 | this.clientServices = clientServices; |
443 | 2 | } |
444 | |
|
445 | |
public List getClientInHandlers() |
446 | |
{ |
447 | 38 | return clientInHandlers; |
448 | |
} |
449 | |
|
450 | |
public void setClientInHandlers(List handlers) |
451 | |
{ |
452 | 0 | clientInHandlers = handlers; |
453 | 0 | } |
454 | |
|
455 | |
public List getClientOutHandlers() |
456 | |
{ |
457 | 38 | return clientOutHandlers; |
458 | |
} |
459 | |
|
460 | |
public void setClientOutHandlers(List handlers) |
461 | |
{ |
462 | 0 | clientOutHandlers = handlers; |
463 | 0 | } |
464 | |
|
465 | |
public String getClientTransport() |
466 | |
{ |
467 | 32 | return clientTransport; |
468 | |
} |
469 | |
|
470 | |
public void setClientTransport(String transportClass) |
471 | |
{ |
472 | 0 | clientTransport = transportClass; |
473 | 0 | } |
474 | |
|
475 | |
public String getServiceTransport() |
476 | |
{ |
477 | 0 | return serviceTransport; |
478 | |
} |
479 | |
|
480 | |
public void setServiceTransport(String transportClass) |
481 | |
{ |
482 | 0 | serviceTransport = transportClass; |
483 | 0 | } |
484 | |
|
485 | |
public String getBindingProvider() |
486 | |
{ |
487 | 0 | return bindingProvider; |
488 | |
} |
489 | |
|
490 | |
public void setBindingProvider(String bindingProvider) |
491 | |
{ |
492 | 0 | this.bindingProvider = bindingProvider; |
493 | 0 | } |
494 | |
|
495 | |
public String getTypeMappingRegistry() |
496 | |
{ |
497 | 0 | return typeMappingRegistry; |
498 | |
} |
499 | |
|
500 | |
public void setTypeMappingRegistry(String typeMappingRegistry) |
501 | |
{ |
502 | 0 | this.typeMappingRegistry = typeMappingRegistry; |
503 | 0 | } |
504 | |
|
505 | |
public void onNotification(UMOServerNotification event) |
506 | |
{ |
507 | 682 | if (event.getAction() == ManagerNotification.MANAGER_STARTED_MODELS) |
508 | |
{ |
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | 44 | if (!MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL).isComponentRegistered( |
519 | |
XFIRE_SERVICE_COMPONENT_NAME + getName())) |
520 | |
{ |
521 | |
try |
522 | |
{ |
523 | |
|
524 | |
|
525 | 44 | if (xfireDescriptor == null) |
526 | |
{ |
527 | 0 | xfireDescriptor = createxfireDescriptor(); |
528 | |
} |
529 | 44 | xfireDescriptor.addInterceptor(new MethodFixInterceptor()); |
530 | |
|
531 | 44 | if (xfireDescriptor.getProperties().get("xfire") == null) |
532 | |
{ |
533 | 0 | xfireDescriptor.getProperties().put("xfire", xfire); |
534 | |
} |
535 | 44 | MuleManager.getInstance().lookupModel(ModelHelper.SYSTEM_MODEL).registerComponent(xfireDescriptor); |
536 | |
} |
537 | 0 | catch (UMOException e) |
538 | |
{ |
539 | 0 | handleException(e); |
540 | 44 | } |
541 | |
} |
542 | |
} |
543 | 682 | } |
544 | |
|
545 | |
public List getServerInHandlers() |
546 | |
{ |
547 | 118 | return serverInHandlers; |
548 | |
} |
549 | |
|
550 | |
public void setServerInHandlers(List serverInHandlers) |
551 | |
{ |
552 | 0 | this.serverInHandlers = serverInHandlers; |
553 | 0 | } |
554 | |
|
555 | |
public List getServerOutHandlers() |
556 | |
{ |
557 | 32 | return serverOutHandlers; |
558 | |
} |
559 | |
|
560 | |
public void setServerOutHandlers(List serverOutHandlers) |
561 | |
{ |
562 | 0 | this.serverOutHandlers = serverOutHandlers; |
563 | 0 | } |
564 | |
|
565 | |
public Map getExtraProperties() |
566 | |
{ |
567 | 38 | return extraProperties; |
568 | |
} |
569 | |
|
570 | |
public void setExtraProperties(Map extraProperties) |
571 | |
{ |
572 | 0 | if (this.extraProperties != null) |
573 | |
{ |
574 | 0 | this.extraProperties.putAll(extraProperties); |
575 | |
} |
576 | |
else |
577 | |
{ |
578 | 0 | this.extraProperties = extraProperties; |
579 | |
} |
580 | 0 | } |
581 | |
} |