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.ByteArrayInputStream; |
14 | |
import java.io.InputStream; |
15 | |
import java.io.ObjectInputStream; |
16 | |
|
17 | |
import org.springframework.remoting.support.RemoteInvocation; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class ObjectToRemoteInvocationTransformer extends AbstractTransformer |
23 | |
{ |
24 | |
|
25 | |
public ObjectToRemoteInvocationTransformer() |
26 | |
{ |
27 | 0 | super(); |
28 | 0 | this.registerSourceType(DataTypeFactory.create(RemoteInvocation.class)); |
29 | 0 | this.registerSourceType(DataTypeFactory.BYTE_ARRAY); |
30 | 0 | this.registerSourceType(DataTypeFactory.INPUT_STREAM); |
31 | 0 | this.setReturnDataType(DataTypeFactory.create(RemoteInvocation.class)); |
32 | 0 | } |
33 | |
|
34 | |
@Override |
35 | |
protected Object doTransform(Object src, String encoding) throws TransformerException |
36 | |
{ |
37 | 0 | if (src instanceof RemoteInvocation) |
38 | |
{ |
39 | 0 | return src; |
40 | |
} |
41 | |
|
42 | 0 | Object o = null; |
43 | |
|
44 | 0 | if (src instanceof InputStream) |
45 | |
{ |
46 | |
try |
47 | |
{ |
48 | 0 | o = new ObjectInputStream((InputStream) src).readObject(); |
49 | |
} |
50 | 0 | catch (Exception e) |
51 | |
{ |
52 | 0 | throw new TransformerException(this, e); |
53 | 0 | } |
54 | |
} |
55 | |
else |
56 | |
{ |
57 | 0 | byte[] data = (byte[]) src; |
58 | 0 | ByteArrayInputStream bais = new ByteArrayInputStream(data); |
59 | |
try |
60 | |
{ |
61 | 0 | ObjectInputStream ois = new ObjectInputStream(bais); |
62 | 0 | o = ois.readObject(); |
63 | |
} |
64 | 0 | catch (Exception e) |
65 | |
{ |
66 | 0 | throw new TransformerException(this, e); |
67 | 0 | } |
68 | |
} |
69 | |
|
70 | 0 | RemoteInvocation ri = (RemoteInvocation) o; |
71 | 0 | if (logger.isDebugEnabled()) |
72 | |
{ |
73 | 0 | logger.debug("request to execute " + ri.getMethodName()); |
74 | 0 | for (int i = 0; i < ri.getArguments().length; i++) |
75 | |
{ |
76 | 0 | Object currentArgument = ri.getArguments()[i]; |
77 | |
|
78 | 0 | StringBuilder buf = new StringBuilder(64); |
79 | 0 | buf.append("with argument ("); |
80 | 0 | buf.append(currentArgument == null ? "<null>" : currentArgument.toString()); |
81 | 0 | buf.append(")"); |
82 | |
|
83 | 0 | logger.debug(buf); |
84 | |
} |
85 | |
} |
86 | 0 | return ri; |
87 | |
} |
88 | |
|
89 | |
} |