Package org.jrack

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


                .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

                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

  public void testCall() throws Exception {
    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/index.html");

    RackResponse response = micro.call(input);
    Assert.assertTrue(RackResponse.getBodyAsString(response).contains("Hello"));
  }
View Full Code Here

    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/index.html")
        .with(Rack.RACK_BROWSER_LOCALE, "de");

    RackResponse response = micro.call(input);
    Assert.assertTrue("Context based localization failed",
        RackResponse.getBodyAsString(response).contains("Grüß Gott!"));
  }
View Full Code Here

        .with(Rack.PARAMS, Collections.singletonMap("language", "en"))
        .with(Rack.PATH_INFO, "/index.html")
        .with(Rack.REQUEST_METHOD, "GET");

    // English
    RackResponse response = micro.call(input);
    Assert.assertTrue("Expecting: Hello", RackResponse.getBodyAsString(response).contains("Hello"));

    // Romanian
    input.with(Rack.PARAMS, Collections.singletonMap("language", "ro"));
    response = micro.call(input);
View Full Code Here

    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/result.html")
        .with(Rack.PARAMS, Collections.singletonMap("exp", URLEncoder.encode("2+2", Globals.UTF8)));

    RackResponse response = micro.call(input);
    Assert.assertTrue("Can't use the request parameters",
        RackResponse.getBodyAsString(response).contains("=4"));
  }
View Full Code Here

  public void testTemplates() throws Exception {
    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/index.txt");

    RackResponse response = micro.call(input);
    Assert.assertTrue("Wrong template",
        RackResponse.getBodyAsString(response).contains("TXT DEFAULT TEMPLATE, content: Some text."));

    input.with(Rack.PATH_INFO, "/another_text.txt");
    response = micro.call(input);
View Full Code Here

  public void testMarkdownViewer() throws Exception {
    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/index.md");

    RackResponse response = micro.call(input);
    Assert.assertTrue(RackResponse.getBodyAsString(response)
        .contains("<h3>Markdown</h3><p>This is a simple markdown document</p>"));
  }
View Full Code Here

  public void testScriptingControllersRedirectToUrl() throws Exception {
    Context<String> input = new MapContext<String>()
        .with(Rack.REQUEST_METHOD, "GET")
        .with(Rack.PATH_INFO, "/redir.html");

    RackResponse response = micro.call(input);
    Assert.assertTrue(response.getStatus() == HttpServletResponse.SC_SEE_OTHER);
    String location = response.getHeaders().get("Location");
    Assert.assertTrue("Invalid redirection control", location.contains("redirected.html"));
    Assert.assertTrue("The response must be empty", RackResponse.getBodyAsString(response).isEmpty());
  }
View Full Code Here

TOP

Related Classes of org.jrack.RackResponse

Copyright © 2018 www.massapicom. 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.