1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.module.spring.remoting; |
8 | |
|
9 | |
import org.mule.api.transformer.TransformerException; |
10 | |
import org.mule.transformer.AbstractTransformer; |
11 | |
import org.mule.transformer.types.DataTypeFactory; |
12 | |
|
13 | |
import java.io.ObjectOutputStream; |
14 | |
|
15 | |
import org.apache.commons.io.output.ByteArrayOutputStream; |
16 | |
import org.springframework.remoting.support.RemoteInvocationResult; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class ObjectToRemoteInvocationResultTransformer extends AbstractTransformer |
23 | |
{ |
24 | |
public ObjectToRemoteInvocationResultTransformer() |
25 | |
{ |
26 | 0 | super(); |
27 | 0 | setReturnDataType(DataTypeFactory.BYTE_ARRAY); |
28 | 0 | } |
29 | |
|
30 | |
@Override |
31 | |
protected Object doTransform(Object src, String outputEncoding) throws TransformerException |
32 | |
{ |
33 | |
try |
34 | |
{ |
35 | 0 | if (logger.isDebugEnabled()) |
36 | |
{ |
37 | 0 | logger.debug("ObjectToRemoteInvocationResult.doTransform(" + src + ")"); |
38 | |
} |
39 | |
|
40 | |
RemoteInvocationResult rval; |
41 | |
|
42 | 0 | if (src instanceof RemoteInvocationResult) |
43 | |
{ |
44 | 0 | rval = (RemoteInvocationResult)src; |
45 | |
} |
46 | |
else |
47 | |
{ |
48 | 0 | rval = new RemoteInvocationResult(src); |
49 | |
} |
50 | |
|
51 | 0 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
52 | 0 | ObjectOutputStream oos = new ObjectOutputStream(baos); |
53 | 0 | oos.writeObject(rval); |
54 | 0 | oos.close(); |
55 | 0 | return baos.toByteArray(); |
56 | |
} |
57 | 0 | catch (Exception e) |
58 | |
{ |
59 | 0 | throw new TransformerException(this, e); |
60 | |
} |
61 | |
} |
62 | |
} |