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