Coverage Report - org.mule.providers.soap.axis.AxisServiceProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
AxisServiceProxy
60%
3/5
N/A
2.5
AxisServiceProxy$AxisServiceHandler
89%
16/18
67%
4/6
2.5
 
 1  
 /*
 2  
  * $Id: AxisServiceProxy.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;
 12  
 
 13  
 import org.mule.config.ExceptionHelper;
 14  
 import org.mule.config.MuleProperties;
 15  
 import org.mule.impl.MuleMessage;
 16  
 import org.mule.impl.RequestContext;
 17  
 import org.mule.providers.AbstractMessageReceiver;
 18  
 import org.mule.providers.soap.ServiceProxy;
 19  
 import org.mule.providers.soap.axis.extras.AxisCleanAndAddProperties;
 20  
 import org.mule.umo.UMOException;
 21  
 import org.mule.umo.UMOExceptionPayload;
 22  
 import org.mule.umo.UMOMessage;
 23  
 import org.mule.umo.provider.UMOMessageAdapter;
 24  
 
 25  
 import java.lang.reflect.InvocationHandler;
 26  
 import java.lang.reflect.Method;
 27  
 import java.lang.reflect.Proxy;
 28  
 
 29  
 /**
 30  
  * <code>ServiceProxy</code> is a proxy that wraps a soap endpointUri to look like
 31  
  * a Web service. Also provides helper methods for building and describing web
 32  
  * service interfaces in Mule.
 33  
  */
 34  
 
 35  0
 public class AxisServiceProxy extends ServiceProxy
 36  
 {
 37  
 
 38  
     public static Object createProxy(AbstractMessageReceiver receiver, boolean synchronous, Class[] classes)
 39  
     {
 40  160
         final ClassLoader cl = Thread.currentThread().getContextClassLoader();
 41  160
         return Proxy.newProxyInstance(cl, classes, createServiceHandler(receiver, synchronous));
 42  
     }
 43  
 
 44  
     public static InvocationHandler createServiceHandler(AbstractMessageReceiver receiver, boolean synchronous)
 45  
     {
 46  160
         return new AxisServiceHandler(receiver, synchronous);
 47  
     }
 48  
 
 49  0
     private static class AxisServiceHandler implements InvocationHandler
 50  
     {
 51  
         private AbstractMessageReceiver receiver;
 52  160
         private boolean synchronous = true;
 53  
 
 54  
         public AxisServiceHandler(AbstractMessageReceiver receiver, boolean synchronous)
 55  160
         {
 56  160
             this.receiver = receiver;
 57  160
             this.synchronous = synchronous;
 58  160
         }
 59  
 
 60  
         public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
 61  
         {
 62  160
             UMOMessageAdapter messageAdapter = receiver.getConnector().getMessageAdapter(args);
 63  160
             messageAdapter.setProperty(MuleProperties.MULE_METHOD_PROPERTY, method);
 64  
             
 65  
             // add all custom headers, filter out all mule headers (such as
 66  
             // MULE_SESSION) except
 67  
             // for MULE_USER header. Filter out other headers like "soapMethods" and
 68  
             // MuleProperties.MULE_METHOD_PROPERTY and "soapAction"
 69  
             // and also filter out any http related header
 70  160
             messageAdapter.addProperties(AxisCleanAndAddProperties.cleanAndAdd(RequestContext.getEventContext()));                        
 71  
                                    
 72  160
             UMOMessage message = receiver.routeMessage(new MuleMessage(messageAdapter), synchronous);
 73  
             
 74  160
             if (message != null)
 75  
             {
 76  160
                 UMOExceptionPayload wsException = message.getExceptionPayload();
 77  
 
 78  160
                 if (wsException != null)
 79  
                 {
 80  10
                     UMOException umoException = ExceptionHelper.getRootMuleException(wsException.getException());
 81  
                     // if the exception has a cause, then throw only the cause
 82  10
                     if (umoException.getCause() != null)
 83  
                     {
 84  10
                         throw umoException.getCause();
 85  
                     }
 86  
                     else
 87  
                     {
 88  0
                         throw umoException;
 89  
                     }
 90  
                 }
 91  
 
 92  150
                 return message.getPayload();
 93  
             }
 94  
             else
 95  
             {
 96  0
                 return null;
 97  
             }
 98  
         }
 99  
     }
 100  
 }