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