com.werxltd.jsonrpc
Class RPC

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.werxltd.jsonrpc.RPC
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class RPC
extends javax.servlet.http.HttpServlet

This class creates a servlet which implements the JSON-RPC specification.

Author:
Wes Widner
See Also:
Serialized Form

Field Summary
protected static org.apache.log4j.Logger LOG
           
 
Constructor Summary
RPC()
           
 
Method Summary
 void addMessageListener(JSONRPCEventListener l)
          Adds a class that implements the JSONRPCEventListener interface to the internal list of listeners
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Called by servlet container when a request is made.
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Forwards request to doGet method for consistency
 void init(javax.servlet.ServletConfig config)
          This method reads the servlet configuration for a list of classes it should scan for acceptable Method objects that can be called remotely.
 org.json.JSONObject listrpcmethods()
          Method lists available RPC methods loaded from configured classes.
 void removeMessageListener(JSONRPCEventListener l)
          Removes a class that implements the JSONRPCEventListener interface from the internal list of listeners
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.log4j.Logger LOG
Constructor Detail

RPC

public RPC()
Method Detail

init

public final void init(javax.servlet.ServletConfig config)
                throws javax.servlet.ServletException
This method reads the servlet configuration for a list of classes it should scan for acceptable Method objects that can be called remotely. Acceptable methods are methods that do not have a Modifier marking them as abstract or interface methods. Static methods are fine.

Valid methods are gathered into a HashMap and instances of non-static classes are created and reused for subsequent RPC calls.

Class is marked as final to prevent overriding and possible interference upstream.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - ServletConfig passed from container upon initialization
Throws:
javax.servlet.ServletException
See Also:
java.lang.reflect.Method, java.lang.reflect.Modifier, java.util.HashMap

addMessageListener

public void addMessageListener(JSONRPCEventListener l)
Adds a class that implements the JSONRPCEventListener interface to the internal list of listeners

Parameters:
l -

removeMessageListener

public void removeMessageListener(JSONRPCEventListener l)
Removes a class that implements the JSONRPCEventListener interface from the internal list of listeners

Parameters:
l -

listrpcmethods

public org.json.JSONObject listrpcmethods()
                                   throws org.json.JSONException
Method lists available RPC methods loaded from configured classes.

Returns:
JSONObject Containing available method information.
Throws:
org.json.JSONException

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException
Forwards request to doGet method for consistency

Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
See Also:
doGet

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws javax.servlet.ServletException
Called by servlet container when a request is made.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException


Copyright © 2010. All Rights Reserved.