net.wotonomy.web.xml
Class XMLRPCServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by net.wotonomy.web.xml.XMLRPCServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class XMLRPCServlet
extends javax.servlet.http.HttpServlet

A servlet that can make any java object into an XML-RPC server. Simply pass in the object to the constructor and XML-RPC requests to this servlet will call the appropriate methods and convert the results to an XML-RPC response.

Depending on your servlet container, it may be necessary to create a simple subclass that creates your handler object in its constructor and then calls setHandler().

Responses are in the specification's standard response format.

Faults are returned if any exception is thrown in the method, or if the specified method is not found on the object. The fault string is the toString value of the exception, and the fault code is the hasCode value of the exception.

Remember that this servlet only responds to POSTs, per the XML-RPC spec.

See Also:
Serialized Form

Field Summary
protected  java.lang.Object handler
           
protected  boolean synchronizing
           
 
Constructor Summary
XMLRPCServlet()
          Default constructor initializes internal state.
XMLRPCServlet(java.lang.Object aHandler)
          Constructor takes any java object and allows its methods to be invoked via XMLRPC requests to this servlet.
 
Method Summary
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Overridden to service the request.
 java.lang.Object getHandler()
          Gets the object whose methods will be invoked to handle incoming requests.
protected  void handleRequest(java.lang.String aMethodName, java.lang.Object[] aParameterArray, javax.servlet.http.HttpServletResponse aResponse)
          Called by doPost after parsing an incoming request, and is responsible for invoking the specified method with the specified parameters on the handler object.
 boolean isSynchronizing()
          Gets whether the servlet should synchonize on the object before invoking methods on it.
 void setHandler(java.lang.Object aHandler)
          Sets the object whose methods will be invoked to handle incoming requests.
 void setSynchronizing(boolean willSynchronize)
          Sets whether the servlet should synchonize on the object before invoking methods on it.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handler

protected java.lang.Object handler

synchronizing

protected boolean synchronizing
Constructor Detail

XMLRPCServlet

public XMLRPCServlet()
Default constructor initializes internal state.


XMLRPCServlet

public XMLRPCServlet(java.lang.Object aHandler)
Constructor takes any java object and allows its methods to be invoked via XMLRPC requests to this servlet. Simply calls setHandler().

Method Detail

getHandler

public java.lang.Object getHandler()
Gets the object whose methods will be invoked to handle incoming requests.


setHandler

public void setHandler(java.lang.Object aHandler)
Sets the object whose methods will be invoked to handle incoming requests.


isSynchronizing

public boolean isSynchronizing()
Gets whether the servlet should synchonize on the object before invoking methods on it. Defaults to false.


setSynchronizing

public void setSynchronizing(boolean willSynchronize)
Sets whether the servlet should synchonize on the object before invoking methods on it. Defaults to false.


doPost

protected void doPost(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws javax.servlet.ServletException,
                      java.io.IOException
Overridden to service the request.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

handleRequest

protected void handleRequest(java.lang.String aMethodName,
                             java.lang.Object[] aParameterArray,
                             javax.servlet.http.HttpServletResponse aResponse)
Called by doPost after parsing an incoming request, and is responsible for invoking the specified method with the specified parameters on the handler object. (This implementation calls getOutputStream() on the response.) Override to customize the handling of the request.



Copyright © 2006 null. All Rights Reserved.