Coverage Report - org.mule.module.spring.remoting.SpringRemoteInvokerComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringRemoteInvokerComponent
0%
0/43
0%
0/12
1.733
SpringRemoteInvokerComponent$1
N/A
N/A
1.733
SpringRemoteInvokerComponent$Delegate
0%
0/7
N/A
1.733
 
 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.module.spring.remoting;
 8  
 
 9  
 import org.mule.api.MuleEventContext;
 10  
 import org.mule.api.lifecycle.Callable;
 11  
 import org.mule.api.lifecycle.Initialisable;
 12  
 import org.mule.api.lifecycle.InitialisationException;
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.util.ClassUtils;
 15  
 
 16  
 import org.springframework.beans.factory.InitializingBean;
 17  
 import org.springframework.remoting.support.RemoteInvocation;
 18  
 import org.springframework.remoting.support.RemoteInvocationBasedExporter;
 19  
 import org.springframework.remoting.support.RemoteInvocationExecutor;
 20  
 import org.springframework.remoting.support.RemoteInvocationResult;
 21  
 
 22  
 public class SpringRemoteInvokerComponent implements Initialisable, Callable
 23  
 {
 24  
     private Delegate delegate;
 25  
     private Class serviceClass;
 26  
     private Class serviceInterface;
 27  
     private Object serviceBean;
 28  0
     private boolean registerTraceInterceptor = false;
 29  
     private RemoteInvocationExecutor remoteInvocationExecutor;
 30  
 
 31  0
     private class Delegate extends RemoteInvocationBasedExporter implements InitializingBean
 32  
     {
 33  
         private Object proxy;
 34  
 
 35  
         public void afterPropertiesSet()
 36  
         {
 37  0
             this.proxy = getProxyForService();
 38  0
         }
 39  
 
 40  
         public Object execute(RemoteInvocation invocation)
 41  
         {
 42  
             try
 43  
             {
 44  0
                 Object value = invoke(invocation, proxy);
 45  0
                 return value;
 46  
             }
 47  0
             catch (Throwable ex)
 48  
             {
 49  0
                 return new RemoteInvocationResult(ex);
 50  
             }
 51  
         }
 52  
     }
 53  
 
 54  
     public SpringRemoteInvokerComponent()
 55  0
     {
 56  0
         delegate = new Delegate();
 57  0
     }
 58  
 
 59  
     public void initialise() throws InitialisationException
 60  
     {
 61  0
         if (serviceClass == null && serviceBean == null)
 62  
         {
 63  0
             throw new InitialisationException(CoreMessages.propertiesNotSet("serviceClass or serviceBean"),
 64  
                 this);
 65  
         }
 66  0
         if (serviceInterface == null)
 67  
         {
 68  0
             throw new InitialisationException(CoreMessages.propertiesNotSet("serviceInterface"), this);
 69  
         }
 70  
 
 71  0
         if (serviceClass != null)
 72  
         {
 73  0
             Object service = null;
 74  
             try
 75  
             {
 76  0
                 service = ClassUtils.instanciateClass(serviceClass, (Object[]) null);
 77  
             }
 78  0
             catch (Exception e)
 79  
             {
 80  0
                 throw new InitialisationException(e, this);
 81  0
             }
 82  0
             delegate.setService(service);
 83  0
         }
 84  0
         else if (serviceBean != null)
 85  
         {
 86  0
             delegate.setService(serviceBean);
 87  
         }
 88  0
         delegate.setServiceInterface(serviceInterface);
 89  0
         delegate.setRegisterTraceInterceptor(registerTraceInterceptor);
 90  0
         if (remoteInvocationExecutor != null)
 91  
         {
 92  0
             delegate.setRemoteInvocationExecutor(remoteInvocationExecutor);
 93  
         }
 94  0
         delegate.afterPropertiesSet();
 95  0
     }
 96  
 
 97  
     public Class getServiceClass()
 98  
     {
 99  0
         return serviceClass;
 100  
     }
 101  
 
 102  
     public void setServiceClass(Class serviceClass)
 103  
     {
 104  0
         this.serviceClass = serviceClass;
 105  0
     }
 106  
 
 107  
     public Object getServiceBean()
 108  
     {
 109  0
         return serviceBean;
 110  
     }
 111  
 
 112  
     public void setServiceBean(Object serviceBean)
 113  
     {
 114  0
         this.serviceBean = serviceBean;
 115  0
     }
 116  
 
 117  
     public Class getServiceInterface()
 118  
     {
 119  0
         return serviceInterface;
 120  
     }
 121  
 
 122  
     public void setServiceInterface(Class serviceInterface)
 123  
     {
 124  0
         this.serviceInterface = serviceInterface;
 125  0
     }
 126  
 
 127  
     public boolean isRegisterTraceInterceptor()
 128  
     {
 129  0
         return registerTraceInterceptor;
 130  
     }
 131  
 
 132  
     public void setRegisterTraceInterceptor(boolean registerTraceInterceptor)
 133  
     {
 134  0
         this.registerTraceInterceptor = registerTraceInterceptor;
 135  0
     }
 136  
 
 137  
     public RemoteInvocationExecutor getRemoteInvocationExecutor()
 138  
     {
 139  0
         return remoteInvocationExecutor;
 140  
     }
 141  
 
 142  
     public void setRemoteInvocationExecutor(RemoteInvocationExecutor remoteInvocationExecutor)
 143  
     {
 144  0
         this.remoteInvocationExecutor = remoteInvocationExecutor;
 145  0
     }
 146  
 
 147  
     public Object onCall(MuleEventContext eventContext) throws Exception
 148  
     {
 149  0
         Object payload = eventContext.getMessage().getPayload();
 150  0
         RemoteInvocation ri = (RemoteInvocation) payload;
 151  0
         Object rval = delegate.execute(ri);
 152  0
         return rval;
 153  
     }
 154  
 }