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