ServletInputStream in = req.getInputStream(); int len = req.getContentLength();
    protected void doPost(HttpServletRequest req, HttpServletResponse res)        throws ServletException, IOException {        increaseAccess();        res.setContentType("text/plain");        ServletOutputStream out = res.getOutputStream();        //        // Keep this for logging.        String remoteAddr = req.getRemoteAddr();        //        // Extract information about request type and how we were called.        // Also suitable for logging.        String method = req.getMethod();        String path = req.getServletPath();        //        // Extract the parameters passed to us using the utility        // HttpUtils.parsePostData available in the servlet package.        ServletInputStream in = req.getInputStream();        int len = req.getContentLength();        //        // Will this work with len == -1 ?? (Unknown length)        // Don't know, but -1 is possible only if we have a GET        // and we KNOW this is a POST :-)        Map params = req.getParameterMap();        try {            // Extract parameters from client            String username = "";            String password = "";            String version = "";            try {                username = ((String[]) params.get(REQUEST_USERNAME))[0];                password = ((String[]) params.get(REQUEST_PASSWORD))[0];                version = ((String[]) params.get(REQUEST_VERSION))[0];            } catch (ArrayIndexOutOfBoundsException ignored) {                // No parameters will result in "" being used from                // step above            } catch (NullPointerException ignoredAsWell) {                // No parameters will result in "" being used from                // step above            }            //            // Extract and verify protocol version            int majorversion = 0;            int minorversion = 0;            // Split version on '.'            int dotAt = version.indexOf('.');            if (dotAt == -1) {                // No separator entered, assume minor == 0                try {                    majorversion = Integer.parseInt(version);                } catch (NumberFormatException nfe) {                    errorLog("doPost: Got " + nfe + " on call from " + remoteAddr +                        " for username '" + username +                        "'. Asuming version is OK. Tried to parse '" + version + "'");                }                minorversion = 0;            } else {                try {                    majorversion = Integer.parseInt(version.substring(0, dotAt));                    minorversion = Integer.parseInt(version.substring(1 + dotAt, version.length()));                } catch (NumberFormatException nfe) {                    errorLog("doPost: Got " + nfe + " on call from " + remoteAddr +                        " for username '" + username +                        "'. Asuming version is OK. Tried to parse '" + version + "'");                }            }            //            // Now let's make sure we can play this tune            if ((majorversion == PROTOCOL_VERSION_MAJOR) &&                    (minorversion <= PROTOCOL_VERSION_MINOR)) {                // We're in business, protocol matches                // This is the call to what the customer usually                // needs to care about.                // The call itself seldom needs to be changed...                //                // You should, of course, make sure that you like                // the given code, as it's only an example!                AuthResult result = authenticateUser(username, password);                //                // Now build the result we'll send to the client                // We treat grant and rejects slightly different                if (result.granted()) {                    increaseGranted();                    out.println(RESPONSE_STATUS + "=" + MSG_OK);                    out.println(RESPONSE_RESULT + "=" + GRANT);                    debugLog("GRANTING request for '" + username + "'");                    // loop over all elements in resultHash, print one by one                    Hashtable resultParams = result.getResult();                    String key;                    // Standard code for printing a Hash.                    for (Enumeration keys = resultParams.keys(); keys.hasMoreElements();) {                        key = (String) keys.nextElement();                        out.println(key + "=" + ((String) resultParams.get(key)));                    }                } else { // rejected.                    increaseRejected();                    out.println(RESPONSE_STATUS + "=" + MSG_OK);                    out.println(RESPONSE_RESULT + "=" + REJECT);                    out.println(RESPONSE_MESSAGE + "=" + result.getReason());                    debugLog("REJECTING request for '" + username + "'. Reason: " +                        result.getReason());                }                out.println(RESPONSE_END); // The end of response token            } else {                // protocol missmatch, reject and return                out.println(RESPONSE_STATUS + "=" + MSG_PROTOCOL_MISMATCH);                out.println("message=Accepting at most " + PROTOCOL_VERSION_MAJOR + "." +                    PROTOCOL_VERSION_MINOR);                errorLog("PROTOCOL MISSMATCH. Got '" + version + "', but accepts only '" +                    PROTOCOL_VERSION_MAJOR + "." + PROTOCOL_VERSION_MINOR + "'");            }        } catch (Exception e) {            out.println(RESPONSE_STATUS + "=" + MSG_GENERIC_ERROR + e);            out.println(RESPONSE_END); // The end of response token            errorLog("?Caught exception ", e);        }    }