View Javadoc

1   /*
2    * $Id: ObjectToRemoteInvocationTransformer.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.extras.spring.remoting;
12  
13  import org.mule.transformers.AbstractTransformer;
14  import org.mule.umo.transformer.TransformerException;
15  
16  import java.io.ByteArrayInputStream;
17  import java.io.ObjectInputStream;
18  
19  import org.springframework.remoting.support.RemoteInvocation;
20  
21  public class ObjectToRemoteInvocationTransformer extends AbstractTransformer
22  {
23  
24      public ObjectToRemoteInvocationTransformer()
25      {
26          super();
27          this.registerSourceType(RemoteInvocation.class);
28          this.registerSourceType(byte[].class);
29          this.setReturnClass(RemoteInvocation.class);
30      }
31  
32      protected Object doTransform(Object src, String encoding) throws TransformerException
33      {
34          if (src instanceof RemoteInvocation)
35          {
36              return src;
37          }
38  
39          try
40          {
41              byte[] data = (byte[])src;
42              ByteArrayInputStream bais = new ByteArrayInputStream(data);
43              ObjectInputStream ois = new ObjectInputStream(bais);
44              Object o = ois.readObject();
45              RemoteInvocation ri = (RemoteInvocation)o;
46              if (logger.isDebugEnabled())
47              {
48                  logger.debug("request to execute " + ri.getMethodName());
49                  for (int i = 0; i < ri.getArguments().length; i++)
50                  {
51                      Object a = ri.getArguments()[i];
52                      logger.debug("with argument (" + a.toString() + ")");
53                  }
54              }
55              return ri;
56          }
57          catch (Exception e)
58          {
59              throw new TransformerException(this, e);
60          }
61      }
62  
63  }