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