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 | 0 | public class AxisServiceProxy extends ServiceProxy |
36 | |
{ |
37 | |
|
38 | |
public static Object createProxy(AbstractMessageReceiver receiver, boolean synchronous, Class[] classes) |
39 | |
{ |
40 | 160 | final ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
41 | 160 | return Proxy.newProxyInstance(cl, classes, createServiceHandler(receiver, synchronous)); |
42 | |
} |
43 | |
|
44 | |
public static InvocationHandler createServiceHandler(AbstractMessageReceiver receiver, boolean synchronous) |
45 | |
{ |
46 | 160 | return new AxisServiceHandler(receiver, synchronous); |
47 | |
} |
48 | |
|
49 | 0 | private static class AxisServiceHandler implements InvocationHandler |
50 | |
{ |
51 | |
private AbstractMessageReceiver receiver; |
52 | 160 | private boolean synchronous = true; |
53 | |
|
54 | |
public AxisServiceHandler(AbstractMessageReceiver receiver, boolean synchronous) |
55 | 160 | { |
56 | 160 | this.receiver = receiver; |
57 | 160 | this.synchronous = synchronous; |
58 | 160 | } |
59 | |
|
60 | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable |
61 | |
{ |
62 | 160 | UMOMessageAdapter messageAdapter = receiver.getConnector().getMessageAdapter(args); |
63 | 160 | messageAdapter.setProperty(MuleProperties.MULE_METHOD_PROPERTY, method); |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 160 | messageAdapter.addProperties(AxisCleanAndAddProperties.cleanAndAdd(RequestContext.getEventContext())); |
71 | |
|
72 | 160 | UMOMessage message = receiver.routeMessage(new MuleMessage(messageAdapter), synchronous); |
73 | |
|
74 | 160 | if (message != null) |
75 | |
{ |
76 | 160 | UMOExceptionPayload wsException = message.getExceptionPayload(); |
77 | |
|
78 | 160 | if (wsException != null) |
79 | |
{ |
80 | 10 | UMOException umoException = ExceptionHelper.getRootMuleException(wsException.getException()); |
81 | |
|
82 | 10 | if (umoException.getCause() != null) |
83 | |
{ |
84 | 10 | throw umoException.getCause(); |
85 | |
} |
86 | |
else |
87 | |
{ |
88 | 0 | throw umoException; |
89 | |
} |
90 | |
} |
91 | |
|
92 | 150 | return message.getPayload(); |
93 | |
} |
94 | |
else |
95 | |
{ |
96 | 0 | return null; |
97 | |
} |
98 | |
} |
99 | |
} |
100 | |
} |