Coverage Report - org.mule.providers.soap.xfire.XFireMessageReceiver
 
Classes in this File Line Coverage Branch Coverage Complexity
XFireMessageReceiver
0%
0/69
0%
0/11
3.375
 
 1  
 /*
 2  
  * $Id: XFireMessageReceiver.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.soap.xfire;
 12  
 
 13  
 import org.mule.providers.AbstractMessageReceiver;
 14  
 import org.mule.providers.soap.SoapConstants;
 15  
 import org.mule.umo.UMOComponent;
 16  
 import org.mule.umo.UMOException;
 17  
 import org.mule.umo.endpoint.UMOEndpoint;
 18  
 import org.mule.umo.lifecycle.InitialisationException;
 19  
 import org.mule.umo.provider.UMOConnector;
 20  
 import org.mule.util.ClassUtils;
 21  
 import org.mule.util.MapUtils;
 22  
 import org.mule.util.StringUtils;
 23  
 
 24  
 import java.net.MalformedURLException;
 25  
 import java.net.URL;
 26  
 import java.util.HashMap;
 27  
 import java.util.List;
 28  
 import java.util.Map;
 29  
 
 30  
 import javax.xml.namespace.QName;
 31  
 
 32  
 import org.codehaus.xfire.annotations.WebAnnotations;
 33  
 import org.codehaus.xfire.annotations.WebServiceAnnotation;
 34  
 import org.codehaus.xfire.handler.Handler;
 35  
 import org.codehaus.xfire.service.Service;
 36  
 
 37  
 /**
 38  
  * Used to register an Xfire endpoint registered with Mule and associated with a
 39  
  * component This receiver is responsible or registering the transport endpoint i.e.
 40  
  * http:// as well as managing the association of this transport endpoint with the
 41  
  * Xfire service.
 42  
  */
 43  
 public class XFireMessageReceiver extends AbstractMessageReceiver
 44  
 {
 45  
 
 46  
     protected XFireConnector connector;
 47  
     protected Service service;
 48  
 
 49  
     protected List serviceInterfaces;
 50  
 
 51  
     public XFireMessageReceiver(UMOConnector umoConnector,
 52  
                                 UMOComponent component,
 53  
                                 UMOEndpoint umoEndpoint) throws InitialisationException
 54  
     {
 55  0
         super(umoConnector, component, umoEndpoint);
 56  0
         connector = (XFireConnector)umoConnector;
 57  0
         init();
 58  0
     }
 59  
 
 60  
     protected void init() throws InitialisationException
 61  
     {
 62  
         try
 63  
         {
 64  0
             Map props = new HashMap(component.getDescriptor().getProperties());
 65  0
             props.putAll(endpoint.getProperties());
 66  
 
 67  
             // check if there is the namespace property on the component
 68  0
             String namespace = (String)component.getDescriptor().getProperties().get(
 69  
                 SoapConstants.SOAP_NAMESPACE_PROPERTY);
 70  
 
 71  
             // check for namespace set as annotation
 72  0
             if (connector.isEnableJSR181Annotations())
 73  
             {
 74  0
                 WebAnnotations wa = (WebAnnotations)ClassUtils.instanciateClass(
 75  
                     XFireConnector.CLASSNAME_ANNOTATIONS, null, this.getClass());
 76  0
                 WebServiceAnnotation webServiceAnnotation = wa.getWebServiceAnnotation(component
 77  
                     .getDescriptor().getImplementationClass());
 78  0
                 namespace = webServiceAnnotation.getTargetNamespace();
 79  
             }
 80  
 
 81  0
             if ((namespace == null) || (namespace.equalsIgnoreCase("")))
 82  
             {
 83  0
                 namespace = MapUtils.getString(props, "namespace",
 84  
                     XFireConnector.DEFAULT_MULE_NAMESPACE_URI);
 85  
             }
 86  
             
 87  
             //Convert createDefaultBindings string to boolean before rewriting as xfire property
 88  0
             if(props.get("createDefaultBindings")!=null){
 89  0
                     props.put("createDefaultBindings", Boolean.valueOf((String)props.get("createDefaultBindings")));  
 90  
             }
 91  
 
 92  0
             if (props.size() == 0)
 93  
             {
 94  
                 // Xfire checks that properties are null rather than empty
 95  0
                 props = null;
 96  
             }
 97  
             else
 98  
             {
 99  0
                 rewriteProperty(props, "portType");
 100  0
                 rewriteProperty(props, "style");
 101  0
                 rewriteProperty(props, "use");
 102  0
                 rewriteProperty(props, "createDefaultBindings");
 103  0
                 rewriteProperty(props, "soap12Transports");
 104  0
                 rewriteProperty(props, "soap11Transports");
 105  0
                 rewriteProperty(props, "scope");
 106  0
                 rewriteProperty(props, "schemas");
 107  
             }
 108  
 
 109  0
             serviceInterfaces = (List)component.getDescriptor().getProperties().get(
 110  
                 "serviceInterfaces");
 111  
             Class exposedInterface;
 112  
 
 113  0
             if (serviceInterfaces == null)
 114  0
                 exposedInterface = component.getDescriptor().getImplementationClass();
 115  
 
 116  
             else
 117  
             {
 118  0
                 String className = (String)serviceInterfaces.get(0);
 119  0
                 exposedInterface = ClassUtils.loadClass(className, this.getClass());
 120  0
                 logger.info(className + " class was used to expose your service");
 121  
 
 122  0
                 if (serviceInterfaces.size() > 1)
 123  
                 {
 124  0
                     logger.info("Only the first class was used to expose your method");
 125  
                 }
 126  
             }
 127  
 
 128  0
             String wsdlUrl = (String)component.getDescriptor().getProperties().get(
 129  
                 SoapConstants.WSDL_URL_PROPERTY);
 130  
 
 131  0
             if (StringUtils.isBlank(wsdlUrl))
 132  
             {
 133  0
                 service = connector.getServiceFactory().create(exposedInterface,
 134  
                     component.getDescriptor().getName(), namespace, props);
 135  
             }
 136  
             else
 137  
             {
 138  0
                 service = connector.getServiceFactory().create(exposedInterface,
 139  
                     new QName(namespace, component.getDescriptor().getName()), new URL(wsdlUrl),
 140  
                     props);
 141  
             }
 142  
 
 143  0
             List inList = connector.getServerInHandlers();
 144  0
             if (inList != null)
 145  
             {
 146  0
                 for (int i = 0; i < inList.size(); i++)
 147  
                 {
 148  0
                     Class clazz = ClassUtils.loadClass(inList.get(i).toString(), this.getClass());
 149  0
                     Handler handler = (Handler)clazz.getConstructor(null).newInstance(null);
 150  0
                     service.addInHandler(handler);
 151  
                 }
 152  
             }
 153  
 
 154  0
             boolean sync = endpoint.isSynchronous();
 155  
             // default to synchronous if using http
 156  0
             if (endpoint.getEndpointURI().getScheme().startsWith("http")
 157  
                 || endpoint.getEndpointURI().getScheme().startsWith("servlet"))
 158  
             {
 159  0
                 sync = true;
 160  
             }
 161  0
             service.setInvoker(new MuleInvoker(this, sync));
 162  
 
 163  
         }
 164  0
         catch (UMOException e)
 165  
         {
 166  0
             throw new InitialisationException(e, this);
 167  
         }
 168  0
         catch (ClassNotFoundException e)
 169  
         {
 170  
             // will be thrown in the case that the ClassUtils.loadClass() does
 171  
             // not find the class to load
 172  0
             throw new InitialisationException(e, this);
 173  
         }
 174  0
         catch (MalformedURLException e)
 175  
         {
 176  0
             throw new InitialisationException(e, this);
 177  
         }
 178  0
         catch (Exception e)
 179  
         {
 180  0
             throw new InitialisationException(e, this);
 181  0
         }
 182  0
     }
 183  
 
 184  
     protected void doDispose()
 185  
     {
 186  
         // template method
 187  0
     }
 188  
 
 189  
     public void doConnect() throws Exception
 190  
     {
 191  
         // Tell the Xfire registry about our new service.
 192  0
         connector.getXfire().getServiceRegistry().register(service);
 193  0
         connector.registerReceiverWithMuleService(this, endpoint.getEndpointURI());
 194  0
     }
 195  
 
 196  
     public void doDisconnect() throws Exception
 197  
     {
 198  0
         connector.getXfire().getServiceRegistry().unregister(service);
 199  0
     }
 200  
 
 201  
     public void doStart() throws UMOException
 202  
     {
 203  
         // nothing to do
 204  0
     }
 205  
 
 206  
     public void doStop() throws UMOException
 207  
     {
 208  
         // nothing to do
 209  0
     }
 210  
 
 211  
     protected void rewriteProperty(Map props, String name)
 212  
     {
 213  0
         if (props.containsKey(name))
 214  
         {
 215  0
             Object temp = props.remove(name);
 216  0
             props.put("objectServiceFactory." + name, temp);
 217  
         }
 218  0
     }
 219  
 
 220  
 }