1 /*
2 * Copyright 1999,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 package org.apache.xmlrpc;
19
20 import java.util.Hashtable;
21 import java.util.Vector;
22
23 /**
24 * The <code>system.multicall</code> handler performs several RPC
25 * calls at a time.
26 *
27 * @author <a href="mailto:adam@megacz.com">Adam Megacz</a>
28 * @author <a href="mailto:andrew@kungfoocoder.org">Andrew Evers</a>
29 * @author Daniel L. Rall
30 * @version $Id: MultiCall.java,v 1.5 2005/04/22 10:25:57 hgomez Exp $
31 * @since 1.2
32 */
33 public class MultiCall
34 implements ContextXmlRpcHandler
35 {
36 public Object execute(String method, Vector params, XmlRpcContext context)
37 throws Exception
38 {
39 if ("multicall".equals(method))
40 {
41 return multicall(params, context);
42 }
43
44 throw new NoSuchMethodException("No method '" + method + "' in " + this.getClass().getName());
45 }
46
47 public Vector multicall(Vector requests, XmlRpcContext context)
48 {
49 // The array of calls is passed as a single parameter of type array.
50 requests=(Vector)requests.elementAt(0);
51 Vector response = new Vector();
52 XmlRpcServerRequest request;
53 for (int i = 0; i < requests.size(); i++)
54 {
55 try
56 {
57 Hashtable call = (Hashtable) requests.elementAt(i);
58 request = new XmlRpcRequest((String) call.get("methodName"),
59 (Vector) call.get("params"));
60 Object handler = context.getHandlerMapping().getHandler(request.getMethodName());
61 Vector v = new Vector();
62 v.addElement(XmlRpcWorker.invokeHandler(handler, request, context));
63 response.addElement(v);
64 }
65 catch (Exception x)
66 {
67 String message = x.toString();
68 int code = (x instanceof XmlRpcException ?
69 ((XmlRpcException) x).code : 0);
70 Hashtable h = new Hashtable();
71 h.put("faultString", message);
72 h.put("faultCode", new Integer(code));
73 response.addElement(h);
74 }
75 }
76 return response;
77 }
78 }