Coverage Report - org.mule.module.spring.remoting.ObjectToRemoteInvocationResultTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectToRemoteInvocationResultTransformer
0%
0/15
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: ObjectToRemoteInvocationResultTransformer.java 19250 2010-08-30 16:53:14Z dirk.olmes $
 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.module.spring.remoting;
 12  
 
 13  
 import org.mule.api.transformer.TransformerException;
 14  
 import org.mule.transformer.AbstractTransformer;
 15  
 import org.mule.transformer.types.DataTypeFactory;
 16  
 
 17  
 import java.io.ObjectOutputStream;
 18  
 
 19  
 import org.apache.commons.io.output.ByteArrayOutputStream;
 20  
 import org.springframework.remoting.support.RemoteInvocationResult;
 21  
 
 22  
 /**
 23  
  * Converts an Object to a Spring RemoteInvocationResult and then into a byte[].
 24  
  */
 25  
 
 26  
 public class ObjectToRemoteInvocationResultTransformer extends AbstractTransformer
 27  
 {
 28  
     public ObjectToRemoteInvocationResultTransformer()
 29  
     {
 30  0
         super();
 31  0
         setReturnDataType(DataTypeFactory.BYTE_ARRAY);
 32  0
     }
 33  
 
 34  
     @Override
 35  
     protected Object doTransform(Object src, String outputEncoding) throws TransformerException
 36  
     {
 37  
         try
 38  
         {
 39  0
             if (logger.isDebugEnabled())
 40  
             {
 41  0
                 logger.debug("ObjectToRemoteInvocationResult.doTransform(" + src + ")");
 42  
             }
 43  
 
 44  
             RemoteInvocationResult rval;
 45  
 
 46  0
             if (src instanceof RemoteInvocationResult)
 47  
             {
 48  0
                 rval = (RemoteInvocationResult)src;
 49  
             }
 50  
             else
 51  
             {
 52  0
                 rval = new RemoteInvocationResult(src);
 53  
             }
 54  
 
 55  0
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 56  0
             ObjectOutputStream oos = new ObjectOutputStream(baos);
 57  0
             oos.writeObject(rval);
 58  0
             oos.close();
 59  0
             return baos.toByteArray();
 60  
         }
 61  0
         catch (Exception e)
 62  
         {
 63  0
             throw new TransformerException(this, e);
 64  
         }
 65  
     }
 66  
 }