Exemplo n.º 1
0
  public PUT put(int x, int y, String id) {

    PUT move = new PUT();
    ArgumentsPut putArgs = new ArgumentsPut();
    putArgs.setId(id);

    putArgs.setXPos(Integer.toString(x));
    putArgs.setYPos(Integer.toString(y));
    move.setCommand("PUT");
    move.setArguments(putArgs);

    return move;
  }
Exemplo n.º 2
0
  @Override
  public Response serve(final Request req) {

    if (log.isDebugEnabled()) {
      log.debug("uri=" + req.uri);
      log.debug("method=" + req.method);
      log.debug("headers=" + req.headers);
      log.debug("params=" + req.params);
    } else if (log.isInfoEnabled()) log.info(req.method + " '" + req.uri + "' ");

    try {

      if (GET.equalsIgnoreCase(req.method)) {

        return doGet(req);

      } else if (POST.equalsIgnoreCase(req.method)) {

        return doPost(req);

      } else if (PUT.equalsIgnoreCase(req.method)) {

        return doPut(req);

      } else if (DELETE.equalsIgnoreCase(req.method)) {

        return doDelete(req);

      } else {

        return new Response(HTTP_METHOD_NOT_ALLOWED, MIME_TEXT_PLAIN, "" + req.method);
      }

    } catch (Throwable e) {

      log.error(e.getMessage(), e);

      final StringWriter w = new StringWriter();

      e.printStackTrace(new PrintWriter(w));

      /*
       * Note: if you send an HTTP_INTERNALERROR (500) the browser won't
       * display the response body so you have to send an Ok with the text
       * of the error message....
       */

      return new Response(HTTP_OK, MIME_TEXT_PLAIN, w.toString());
    }
  }