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