Пример #1
0
  /**
   * Override this to customize the server.
   *
   * <p>
   *
   * <p>(By default, this delegates to serveFile() and allows directory listing.)
   *
   * @param session The HTTP session
   * @return HTTP response, see class Response for details
   */
  public Response serve(IHTTPSession session) {
    Map<String, String> files = new HashMap<String, String>();
    Method method = session.getMethod();
    if (Method.PUT.equals(method) || Method.POST.equals(method)) {
      try {
        session.parseBody(files);
      } catch (IOException ioe) {
        return new Response(
            Response.Status.INTERNAL_ERROR,
            MIME_PLAINTEXT,
            "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage());
      } catch (ResponseException re) {
        return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage());
      }
    }

    Map<String, String> parms = session.getParms();
    parms.put(QUERY_STRING_PARAMETER, session.getQueryParameterString());
    return serve(session.getUri(), method, session.getHeaders(), parms, files);
  }