dlr 2002/08/14 10:36:44
Modified: src/java/org/apache/xmlrpc XmlRpcServer.java
Log:
getWorker(): Tiny bit of documentation.
getHandler(): Refactored from Worker.executeInternal() into separate
method by Adam Megacz <[EMAIL PROTECTED]> (to support system.multicall).
invokeHandler(): Refactored from Worker.executeInternal() into
separate method by Adam Megacz <[EMAIL PROTECTED]> (to support
system.multicall).
Worker.executeInternal(): Patched by Adam Megacz to use getHandler()
and invokeHandler() methods.
Revision Changes Path
1.29 +70 -51 xml-rpc/src/java/org/apache/xmlrpc/XmlRpcServer.java
Index: XmlRpcServer.java
===================================================================
RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlRpcServer.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -u -r1.28 -r1.29
--- XmlRpcServer.java 9 Aug 2002 09:14:24 -0000 1.28
+++ XmlRpcServer.java 14 Aug 2002 17:36:44 -0000 1.29
@@ -154,8 +154,9 @@
}
/**
+ * Hands out pooled workers.
*
- * @return
+ * @return A worker.
*/
private final Worker getWorker()
{
@@ -180,6 +181,70 @@
}
/**
+ * Find the handler for a given method.
+ *
+ * @param methodName The name of the method to find.
+ */
+ protected Object getHandler(String methodName)
+ throws Exception
+ {
+ Object handler = null;
+ String handlerName = null;
+ int dot = methodName.lastIndexOf('.');
+ if (dot > -1)
+ {
+ handlerName = methodName.substring(0, dot);
+ handler = handlers.get(handlerName);
+ if (handler != null)
+ {
+ methodName = methodName.substring(dot + 1);
+ }
+ }
+
+ if (handler == null)
+ {
+ handler = handlers.get("$default");
+ }
+
+ if (handler == null)
+ {
+ if (dot > -1)
+ {
+ throw new Exception("RPC handler object \""
+ + handlerName + "\" not found and no default "
+ + "handler registered.");
+ }
+ else
+ {
+ throw new Exception("RPC handler object not found for \""
+ + methodName
+ + "\": no default handler registered.");
+ }
+ }
+
+ return handler;
+ }
+
+ /**
+ * Invokes the specified method on the provided handler.
+ */
+ protected Object invokeHandler(Object handler, String methodName,
+ Vector request, String user,
+ String password)
+ throws Exception
+ {
+ if (handler instanceof AuthenticatedXmlRpcHandler)
+ {
+ return ((AuthenticatedXmlRpcHandler) handler)
+ .execute(methodName, request, user, password);
+ }
+ else
+ {
+ return ((XmlRpcHandler) handler).execute(methodName, request);
+ }
+ }
+
+ /**
* Performs streaming, parsing, and handler execution.
* Implementation is not thread-safe.
*/
@@ -226,7 +291,7 @@
private byte[] executeInternal(InputStream is, String user,
String password)
{
- byte[] result;
+ byte[] result = null;
long now = 0;
if (XmlRpc.debug)
@@ -246,60 +311,14 @@
{
throw new Exception(errorMsg);
}
- Object handler = null;
-
- String handlerName = null;
- int dot = methodName.lastIndexOf('.');
- if (dot > -1)
- {
- handlerName = methodName.substring(0, dot);
- handler = handlers.get(handlerName);
- if (handler != null)
- {
- methodName = methodName.substring(dot + 1);
- }
- }
- if (handler == null)
- {
- handler = handlers.get("$default");
- }
-
- if (handler == null)
- {
- if (dot > -1)
- {
- throw new Exception("RPC handler object \""
- + handlerName + "\" not found and no default "
- + "handler registered.");
- }
- else
- {
- throw new Exception("RPC handler object not found for \""
- + methodName
- + "\": no default handler registered.");
- }
- }
+ Object handler = getHandler(methodName);
+ Object outParam = invokeHandler(handler, methodName, inParams,
user, password);
- Object outParam;
- if (handler instanceof AuthenticatedXmlRpcHandler)
- {
- outParam =((AuthenticatedXmlRpcHandler) handler)
- .execute(methodName, inParams, user, password);
- }
- else
- {
- outParam =((XmlRpcHandler) handler)
- .execute(methodName, inParams);
- }
if (XmlRpc.debug)
{
System.out.println("outparam = " + outParam);
}
- writer = new XmlWriter(buffer, encoding);
- writeResponse(outParam, writer);
- writer.flush();
- result = buffer.toByteArray();
}
catch(Exception x)
{