|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package net.sf.crispy.impl; |
|
6 |
| |
|
7 |
| import java.lang.reflect.Method; |
|
8 |
| import java.util.Vector; |
|
9 |
| |
|
10 |
| import net.sf.crispy.ExceptionWrapper; |
|
11 |
| import net.sf.crispy.Executor; |
|
12 |
| import net.sf.crispy.InvocationException; |
|
13 |
| import net.sf.crispy.InvocationStrategy; |
|
14 |
| import net.sf.crispy.strategy.NameSpacePlusMethodInvocationStrategy; |
|
15 |
| import net.sf.crispy.util.Invoker; |
|
16 |
| import net.sf.crispy.util.Util; |
|
17 |
| |
|
18 |
| import org.apache.xmlrpc.XmlRpcClient; |
|
19 |
| import org.apache.xmlrpc.XmlRpcException; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| public class XmlRpcExecutor extends Executor { |
|
28 |
| |
|
29 |
| public final static String DEFAULT_URL_AND_PORT = "http://localhost:9090"; |
|
30 |
| |
|
31 |
| private XmlRpcClient client = null; |
|
32 |
| |
|
33 |
| |
|
34 |
128
| public String getDefaultUrlAndPort() { return DEFAULT_URL_AND_PORT; }
|
|
35 |
| |
|
36 |
82
| public InvocationStrategy getDefaultInvocationStrategy() { return new NameSpacePlusMethodInvocationStrategy(); }
|
|
37 |
| |
|
38 |
77
| public boolean withConverter() { return true; }
|
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
77
| public Object execute(Class pvProxyClass, Object pvProxy, Method pvMethod, Object[] pvArgs) throws Exception {
|
|
44 |
| |
|
45 |
77
| if (client == null) {
|
|
46 |
47
| client = new XmlRpcClient(getUrlAndPort());
|
|
47 |
| if (log.isDebugEnabled()) { log.debug("Create XmlRpcClient: " + client + " - URL: " + getUrlAndPort()); } |
|
48 |
| } |
|
49 |
| |
|
50 |
77
| String lvStrService = getInvocationStrategy().toString();
|
|
51 |
| if (log.isDebugEnabled()) { log.debug("Service: " + lvStrService + ": " + pvArgs); } |
|
52 |
77
| Vector param = Invoker.array2Vector(pvArgs);
|
|
53 |
77
| Object ret = null;
|
|
54 |
77
| try {
|
|
55 |
77
| ret = client.execute(lvStrService, param);
|
|
56 |
75
| ret = ExceptionWrapper.isResultExceptionThanThrowIt(ret);
|
|
57 |
| } catch (XmlRpcException e) { |
|
58 |
1
| Throwable t = Util.findDeepestThrowable(e);
|
|
59 |
1
| throw new InvocationException("Error by execute service: " + lvStrService + " -- args: " + param + " -- " + t.getMessage(), t);
|
|
60 |
| } |
|
61 |
| |
|
62 |
72
| return ret;
|
|
63 |
| } |
|
64 |
| } |