Coverage Report - org.mule.providers.soap.axis.extensions.MuleMsgProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleMsgProvider
45%
22/49
25%
5/20
4.4
 
 1  
 /*
 2  
  * $Id: MuleMsgProvider.java 7963 2007-08-21 08:53:15Z 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.axis.extensions;
 12  
 
 13  
 import org.mule.impl.RequestContext;
 14  
 import org.mule.impl.model.ModelHelper;
 15  
 import org.mule.providers.soap.ServiceProxy;
 16  
 import org.mule.providers.soap.axis.AxisConnector;
 17  
 import org.mule.providers.soap.axis.AxisMessageReceiver;
 18  
 import org.mule.providers.soap.axis.AxisServiceProxy;
 19  
 import org.mule.umo.UMOComponent;
 20  
 
 21  
 import java.lang.reflect.Proxy;
 22  
 
 23  
 import org.apache.axis.AxisFault;
 24  
 import org.apache.axis.Constants;
 25  
 import org.apache.axis.MessageContext;
 26  
 import org.apache.axis.description.OperationDesc;
 27  
 import org.apache.axis.handlers.soap.SOAPService;
 28  
 import org.apache.axis.providers.java.MsgProvider;
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 
 32  
 /**
 33  
  * <code>MuleMsgProvider</code> is an Axis service endpoint that builds services
 34  
  * from Mule managed components.
 35  
  */
 36  
 public class MuleMsgProvider extends MsgProvider
 37  
 {
 38  
     /**
 39  
      * Serial version
 40  
      */
 41  
     private static final long serialVersionUID = -4399291846942449361L;
 42  
 
 43  
     private AxisConnector connector;
 44  
 
 45  4
     private static Log logger = LogFactory.getLog(MuleMsgProvider.class);
 46  
 
 47  4
     private String METHOD_BODYARRAY = "soapbodyelement";
 48  4
     private String METHOD_ELEMENTARRAY = "element";
 49  4
     private String METHOD_DOCUMENT = "document";
 50  
 
 51  
     public MuleMsgProvider(AxisConnector connector)
 52  4
     {
 53  4
         this.connector = connector;
 54  4
     }
 55  
 
 56  
     protected Object makeNewServiceObject(MessageContext messageContext, String s) throws Exception
 57  
     {
 58  52
         String transUrl = (String)messageContext.getProperty("transport.url");
 59  52
         int i = transUrl.indexOf('?');
 60  52
         if (i > -1)
 61  
         {
 62  12
             transUrl = transUrl.substring(0, i);
 63  
         }
 64  52
         AxisMessageReceiver receiver = (AxisMessageReceiver)connector.lookupReceiver(transUrl);
 65  52
         if (receiver == null)
 66  
         {
 67  0
             receiver = (AxisMessageReceiver)connector.lookupReceiver(messageContext.getTargetService());
 68  
         }
 69  52
         if (receiver == null)
 70  
         {
 71  0
             throw new AxisFault("Could not find Mule registered service: " + s);
 72  
         }
 73  52
         Class[] classes = ServiceProxy.getInterfacesForComponent(receiver.getComponent());
 74  52
         return AxisServiceProxy.createProxy(receiver, true, classes);
 75  
     }
 76  
 
 77  
     protected Class getServiceClass(String s, SOAPService soapService, MessageContext messageContext)
 78  
         throws AxisFault
 79  
     {
 80  4
         UMOComponent component = ModelHelper.getComponent(soapService.getName());
 81  
         try
 82  
         {
 83  4
             Class[] classes = ServiceProxy.getInterfacesForComponent(component);
 84  4
             return Proxy.getProxyClass(Thread.currentThread().getContextClassLoader(), classes);
 85  
         }
 86  0
         catch (Exception e)
 87  
         {
 88  0
             throw new AxisFault("Failed to implementation class for component: " + e.getMessage(), e);
 89  
         }
 90  
     }
 91  
 
 92  
     /**
 93  
      * @param msgContext
 94  
      * @deprecated I dont think this is necessary, but leaving it here for a while
 95  
      */
 96  
     protected void setOperationStyle(MessageContext msgContext)
 97  
     {
 98  
         /*
 99  
          * Axis requires that the OperationDesc.operationStyle be set to match the
 100  
          * method signature This does not appear to be an automated process so
 101  
          * determine from the 4 allowed forms public Element [] method(Element []
 102  
          * bodies); public SOAPBodyElement [] method (SOAPBodyElement [] bodies);
 103  
          * public Document method(Document body); public void method(SOAPEnvelope
 104  
          * req, SOAPEnvelope resp);
 105  
          */
 106  0
         int methodType = msgContext.getOperation().getMessageOperationStyle();
 107  0
         if (methodType > -1)
 108  
         {
 109  
             // Already set, nothing more to do
 110  0
             return;
 111  
         }
 112  0
         OperationDesc operation = msgContext.getOperation();
 113  0
         String methodSignature = operation.getMethod().toString().toLowerCase();
 114  0
         if (methodSignature.indexOf(METHOD_BODYARRAY) != -1)
 115  
         {
 116  0
             methodType = OperationDesc.MSG_METHOD_BODYARRAY;
 117  
         }
 118  0
         else if (methodSignature.indexOf(METHOD_ELEMENTARRAY) != -1)
 119  
         {
 120  0
             methodType = OperationDesc.MSG_METHOD_ELEMENTARRAY;
 121  
         }
 122  0
         else if (methodSignature.indexOf(METHOD_DOCUMENT) != -1)
 123  
         {
 124  0
             methodType = OperationDesc.MSG_METHOD_DOCUMENT;
 125  
         }
 126  
         else
 127  
         {
 128  0
             methodType = OperationDesc.MSG_METHOD_SOAPENVELOPE;
 129  
         }
 130  0
         operation.setMessageOperationStyle(methodType);
 131  0
         logger.debug("Now Invoking service (Method Format) " + operation.getMethod().toString());
 132  0
         logger.debug("Now Invoking service (MethodType) "
 133  
                      + String.valueOf(operation.getMessageOperationStyle()));
 134  0
     }
 135  
 
 136  
     public void invoke(MessageContext msgContext) throws AxisFault
 137  
     {
 138  
         // Make sure that the method style is correctly set (This does not appear to
 139  
         // be handled by default)
 140  
         // setOperationStyle(msgContext);
 141  52
         super.invoke(msgContext);
 142  52
         if (RequestContext.getExceptionPayload() != null)
 143  
         {
 144  0
             Throwable t = RequestContext.getExceptionPayload().getException();
 145  0
             if (t instanceof Exception)
 146  
             {
 147  0
                 AxisFault fault = AxisFault.makeFault((Exception)t);
 148  0
                 if (t instanceof RuntimeException)
 149  
                 {
 150  0
                     fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION, "true");
 151  
                 }
 152  0
                 throw fault;
 153  
             }
 154  
             else
 155  
             {
 156  0
                 throw (Error)t;
 157  
             }
 158  
         }
 159  52
     }
 160  
 
 161  
 }