1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.soap.axis; |
12 | |
|
13 | |
import org.mule.config.ExceptionHelper; |
14 | |
import org.mule.config.MuleProperties; |
15 | |
import org.mule.impl.MuleMessage; |
16 | |
import org.mule.impl.RequestContext; |
17 | |
import org.mule.providers.AbstractMessageReceiver; |
18 | |
import org.mule.providers.soap.ServiceProxy; |
19 | |
import org.mule.providers.soap.axis.extras.AxisCleanAndAddProperties; |
20 | |
import org.mule.umo.UMOException; |
21 | |
import org.mule.umo.UMOExceptionPayload; |
22 | |
import org.mule.umo.UMOMessage; |
23 | |
import org.mule.umo.provider.UMOMessageAdapter; |
24 | |
|
25 | |
import java.lang.reflect.InvocationHandler; |
26 | |
import java.lang.reflect.Method; |
27 | |
import java.lang.reflect.Proxy; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class AxisServiceProxy extends ServiceProxy |
39 | |
{ |
40 | |
|
41 | |
public static Object createProxy(AbstractMessageReceiver receiver, boolean synchronous, Class[] classes) |
42 | |
{ |
43 | 0 | final ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
44 | 0 | return Proxy.newProxyInstance(cl, classes, createServiceHandler(receiver, synchronous)); |
45 | |
} |
46 | |
|
47 | |
public static InvocationHandler createServiceHandler(AbstractMessageReceiver receiver, boolean synchronous) |
48 | |
{ |
49 | 0 | return new AxisServiceHandler(receiver, synchronous); |
50 | |
} |
51 | |
|
52 | 0 | private static class AxisServiceHandler implements InvocationHandler |
53 | |
{ |
54 | |
private AbstractMessageReceiver receiver; |
55 | 0 | private boolean synchronous = true; |
56 | |
|
57 | |
public AxisServiceHandler(AbstractMessageReceiver receiver, boolean synchronous) |
58 | 0 | { |
59 | 0 | this.receiver = receiver; |
60 | 0 | this.synchronous = synchronous; |
61 | 0 | } |
62 | |
|
63 | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable |
64 | |
{ |
65 | 0 | UMOMessageAdapter messageAdapter = receiver.getConnector().getMessageAdapter(args); |
66 | 0 | messageAdapter.setProperty(MuleProperties.MULE_METHOD_PROPERTY, method); |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 0 | messageAdapter.addProperties(AxisCleanAndAddProperties.cleanAndAdd(RequestContext.getEventContext())); |
74 | |
|
75 | 0 | UMOMessage message = receiver.routeMessage(new MuleMessage(messageAdapter), synchronous); |
76 | |
|
77 | 0 | if (message != null) |
78 | |
{ |
79 | 0 | UMOExceptionPayload wsException = message.getExceptionPayload(); |
80 | |
|
81 | 0 | if (wsException != null) |
82 | |
{ |
83 | 0 | UMOException umoException = ExceptionHelper.getRootMuleException(wsException.getException()); |
84 | |
|
85 | 0 | if (umoException.getCause() != null) |
86 | |
{ |
87 | 0 | throw umoException.getCause(); |
88 | |
} |
89 | |
else |
90 | |
{ |
91 | 0 | throw umoException; |
92 | |
} |
93 | |
} |
94 | |
|
95 | 0 | return message.getPayload(); |
96 | |
} |
97 | |
else |
98 | |
{ |
99 | 0 | return null; |
100 | |
} |
101 | |
} |
102 | |
} |
103 | |
} |