1
2
3
4
5
6
7
8
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
24
25
26 public class ObjectToRemoteInvocationResultTransformer extends AbstractTransformer
27 {
28 public ObjectToRemoteInvocationResultTransformer()
29 {
30 super();
31 setReturnDataType(DataTypeFactory.BYTE_ARRAY);
32 }
33
34 @Override
35 protected Object doTransform(Object src, String outputEncoding) throws TransformerException
36 {
37 try
38 {
39 if (logger.isDebugEnabled())
40 {
41 logger.debug("ObjectToRemoteInvocationResult.doTransform(" + src + ")");
42 }
43
44 RemoteInvocationResult rval;
45
46 if (src instanceof RemoteInvocationResult)
47 {
48 rval = (RemoteInvocationResult)src;
49 }
50 else
51 {
52 rval = new RemoteInvocationResult(src);
53 }
54
55 ByteArrayOutputStream baos = new ByteArrayOutputStream();
56 ObjectOutputStream oos = new ObjectOutputStream(baos);
57 oos.writeObject(rval);
58 oos.close();
59 return baos.toByteArray();
60 }
61 catch (Exception e)
62 {
63 throw new TransformerException(this, e);
64 }
65 }
66 }