1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| package org.apache.xindice.server.rpc; |
21 |
| |
22 |
| import org.apache.commons.logging.Log; |
23 |
| import org.apache.commons.logging.LogFactory; |
24 |
| import org.apache.xindice.core.Collection; |
25 |
| import org.apache.xindice.core.DBException; |
26 |
| import org.apache.xindice.core.FaultCodes; |
27 |
| import org.apache.xmlrpc.XmlRpcException; |
28 |
| import org.apache.xmlrpc.XmlRpcHandler; |
29 |
| import org.apache.xmlrpc.XmlRpcRequest; |
30 |
| |
31 |
| import org.xmldb.api.base.ErrorCodes; |
32 |
| import org.xmldb.api.base.XMLDBException; |
33 |
| |
34 |
| import java.util.Map; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| public final class RPCMessageInterface implements XmlRpcHandler { |
41 |
| |
42 |
| private static final Log log = LogFactory.getLog(Collection.class); |
43 |
| |
44 |
| public static final String MESSAGE_PARAM = "message"; |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| private static final XmlRpcHandler INSTANCE = new RPCMessageInterface(); |
50 |
| |
51 |
| |
52 |
2381
| public static XmlRpcHandler getHandler() {
|
53 |
2381
| return INSTANCE;
|
54 |
| } |
55 |
| |
56 |
| |
57 |
1
| private RPCMessageInterface() {
|
58 |
| } |
59 |
| |
60 |
2381
| public Object execute(XmlRpcRequest xmlRpcRequest) throws XmlRpcException {
|
61 |
2381
| Map message = (Map) xmlRpcRequest.getParameter(0);
|
62 |
| |
63 |
| |
64 |
2381
| String type = (String) message.get(MESSAGE_PARAM);
|
65 |
2381
| try {
|
66 |
2381
| RPCMessage handler = (RPCMessage) Class.forName("org.apache.xindice.server.rpc.messages." + type).newInstance();
|
67 |
2381
| return handler.execute(message);
|
68 |
| } catch (XMLDBException e) { |
69 |
1
| if (log.isDebugEnabled()) {
|
70 |
0
| log.debug("Exception while processing XmlRpc command " + type, e);
|
71 |
| } |
72 |
| |
73 |
1
| throw new XmlRpcException(e.errorCode * FaultCodes.MAX_CODE + e.vendorErrorCode,
|
74 |
| e.getMessage()); |
75 |
| } catch (DBException e) { |
76 |
13
| if (log.isDebugEnabled()) {
|
77 |
0
| log.debug("Exception while processing XmlRpc command " + type, e);
|
78 |
| } |
79 |
| |
80 |
| |
81 |
13
| throw new XmlRpcException(ErrorCodes.VENDOR_ERROR * FaultCodes.MAX_CODE + e.faultCode,
|
82 |
| e.getMessage()); |
83 |
| } catch (Exception e) { |
84 |
0
| if (log.isDebugEnabled()) {
|
85 |
0
| log.debug("Exception while processing XmlRpc command " + type, e);
|
86 |
| } |
87 |
| |
88 |
| |
89 |
0
| throw new XmlRpcException(ErrorCodes.UNKNOWN_ERROR * FaultCodes.MAX_CODE + FaultCodes.GEN_UNKNOWN,
|
90 |
| e.getMessage()); |
91 |
| } |
92 |
| } |
93 |
| } |