Examples of RackResponse


Examples of com.squareup.rack.RackResponse

    app = new JRubyRackApplication(callable);
    env = envBuilder.build(request);
  }

  @Test public void callSetsTheResponseStatus() {
    RackResponse response = app.call(env);
    assertThat(response.getStatus()).isEqualTo(200);
  }
View Full Code Here

Examples of com.squareup.rack.RackResponse

    RackResponse response = app.call(env);
    assertThat(response.getStatus()).isEqualTo(200);
  }

  @Test public void callSetsTheResponseHeaders() {
    RackResponse response = app.call(env);
    assertThat(response.getHeaders()).contains(entry("Content-Type", "text/plain"));
  }
View Full Code Here

Examples of com.squareup.rack.RackResponse

    RackResponse response = app.call(env);
    assertThat(response.getHeaders()).contains(entry("Content-Type", "text/plain"));
  }

  @Test public void callSetsTheResponseBody() {
    RackResponse response = app.call(env);

    ImmutableList.Builder<String> strings = ImmutableList.builder();

    Iterator<byte[]> bytes = response.getBody();
    while (bytes.hasNext()) {
      strings.add(new String(bytes.next()));
    }

    assertThat(SPACE.join(strings.build())).isEqualTo(SPACE.join(env.keySet()));
View Full Code Here

Examples of com.squareup.rack.RackResponse

  @Test public void callParsesTheResponseStatusFromAString() {
    IRubyObject callable = Ruby.getGlobalRuntime()
        .evalScriptlet("proc { |env| ['201', {'Content-Type' => 'text/plain'}, env.keys] }");
    app = new JRubyRackApplication(callable);

    RackResponse response = app.call(env);
    assertThat(response.getStatus()).isEqualTo(201);
  }
View Full Code Here

Examples of com.squareup.rack.RackResponse

      body.add(parts);
      return this;
    }

    public RackResponse build() {
      return new RackResponse(status, headers.build(), body.build().iterator());
    }
View Full Code Here

Examples of com.squareup.rack.RackResponse

  @Override protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    RackEnvironment rackEnvironment = rackEnvironmentBuilder.build(request);

    try {
      RackResponse rackResponse = rackApplication.call(rackEnvironment);
      rackResponsePropagator.propagate(rackResponse, response);
    } finally {
      rackEnvironment.closeRackInput();
    }
  }
View Full Code Here

Examples of com.squareup.rack.RackResponse

  private RackResponse convertToJavaRackResponse(RubyArray response) {
    int status = Integer.parseInt(response.get(0).toString(), 10);
    Map headers = (Map) response.get(1);
    IRubyObject body = (IRubyObject) response.get(2);

    return new RackResponse(status, headers, new JRubyRackBodyIterator(body));
  }
View Full Code Here

Examples of org.jrack.RackResponse

    public static final String CONTENT_TYPE_TEXT_HTML = "text/html;charset=utf-8";
    public static final String JSON_TYPE = ".json";

    public static RackResponse standardHtml(String body) {
        return new RackResponse(HttpServletResponse.SC_OK)
                .withContentType(CONTENT_TYPE_TEXT_HTML)
                .withBody(body);
    }
View Full Code Here

Examples of org.jrack.RackResponse

                .withContentType(CONTENT_TYPE_TEXT_HTML)
                .withBody(body);
    }

    public static RackResponse standardJson(String body) {
        return new RackResponse(HttpServletResponse.SC_OK)
                .withContentType(Mime.mimeType(JSON_TYPE))
                .withBody(body);
    }
View Full Code Here

Examples of org.jrack.RackResponse

                String.format(FILE_FORMAT, params.get(IMAGE_FILE), params.get(TYPE)));

        String fileType = PathUtilities.extractType(file.getAbsolutePath());

        if (file.exists()) {
            RackResponse rackResponse = null;
            try {
                rackResponse = context.getRackResponse().withBody(file).withContentLength(file.length());
                if (configuration != null) {
                    Map<String, String> customMimeTypes = (Map<String, String>) configuration.get(CONFIG_ELEMENT_MIME_TYPES);
                    if (!CollectionUtils.isEmpty(customMimeTypes) && customMimeTypes.containsKey(fileType)) {
                        rackResponse.withContentType(customMimeTypes.get(fileType));
                    } else {
                        rackResponse.withContentType(Mime.mimeType(fileType));
                    }
                } else {
                    rackResponse.withContentType(Mime.mimeType(fileType));
                }
            } catch (FileNotFoundException e) {
                throw new ControllerException("File not found: " + file.getAbsolutePath(), e);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.