FileDocCategorySizeDatePackage
SimplifiedServletHandler.javaAPI DocExample4240Thu Nov 08 00:23:38 GMT 2001com.ora.rmibook.chapter22.tunneler

SimplifiedServletHandler

public class SimplifiedServletHandler extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        returnClientError(res, "GET Operation not supported: " + "Can only forward POST requests.");
    
public voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
Execute the command given in the servlet request query string. The string before the first '=' in the queryString is interpreted as the command name, and the string after the first '=' is the parameters to the command.

param
req HTTP servlet request, contains incoming command and arguments
param
res HTTP servlet response
exception
ServletException and IOException when invoking methods of req or res.

        try {
            String queryString = req.getQueryString();
            String command, param;
            int delim = queryString.indexOf("=");

            if (delim == -1) {
                command = queryString;
                param = "";
            } else {
                command = queryString.substring(0, delim);
                param = queryString.substring(delim + 1);
            }

            if (command.equalsIgnoreCase("forward")) {
                try {
                    LoggingServletForwardCommand.execute(req, res, param);
                } catch (ServletClientException e) {
                    returnClientError(res, "client error: " + e.getMessage());
                    e.printStackTrace();
                } catch (ServletServerException e) {
                    returnServerError(res, "internal server error: " + e.getMessage());
                    e.printStackTrace();
                }
            } else {
                returnClientError(res, "invalid command: " + command);
            }
        } catch (Exception e) {
            returnServerError(res, "internal error: " + e.getMessage());
            e.printStackTrace();
        }
    
public voiddoPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        returnClientError(res, "PUT Operation not supported: " + "Can only forward POST requests.");
    
public java.lang.StringgetServletInfo()

        return "RMI Call Forwarding Servlet Servlet.<br>\n";
    
public voidinit(javax.servlet.ServletConfig config)

        super.init(config);
        System.out.println("Simplified RMI Servlet Handler loaded sucessfully.");
    
private static voidreturnClientError(javax.servlet.http.HttpServletResponse res, java.lang.String message)

	
        res.sendError(HttpServletResponse.SC_BAD_REQUEST,
            "<HTML><HEAD>" +
            "<TITLE>Java RMI Client Error</TITLE>" +
            "</HEAD>" +
            "<BODY>" +
            "<H1>Java RMI Client Error</H1>" +
            message +
            "</BODY></HTML>");

        System.err.println(HttpServletResponse.SC_BAD_REQUEST +
            "Java RMI Client Error" + message);
    
private static voidreturnServerError(javax.servlet.http.HttpServletResponse res, java.lang.String message)

	
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            "<HTML><HEAD>" +
            "<TITLE>Java RMI Server Error</TITLE>" +
            "</HEAD>" +
            "<BODY>" +
            "<H1>Java RMI Server Error</H1>" +
            message +
            "</BODY></HTML>");

        System.err.println(HttpServletResponse.SC_INTERNAL_SERVER_ERROR +
            "Java RMI Server Error: " + message);