public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String method = req.getMethod(); String path = req.getPathInfo(); String query = req.getQueryString(); ClassificationResult classification = processor.classifyRequest(method, path, query); if (supportCors != Cors.NONE) { addCorsHeaders(req, resp); } switch (classification.getStatus()) { case INVALID_PATH: sendError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid path " + path); break; case INVALID_METHOD: resp.setHeader("Allow", makeAllowHeader(classification)); sendError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method not allowed: " + method); break; case REQUIRED_QPS_MISSING: sendError( resp, HttpServletResponse.SC_BAD_REQUEST, "Required query parameters missing: " + classification.getMissingQueryParams()); break; case INVALID_QP_VALUE: sendError(resp, HttpServletResponse.SC_BAD_REQUEST, "Bad query parameter value"); break; case EXTRA_QPS: processRequest(classification, req, resp); break; case SUCCESSFUL: if (req.getMethod().equalsIgnoreCase("OPTIONS")) { resp.setHeader("Allow", makeAllowHeader(classification)); if (supportCors != Cors.NONE) { addOptionsCorsHeaders(req, resp, classification); } } else { processRequest(classification, req, resp); } break; default: throw new AssertionError(); } }