1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.client; |
17 |
|
|
18 |
|
import java.util.Iterator; |
19 |
|
import java.util.Map; |
20 |
|
|
21 |
|
import org.apache.xmlrpc.XmlRpcConfig; |
22 |
|
import org.apache.xmlrpc.XmlRpcException; |
23 |
|
import org.apache.xmlrpc.XmlRpcRequest; |
24 |
|
import org.apache.xmlrpc.common.XmlRpcExtensionException; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
public class XmlRpcLocalTransport extends XmlRpcTransportImpl { |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
public XmlRpcLocalTransport(XmlRpcClient pClient) { |
33 |
22 |
super(pClient); |
34 |
22 |
} |
35 |
|
|
36 |
|
private boolean isExtensionType(Object pObject) { |
37 |
52 |
if (pObject == null) { |
38 |
2 |
return true; |
39 |
50 |
} else if (pObject instanceof Object[]) { |
40 |
2 |
Object[] objects = (Object[]) pObject; |
41 |
6 |
for (int i = 0; i < objects.length; i++) { |
42 |
5 |
if (isExtensionType(objects[i])) { |
43 |
1 |
return true; |
44 |
|
} |
45 |
|
} |
46 |
1 |
return false; |
47 |
48 |
} else if (pObject instanceof Map) { |
48 |
2 |
Map map = (Map) pObject; |
49 |
10 |
for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) { |
50 |
6 |
Map.Entry entry = (Map.Entry) iter.next(); |
51 |
6 |
if (isExtensionType(entry.getKey()) || isExtensionType(entry.getValue())) { |
52 |
0 |
return true; |
53 |
|
} |
54 |
|
} |
55 |
2 |
return false; |
56 |
|
} else { |
57 |
61 |
return !(pObject instanceof Integer |
58 |
29 |
|| pObject instanceof String |
59 |
17 |
|| pObject instanceof byte[] |
60 |
15 |
|| pObject instanceof Double); |
61 |
|
} |
62 |
|
} |
63 |
|
|
64 |
|
public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException { |
65 |
48 |
XmlRpcConfig config = pRequest.getConfig(); |
66 |
48 |
if (!config.isEnabledForExtensions()) { |
67 |
35 |
for (int i = 0; i < pRequest.getParameterCount(); i++) { |
68 |
24 |
if (isExtensionType(pRequest.getParameter(i))) { |
69 |
13 |
throw new XmlRpcExtensionException("Parameter " + i + " has invalid type, if isEnabledForExtensions() == false"); |
70 |
|
} |
71 |
|
} |
72 |
|
} |
73 |
|
Object result; |
74 |
|
try { |
75 |
35 |
result = ((XmlRpcLocalClientConfig) config).getXmlRpcServer().execute(pRequest); |
76 |
0 |
} catch (Throwable t) { |
77 |
0 |
if (t instanceof XmlRpcClientException) { |
78 |
0 |
throw (XmlRpcClientException) t; |
79 |
|
} else { |
80 |
0 |
throw new XmlRpcClientException("Failed to invoke method " + pRequest.getMethodName() |
81 |
0 |
+ ": " + t.getMessage(), t); |
82 |
|
} |
83 |
|
} |
84 |
35 |
if (!config.isEnabledForExtensions()) { |
85 |
11 |
if (isExtensionType(result)) { |
86 |
0 |
throw new XmlRpcExtensionException("Result has invalid type, if isEnabledForExtensions() == false"); |
87 |
|
} |
88 |
|
} |
89 |
35 |
return result; |
90 |
|
} |
91 |
|
} |