Coverage Report - org.mule.transport.rmi.RmiMessageDispatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
RmiMessageDispatcher
0%
0/30
0%
0/12
2.143
 
 1  
 /*
 2  
  * $Id: RmiMessageDispatcher.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.rmi;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.api.endpoint.OutboundEndpoint;
 16  
 import org.mule.api.transformer.TransformerException;
 17  
 import org.mule.transport.AbstractMessageDispatcher;
 18  
 import org.mule.transport.NullPayload;
 19  
 
 20  
 import java.lang.reflect.Method;
 21  
 import java.rmi.RMISecurityManager;
 22  
 import java.rmi.Remote;
 23  
 
 24  
 /**
 25  
  * <code>RmiMessageDispatcher</code> will send transformed mule events over
 26  
  * RMI-JRMP.
 27  
  */
 28  
 public class RmiMessageDispatcher extends AbstractMessageDispatcher
 29  
 {
 30  
     private final RmiConnector connector;
 31  
     protected volatile Remote remoteObject;
 32  
     protected volatile Method invokedMethod;
 33  
 
 34  
     public RmiMessageDispatcher(OutboundEndpoint endpoint)
 35  
     {
 36  0
         super(endpoint);
 37  0
         this.connector = (RmiConnector)endpoint.getConnector();
 38  0
     }
 39  
 
 40  
     protected void doConnect() throws Exception
 41  
     {
 42  0
         if (remoteObject == null)
 43  
         {
 44  
             // Shouldn't all this be in the connector?
 45  0
             String rmiPolicyPath = connector.getSecurityPolicy();
 46  0
             System.setProperty("java.security.policy", rmiPolicyPath);
 47  
 
 48  
             // Set security manager
 49  0
             if (System.getSecurityManager() == null)
 50  
             {
 51  0
                 System.setSecurityManager(new RMISecurityManager());
 52  
             }
 53  
 
 54  0
             remoteObject = connector.getRemoteObject(endpoint);
 55  
         }
 56  0
     }
 57  
 
 58  
     protected void doDisconnect() throws Exception
 59  
     {
 60  0
         remoteObject = null;
 61  0
         invokedMethod = null;
 62  0
     }
 63  
 
 64  
     private Object[] getArgs(MuleEvent event) throws TransformerException
 65  
     {
 66  0
         Object payload = event.getMessage().getPayload();
 67  0
         if (payload instanceof Object[])
 68  
         {
 69  0
             return (Object[])payload;
 70  
         }
 71  
         else
 72  
         {
 73  0
             return new Object[]{payload};
 74  
         }
 75  
     }
 76  
 
 77  
     protected void doDispatch(MuleEvent event) throws Exception
 78  
     {
 79  0
         Object[] arguments = getArgs(event);
 80  0
         if (invokedMethod == null)
 81  
         {
 82  0
             invokedMethod = connector.getMethodObject(remoteObject, event);
 83  
         }
 84  0
         invokedMethod.invoke(remoteObject, arguments);
 85  0
     }
 86  
 
 87  
     public MuleMessage doSend(MuleEvent event) throws Exception
 88  
     {
 89  0
         if (invokedMethod == null)
 90  
         {
 91  0
             invokedMethod = connector.getMethodObject(remoteObject, event);
 92  
         }
 93  
 
 94  0
         Object[] arguments = getArgs(event);
 95  0
         Object result = invokedMethod.invoke(remoteObject, arguments);
 96  
 
 97  0
         if (result == null)
 98  
         {
 99  0
             return createMuleMessage(NullPayload.getInstance());
 100  
         }
 101  
         else
 102  
         {
 103  0
             return createMuleMessage(result);
 104  
         }
 105  
     }
 106  
 
 107  
     protected void doDispose()
 108  
     {
 109  
         // template method
 110  0
     }
 111  
 }