コード例 #1
0
 public void setRequestMethod(String method) throws ProtocolException {
   this.method = method;
   if (METHOD_GET.equalsIgnoreCase(method)) {
     req = new HttpGet(url.toString());
   } else if (METHOD_HEAD.equalsIgnoreCase(method)) {
     req = new HttpHead(url.toString());
   } else if (METHOD_PUT.equalsIgnoreCase(method)) {
     req = new HttpPut(url.toString());
   } else if (METHOD_POST.equalsIgnoreCase(method)) {
     req = new HttpPost(url.toString());
   } else {
     this.method = null;
     throw new UnsupportedOperationException();
   }
 }
コード例 #2
0
  /**
   * Services the provided HTTP servlet request.
   *
   * @param req The HTTP servlet request.
   * @param resp The HTTP servlet response.
   * @throws IOException If an unexpected IO error occurred while sending the response.
   */
  public void service(final HttpServletRequest req, final HttpServletResponse resp)
      throws IOException {

    // Dispatch the request based on method, taking into account \
    // method override header.
    final String method = getMethod(req);
    if (METHOD_DELETE.equals(method)) {
      doDelete(req, resp);
    } else if (METHOD_GET.equals(method)) {
      doGet(req, resp);
    } else if (METHOD_PATCH.equals(method)) {
      doPatch(req, resp);
    } else if (METHOD_POST.equals(method)) {
      doPost(req, resp);
    } else if (METHOD_PUT.equals(method)) {
      doPut(req, resp);
    } else {
      // TODO: i18n
      fail(req, resp, new NotSupportedException("Method " + method + " not supported"));
    }
  }