1 10 11 package org.mule.providers.soap.xfire; 12 13 import java.util.List ; 14 15 import org.codehaus.xfire.DefaultXFire; 16 import org.codehaus.xfire.XFire; 17 import org.codehaus.xfire.annotations.AnnotationServiceFactory; 18 import org.codehaus.xfire.annotations.WebAnnotations; 19 import org.codehaus.xfire.service.Service; 20 import org.codehaus.xfire.service.ServiceFactory; 21 import org.codehaus.xfire.service.binding.ObjectServiceFactory; 22 import org.mule.MuleManager; 23 import org.mule.config.i18n.Message; 24 import org.mule.impl.MuleDescriptor; 25 import org.mule.impl.endpoint.MuleEndpoint; 26 import org.mule.impl.internal.notifications.ModelNotification; 27 import org.mule.impl.internal.notifications.ModelNotificationListener; 28 import org.mule.impl.internal.notifications.NotificationException; 29 import org.mule.providers.AbstractServiceEnabledConnector; 30 import org.mule.providers.soap.MethodFixInterceptor; 31 import org.mule.providers.http.HttpConnector; 32 import org.mule.providers.http.HttpConstants; 33 import org.mule.umo.UMOComponent; 34 import org.mule.umo.UMOException; 35 import org.mule.umo.endpoint.UMOEndpoint; 36 import org.mule.umo.endpoint.UMOEndpointURI; 37 import org.mule.umo.lifecycle.InitialisationException; 38 import org.mule.umo.manager.UMOServerNotification; 39 import org.mule.umo.provider.UMOMessageReceiver; 40 import org.mule.util.ClassUtils; 41 import org.mule.util.SystemUtils; 42 43 46 public class XFireConnector extends AbstractServiceEnabledConnector 47 implements ModelNotificationListener 48 { 49 public static final String XFIRE_SERVICE_COMPONENT_NAME = "_xfireServiceComponent"; 50 public static final String DEFAULT_MULE_NAMESPACE_URI = "http://www.muleumo.org"; 51 public static final String XFIRE_PROPERTY = "xfire"; 52 public static final String XFIRE_TRANSPORT = "transportClass"; 53 54 private static final String CLASSNAME_ANNOTATIONS = "org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations"; 55 56 protected MuleDescriptor xfireDescriptor; 57 58 private XFire xfire; 59 60 private ServiceFactory serviceFactory; 61 62 private boolean enableJSR181Annotations = false; 63 64 private List clientServices = null; 65 private List clientInHandlers = null; 66 private List clientOutHandlers = null; 67 private String clientTransport = null; 68 69 private String serviceTransport = null; 70 private List serverInHandlers = null; 71 private List serverOutHandlers = null; 72 73 public XFireConnector() 74 { 75 super(); 76 registerProtocols(); 77 } 78 79 protected void registerProtocols() 80 { 81 registerSupportedProtocol("http"); 82 registerSupportedProtocol("https"); 83 registerSupportedProtocol("jms"); 84 registerSupportedProtocol("vm"); 85 registerSupportedProtocol("servlet"); 86 } 87 88 public String getProtocol() 89 { 90 return "xfire"; 91 } 92 93 public void doInitialise() throws InitialisationException 94 { 95 super.doInitialise(); 96 try 97 { 98 MuleManager.getInstance().registerListener(this); 99 } 100 catch (NotificationException e) 101 { 102 throw new InitialisationException(e, this); 103 } 104 105 if (xfire == null) 106 { 107 xfire = new DefaultXFire(); 108 } 109 110 if (clientServices != null) 111 { 112 ObjectServiceFactory factory = new ObjectServiceFactory(); 113 for (int i = 0; i < clientServices.size(); i++) 114 { 115 try 116 { 117 Class clazz = Class.forName(clientServices.get(i).toString()); 118 Service service = factory.create(clazz); 119 xfire.getServiceRegistry().register(service); 120 } 121 catch (ClassNotFoundException e) 122 { 123 throw new InitialisationException(new Message("xfire", 10, clientServices 124 .get(i)), e, this); 125 } 126 } 127 } 128 129 if (serviceFactory == null) 130 { 131 if (enableJSR181Annotations) 132 { 133 if (!SystemUtils.isJavaVersionAtLeast(150)) 135 { 136 throw new InitialisationException(new Message("xfire", 9), this); 137 } 138 try 139 { 140 WebAnnotations wa = (WebAnnotations)ClassUtils.instanciateClass( 141 CLASSNAME_ANNOTATIONS, null, this.getClass()); 142 serviceFactory = new AnnotationServiceFactory(wa, xfire.getTransportManager()); 143 } 144 catch (Exception ex) 145 { 146 throw new InitialisationException(new Message("xfire", 10, 147 CLASSNAME_ANNOTATIONS), ex, this); 148 } 149 } 150 else 151 { 152 serviceFactory = new MuleObjectServiceFactory(xfire.getTransportManager()); 153 } 154 } 155 if (serviceFactory instanceof ObjectServiceFactory) 156 { 157 ObjectServiceFactory osf = (ObjectServiceFactory)serviceFactory; 158 if (osf.getTransportManager() == null) 159 { 160 osf.setTransportManager(xfire.getTransportManager()); 161 } 162 } 163 } 164 165 public XFire getXfire() 166 { 167 return xfire; 168 } 169 170 public void setXfire(XFire xfire) 171 { 172 this.xfire = xfire; 173 } 174 175 protected void registerReceiverWithMuleService(UMOMessageReceiver receiver, UMOEndpointURI ep) 176 throws UMOException 177 { 178 if (xfireDescriptor == null) 182 { 183 xfireDescriptor = (MuleDescriptor)MuleManager.getInstance().getModel().getDescriptor( 187 XFIRE_SERVICE_COMPONENT_NAME + getName()); 188 if (xfireDescriptor == null) 189 { 190 xfireDescriptor = createxfireDescriptor(); 191 } 192 else 193 { 194 MuleManager.getInstance().getModel().unregisterComponent(xfireDescriptor); 198 } 199 if (xfireDescriptor.getProperties().get(XFIRE_PROPERTY) == null) 202 { 203 xfireDescriptor.getProperties().put(XFIRE_PROPERTY, xfire); 204 } 205 if (serviceTransport != null 206 && xfireDescriptor.getProperties().get(XFIRE_TRANSPORT) == null) 207 { 208 xfireDescriptor.getProperties().put(XFIRE_TRANSPORT, serviceTransport); 209 } 210 xfireDescriptor.setContainerManaged(false); 211 } 212 String serviceName = receiver.getComponent().getDescriptor().getName(); 213 214 String endpoint = receiver.getEndpointURI().getAddress(); 218 String scheme = ep.getScheme().toLowerCase(); 219 220 boolean sync = false; 223 if (!receiver.getEndpoint().isSynchronousSet()) 224 { 225 if (scheme.equals("http") || scheme.equals("https") || scheme.equals("ssl") 226 || scheme.equals("tcp")) 227 { 228 sync = true; 229 } 230 } 231 else 232 { 233 sync = receiver.getEndpoint().isSynchronous(); 234 } 235 236 if (scheme.equals("http") || scheme.equals("https") || scheme.equals("ssl") 240 || scheme.equals("tcp") || scheme.equals("servlet")) 241 { 242 endpoint += "/" + serviceName; 243 receiver.getEndpoint().getProperties().put(HttpConnector.HTTP_METHOD_PROPERTY, "POST"); 244 receiver.getEndpoint().getProperties().put(HttpConstants.HEADER_CONTENT_TYPE, 245 "text/xml"); 246 } 247 248 UMOEndpoint serviceEndpoint = new MuleEndpoint(endpoint, true); 249 serviceEndpoint.setSynchronous(sync); 250 serviceEndpoint.setName(ep.getScheme() + ":" + serviceName); 251 252 serviceEndpoint.setTransformer(receiver.getEndpoint().getTransformer()); 254 receiver.getEndpoint().setTransformer(null); 255 256 serviceEndpoint.setResponseTransformer(receiver.getEndpoint().getResponseTransformer()); 257 receiver.getEndpoint().setResponseTransformer(null); 258 259 serviceEndpoint.setFilter(receiver.getEndpoint().getFilter()); 261 receiver.getEndpoint().setFilter(null); 263 264 serviceEndpoint.setSecurityFilter(receiver.getEndpoint().getSecurityFilter()); 267 receiver.getEndpoint().setSecurityFilter(null); 269 xfireDescriptor.getInboundRouter().addEndpoint(serviceEndpoint); 270 } 271 272 protected MuleDescriptor createxfireDescriptor() 273 { 274 MuleDescriptor xfireDescriptor = (MuleDescriptor)MuleManager.getInstance().getModel() 275 .getDescriptor(XFIRE_SERVICE_COMPONENT_NAME + getName()); 276 if (xfireDescriptor == null) 277 { 278 xfireDescriptor = new MuleDescriptor(XFIRE_SERVICE_COMPONENT_NAME + getName()); 279 xfireDescriptor.setImplementation(XFireServiceComponent.class.getName()); 280 } 281 return xfireDescriptor; 282 } 283 284 public ServiceFactory getServiceFactory() 285 { 286 return serviceFactory; 287 } 288 289 public void setServiceFactory(ObjectServiceFactory serviceFactory) 290 { 291 this.serviceFactory = serviceFactory; 292 } 293 294 302 protected Object getReceiverKey(UMOComponent component, UMOEndpoint endpoint) 303 { 304 if (endpoint.getEndpointURI().getPort() == -1) 305 { 306 return component.getDescriptor().getName(); 307 } 308 else 309 { 310 return endpoint.getEndpointURI().getAddress() + "/" 311 + component.getDescriptor().getName(); 312 } 313 } 314 315 public boolean isEnableJSR181Annotations() 316 { 317 return enableJSR181Annotations; 318 } 319 320 public void setEnableJSR181Annotations(boolean enableJSR181Annotations) 321 { 322 this.enableJSR181Annotations = enableJSR181Annotations; 323 } 324 325 public List getClientServices() 326 { 327 return clientServices; 328 } 329 330 public void setClientServices(List clientServices) 331 { 332 this.clientServices = clientServices; 333 } 334 335 public List getClientInHandlers() 336 { 337 return clientInHandlers; 338 } 339 340 public void setClientInHandlers(List handlers) 341 { 342 clientInHandlers = handlers; 343 } 344 345 public List getClientOutHandlers() 346 { 347 return clientOutHandlers; 348 } 349 350 public void setClientOutHandlers(List handlers) 351 { 352 clientOutHandlers = handlers; 353 } 354 355 public String getClientTransport() 356 { 357 return clientTransport; 358 } 359 360 public void setClientTransport(String transportClass) 361 { 362 clientTransport = transportClass; 363 } 364 365 public String getServiceTransport() 366 { 367 return serviceTransport; 368 } 369 370 public void setServiceTransport(String transportClass) 371 { 372 serviceTransport = transportClass; 373 } 374 375 public void onNotification(UMOServerNotification event) 376 { 377 if (event.getAction() == ModelNotification.MODEL_STARTED) 378 { 379 if (!MuleManager.getInstance().getModel().isComponentRegistered( 389 XFIRE_SERVICE_COMPONENT_NAME + getName())) 390 { 391 try 392 { 393 if (xfireDescriptor == null) 396 { 397 xfireDescriptor = createxfireDescriptor(); 398 } 399 xfireDescriptor.addInterceptor(new MethodFixInterceptor()); 400 401 if (xfireDescriptor.getProperties().get("xfire") == null) 402 { 403 xfireDescriptor.getProperties().put("xfire", xfire); 404 } 405 MuleManager.getInstance().getModel().registerComponent(xfireDescriptor); 406 } 407 catch (UMOException e) 408 { 409 handleException(e); 410 } 411 } 412 } 413 } 414 415 public List getServerInHandlers() 416 { 417 return serverInHandlers; 418 } 419 420 public void setServerInHandlers(List serverInHandlers) 421 { 422 this.serverInHandlers = serverInHandlers; 423 } 424 425 public List getServerOutHandlers() 426 { 427 return serverOutHandlers; 428 } 429 430 public void setServerOutHandlers(List serverOutHandlers) 431 { 432 this.serverOutHandlers = serverOutHandlers; 433 } 434 } 435 | Popular Tags |