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