1
2
3
4
5
6
7
8
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 }