@Override
 public JsonProcessorResultWrapper execute(HttpRequest reqJson) {
   // System.out.println(String.format("Body: %s", reqJson.body()));
   RegistrationDataIn body = json.fromJson(reqJson.body(), RegistrationDataIn.class);
   RegistrationDataOut out = new RegistrationDataOut();
   Team team = TeamFactory.create(body.name);
   out.id = ((Long) team.getId());
   out.acceptedName = team.getName();
   String jsonOut = json.toJson(out);
   // System.out.println(String.format("Response: %s", jsonOut));
   return new JsonProcessorResultWrapper(201, jsonOut);
 }
Example #2
0
  @Override
  public void handleHttpRequest(
      HttpRequest httpRequest, HttpResponse httpResponse, HttpControl httpControl)
      throws Exception {
    if (!"GET".equals(httpRequest.method())) {
      httpResponse.status(500);
      httpResponse.end();
      return;
    }

    JSONObject build = new JSONObject();
    build.put("version", seledendroidServer.getServerVersion());
    build.put("browserName", "selendroid");

    JSONObject os = new JSONObject();
    os.put("arch", seledendroidServer.getCpuArch());
    os.put("name", seledendroidServer.getOsName());
    os.put("version", seledendroidServer.getOsVersion());

    JSONObject json = new JSONObject();
    json.put("build", build);
    json.put("os", os);

    JSONArray devices = null;
    try {
      devices = seledendroidServer.getSupportedDevices();
    } catch (Exception e) {
      devices = new JSONArray();
    }

    json.put("supportedDevices", devices);

    if (apps == null || devices.length() == 0) {
      try {
        apps = seledendroidServer.getSupportedApps();
      } catch (Exception e) {
        apps = new JSONArray();
      }
    }
    json.put("supportedApps", apps);

    // httpResponse.header("Content-Type", "text/plain");
    httpResponse.header("Content-Type", "application/json");

    httpResponse.content("{status: 0, value: " + json + "}");
    httpResponse.end();
  }
  public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) {
    String segment = getLastPathPart(request.uri());

    String body =
        String.format(
            "<html><head><title>Page%s</title></head>"
                + "<body>Page number <span id=\"pageNumber\">%s</span>"
                + "<p><a href=\"../xhtmlTest.html\" target=\"_top\">top</a>"
                + "</body></html>",
            segment, segment);

    response
        .charset(CHARSET)
        .header("Content-Type", "text/html; charset=" + CHARSET.name())
        .header("Content-Length", body.length())
        .content(body)
        .end();
  }