org.mmbase.servlet.rmi
Class RMIHandlerServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.mmbase.servlet.MMBaseServlet
              extended by org.mmbase.servlet.rmi.RMIHandlerServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig, MMBaseStarter

public class RMIHandlerServlet
extends MMBaseServlet

The default RMI socket factory contains several "fallback" mechanisms which enable an RMI client to communicate with a remote server. When an RMI client initiates contact with a remote server, it attempts to establish a connection using each of the following protocols in turn, until one succeeds: 1. Direct TCP connection. 2. Direct HTTP connection. 3. Proxy connection (SOCKS or HTTP). 4. Connection on port 80 over HTTP to a CGI script. 5. Proxy HTTP connection to CGI script on port 80. The RMI ServletHandler can be used as replacement for the java-rmi.cgi script that comes with the Java Development Kit (and is invoked in protocols 4 and 5 above). The java-rmi.cgi script and the ServletHandler both function as proxy applications that forward remote calls embedded in HTTP to local RMI servers which service these calls. The RMI ServletHandler enables RMI to tunnel remote method calls over HTTP more efficiently than the existing java-rmi.cgi script. The ServletHandler is only loaded once from the servlet administration utility. The script, java-rmi.cgi, is executed once every remote call. The ServletHandler class contains methods for executing as a Java servlet extension. Because the RMI protocol only makes use of the HTTP post command, the ServletHandler only supports the doPost HttpServlet method. The doPost method of this class interprets a servlet request's query string as a command of the form "=". These commands are represented by the abstract interface, RMICommandHandler. Once the doPost method has parsed the requested command, it calls the execute method on one of several command handlers in the commands array. The command that actually proxies remote calls is the ServletForwardCommand. When the execute method is invoked on the ServletForwardCommand, the command will open a connection on a local port specified by its param parameter and will proceed to write the body of the relevant post request into this connection. It is assumed that an RMI server (e.g. SampleRMIServer) is listening on the local port, "param." The "forward" command will then read the RMI server's response and send this information back to the RMI client as the body of the response to the HTTP post method. Because the ServletHandler uses a local socket to proxy remote calls, the servlet has the ability to forward remote calls to local RMI objects that reside in the ServletVM or outside of it. Servlet documentation may be found at the following location: http://jserv.javasoft.com/products/java-server/documentation/ webserver1.0.2/apidoc/Package-javax.servlet.http.html

See Also:
Serialized Form

Nested Class Summary
protected static class RMIHandlerServlet.ServletClientException
          ServletClientException is thrown when an error is detected in a client's request.
protected static class RMIHandlerServlet.ServletServerException
          ServletServerException is thrown when an error occurs here on the server.
 
Field Summary
 
Fields inherited from class org.mmbase.servlet.MMBaseServlet
mmbase, retryAfter
 
Constructor Summary
RMIHandlerServlet()
           
 
Method Summary
 void doGet(HttpServletRequest req, HttpServletResponse res)
          Provide more intelligible errors for methods that are likely to be called.
 void doPost(HttpServletRequest req, HttpServletResponse res)
           
 void doPut(HttpServletRequest req, HttpServletResponse res)
           
 void forward(HttpServletRequest req, HttpServletResponse res, String param)
          Execute the forward command.
 void getHostname(HttpServletRequest req, HttpServletResponse res, String param)
           
 String getServletInfo()
          Returns information about this servlet.
 void hostname(HttpServletRequest req, HttpServletResponse res, String param)
           
 void init(ServletConfig config)
           
 void ping(HttpServletRequest req, HttpServletResponse res, String param)
           
 
Methods inherited from class org.mmbase.servlet.MMBaseServlet
associateMapping, checkInited, decRefCount, destroy, getAssociations, getBasePath, getMMBase, getRequestURL, getServletByAssociation, getServletByMapping, getServletMappings, getServletMappingsByAssociation, incRefCount, init, service, setInitException, setMMBase
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RMIHandlerServlet

public RMIHandlerServlet()
Method Detail

init

public void init(ServletConfig config)
          throws ServletException
Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Throws:
ServletException

doPost

public void doPost(HttpServletRequest req,
                   HttpServletResponse res)
            throws ServletException,
                   IOException
Overrides:
doPost in class HttpServlet
Throws:
ServletException
IOException

doGet

public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
           throws ServletException,
                  IOException
Provide more intelligible errors for methods that are likely to be called. Let unsupported HTTP "do*" methods result in an error generated by the super class.

Overrides:
doGet in class MMBaseServlet
Parameters:
req - http Servlet request, contains incoming command and arguments
res - http Servlet response
Throws:
ServletException - and IOException when invoking methods of req or res.
IOException

doPut

public void doPut(HttpServletRequest req,
                  HttpServletResponse res)
           throws ServletException,
                  IOException
Overrides:
doPut in class HttpServlet
Throws:
ServletException
IOException

getServletInfo

public String getServletInfo()
Description copied from class: MMBaseServlet
Returns information about this servlet. Don't forget to override it.

Specified by:
getServletInfo in interface Servlet
Overrides:
getServletInfo in class MMBaseServlet

forward

public void forward(HttpServletRequest req,
                    HttpServletResponse res,
                    String param)
             throws RMIHandlerServlet.ServletClientException,
                    RMIHandlerServlet.ServletServerException,
                    IOException
Execute the forward command. Forwards data from incoming servlet request to a port on the local machine. Presumably, an RMI server will be reading the data that this method sends.

Parameters:
req - The servlet request.
res - The servlet response.
param - Port to which data will be sent.
Throws:
RMIHandlerServlet.ServletClientException
RMIHandlerServlet.ServletServerException
IOException

getHostname

public void getHostname(HttpServletRequest req,
                        HttpServletResponse res,
                        String param)
                 throws IOException
Throws:
IOException

ping

public void ping(HttpServletRequest req,
                 HttpServletResponse res,
                 String param)

hostname

public void hostname(HttpServletRequest req,
                     HttpServletResponse res,
                     String param)
              throws IOException
Throws:
IOException


MMBase 2.0-SNAPSHOT - null