mini.rmi.registry
Class ServletRegistry

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--mini.rmi.registry.ServletRegistry
All Implemented Interfaces:
Registry, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ServletRegistry
extends javax.servlet.http.HttpServlet
implements Registry

Registry implemented as servlet. Passes RMI calls to remote objects.

Optional servlet parameters:

Note: If you need to subclass a different servlet, you can use the common wrapping trick:

 public class MyServletRegistry extends SomeOtherServlet {
     private ServletRegistry servletRegistry = new ServletRegistry();

     public void init(ServletConfig config) throws ServletException {
         servletRegistry.init(config);
         // ...
     }

     protected void doPost(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
         if (Naming.MINIRMI_CONTENT_TYPE.equals(req.getContentType())) {
             servletRegistry.doPost(req, res);
             return;
         }
         // ...
    }
 }

See Also:
Serialized Form

Constructor Summary
ServletRegistry()
           
 
Method Summary
 void bind(java.lang.String name, Remote object)
          Binds specified name to object.
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Serves as registry entry point: handles lookups and RMI calls.
static java.lang.String getClientHost()
          Called by UnicastRemoteObject.getClientHost() method.
 void init(javax.servlet.ServletConfig config)
          Initialization.
protected  java.lang.Object invokeMethod(Remote target, java.lang.reflect.Method method, java.lang.Object[] params)
          Method that actually invokes each RMI method.
 java.lang.String[] list()
          Returns array of names bound in registry.
 Remote lookup(java.lang.String name)
          Returns object associated with specified name.
 void rebind(java.lang.String name, Remote object)
          Rebinds specified name to a new object.
 java.lang.Object replaceObject(java.lang.Object object, java.lang.String clientJavaVersion)
          Override if you need to replace objects sent in RMI response.
 void setLogging(boolean b)
          Switches all logging on/off.
 void signObjID(ObjID oid)
          Signs object's ObjID.
 void unbind(java.lang.String name)
          Destroys the binding for specified name.
 boolean verifyObjID(ObjID oid)
          Returns true if object's ObjID was not tampered.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, 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
 

Constructor Detail

ServletRegistry

public ServletRegistry()
Method Detail

bind

public void bind(java.lang.String name,
                 Remote object)
          throws RemoteException,
                 AlreadyBoundException
Binds specified name to object.
Specified by:
bind in interface Registry

doPost

protected void doPost(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse res)
               throws javax.servlet.ServletException,
                      java.io.IOException
Serves as registry entry point: handles lookups and RMI calls.
Overrides:
doPost in class javax.servlet.http.HttpServlet

getClientHost

public static java.lang.String getClientHost()
                                      throws ServerNotActiveException
Called by UnicastRemoteObject.getClientHost() method.
Throws:
ServerNotActiveException - if called from non-RMI thread

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Initialization.
Overrides:
init in class javax.servlet.GenericServlet

invokeMethod

protected java.lang.Object invokeMethod(Remote target,
                                        java.lang.reflect.Method method,
                                        java.lang.Object[] params)
                                 throws java.lang.reflect.InvocationTargetException
Method that actually invokes each RMI method. Override to intercept RMI calls.
Parameters:
target - object which method will be invoked
method - method to be invoked
params - parameters passed to method
Returns:
value returned by invoked method (null for void method)
Since:
version 0.93

list

public java.lang.String[] list()
Returns array of names bound in registry.
Specified by:
list in interface Registry

lookup

public Remote lookup(java.lang.String name)
              throws RemoteException
Returns object associated with specified name.
Specified by:
lookup in interface Registry

rebind

public void rebind(java.lang.String name,
                   Remote object)
            throws RemoteException
Rebinds specified name to a new object.
Specified by:
rebind in interface Registry

replaceObject

public java.lang.Object replaceObject(java.lang.Object object,
                                      java.lang.String clientJavaVersion)
Override if you need to replace objects sent in RMI response. Returns the passed 'object' by default.
Parameters:
object - object that may be replaced
clientJavaVersion - Java version detected on client - (values: "1.1", "1.2", "1.3", "1.4" or null - if client uses miniRMI older than 0.94)
Returns:
object that will be sent instead of 'object'
Since:
version 0.94

setLogging

public void setLogging(boolean b)
Switches all logging on/off.

signObjID

public void signObjID(ObjID oid)
               throws java.lang.Exception
Signs object's ObjID. Override to implement custom signing.
Throws:
java.lang.Exception - if error ocurrs during signing
See Also:
verifyObjID(ObjID)

unbind

public void unbind(java.lang.String name)
Destroys the binding for specified name.
Specified by:
unbind in interface Registry

verifyObjID

public boolean verifyObjID(ObjID oid)
                    throws java.lang.Exception
Returns true if object's ObjID was not tampered. Override to implement custom signing.
Throws:
java.lang.Exception - if error ocurrs during verify
See Also:
signObjID(ObjID)