private Request buildRequest() {
    Request request = new Request();

    Reference ref = new Reference("http://localhost:12345/");

    request.setRootRef(ref);
    request.setResourceRef(new Reference(ref, "users"));

    return request;
  }
Exemplo n.º 2
0
  public Response sendRequest(Method method, String url, Representation representation) {
    this.logger.debug("Method: " + method.getName() + " url: " + url);

    Request request = new Request();
    request.setResourceRef(url);
    request.setMethod(method);

    if (!Method.GET.equals(method) && !Method.DELETE.equals(method)) {
      request.setEntity(representation);
    }

    request.setChallengeResponse(this.challenge);

    return this.restClient.handle(request);
  }
  @Test
  public void testJSON() throws IOException {
    JSONObject obj = new JSONObject();
    obj.put("title", "TITLE");
    JSONArray stuff = new JSONArray();
    for (int i = 0; i < 10; i++) {
      stuff.add(i);
    }
    obj.put("stuff", stuff);
    stuff = new JSONArray();
    for (int i = 0; i < 10; i++) {
      JSONObject s = new JSONObject();
      s.put("name", i);
      stuff.add(s);
    }
    obj.put("moreStuff", stuff);
    obj.put("missing", null);

    FreemarkerReaderTest.createTemplate(
        "farby.ftl",
        new StringReader(
            "${title}"
                + " <#list stuff as x>${x}</#list> "
                + " <#list moreStuff as s>${s.name}</#list>"
                + " ${missing!\"MISSING\"}"));

    FreemarkerReaderSource src = new FreemarkerReaderSource();
    Request req = new Request();
    Reference reference = new Reference();
    reference.setPath("/unused");
    reference.setQuery("");
    req.setResourceRef(reference);
    req.getAttributes().put("template", "farby");
    String json = obj.toString();
    req.setEntity(json, MediaType.APPLICATION_JSON);
    String text = new Scanner(src.printngReader(req).reader()).useDelimiter("\\Z").next();
    assertEquals("TITLE 0123456789  0123456789 MISSING", text);
  }