Examples of RackResponse


Examples of org.jrack.RackResponse

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

        RackResponse response = micro.call(input);
        expect200(response);

        Assert.assertTrue("Download activity must be logged",
                ((MicroContext) input.getObject(Globals.CONTEXT))
                        .get("downloadActivity").equals("logged"));
View Full Code Here

Examples of org.jrack.RackResponse

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

        RackResponse response = micro.call(input);
        expect200(response);

        Assert.assertTrue("There is no stickiness in this context, pathless filters failure",
                ((MicroContext) input.getObject(Globals.CONTEXT))
                        .get("sticky").equals("I am a sticky filter"));
View Full Code Here

Examples of org.jrack.RackResponse

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

        RackResponse response = micro.call(input);
        String body = RackResponse.getBodyAsString(response);

        Assert.assertTrue(body.contains("Before: true"));
        Assert.assertTrue(body.contains("Wrapped with: love"));
        Assert.assertTrue(body.contains("After: true"));
View Full Code Here

Examples of org.jrack.RackResponse

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

        RackResponse response = micro.call(input);
        String body = RackResponse.getBodyAsString(response);
        MicroContext context = (MicroContext) ((MapContext) input).get("context");
        Assert.assertTrue("Invalid response", response.getStatus() == HttpServletResponse.SC_OK);
        Assert.assertTrue("Couldn't evaluate the BEFORE filters",
                body.contains("BEFORE: [filters/BeforeViewFilter1.bsh, filters/BeforeViewFilter2.bsh]"));
        Assert.assertNotNull("Should receive some feedback from the AFTER filters",
                context.get("afterFilters"));
    }
View Full Code Here

Examples of org.jrack.RackResponse

    public void testBinaryContent() throws Exception {
        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro-logo.png");

        RackResponse response = micro.call(input);
        Assert.assertTrue("Can't load binary content from a dynamic repository",
                RackResponse.getBodyAsBytes(response).length == 6898);

        Assert.assertTrue("Invalid Content-Type header",
                RackResponse.getHeaders(response).get("Content-Type")
View Full Code Here

Examples of org.jrack.RackResponse

        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro/files");

        RackResponse response = micro.call(input);
        Assert.assertEquals("Invalid response", "/micro/files",
                RackResponse.getBodyAsString(response, Charset.forName("UTF-8")));
    }
View Full Code Here

Examples of org.jrack.RackResponse

        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro/µ/0.1.2");

        RackResponse response = micro.call(input);
        Assert.assertEquals("Invalid response", "{\"micro\":{\"name\":\"µ\",\"version\":\"0.1.2\"}}",
                RackResponse.getBodyAsString(response, Charset.forName("UTF-8")));
    }
View Full Code Here

Examples of org.jrack.RackResponse

        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/view/Micro");

        RackResponse response = micro.call(input);
        Assert.assertEquals("Invalid response", "Micro",
                RackResponse.getBodyAsString(response, Charset.forName("UTF-8")));
    }
View Full Code Here

Examples of org.jrack.RackResponse

     * @throws FileNotFoundException
     * @throws ViewException
     */
    @Override
    public RackResponse call(MicroContext context) throws Exception {
        RackResponse response = null;

        if (context != null) {
            SiteContext site = context.getSiteContext();

            if (!CollectionUtils.isEmpty(getControllers())) {
                for (int i = 0; i < getControllers().size(); i++) {
                    Map<String, Object> controllerMap = getControllers().get(i);
                    site.getControllerManager().execute((String) controllerMap.get(Globals.NAME),
                            context, (Map) controllerMap.get(Globals.OPTIONS));
                    if (context.isHalt()) return context.getRackResponse();
                }
            }

            if (getView() != null && getView().getPath() != null) {
                response = context.getRackResponse();
                RepositoryManager repositoryManager = site.getRepositoryManager();
                String repositoryName = StringUtils.defaultString(getView().getRepositoryName(),
                        repositoryManager.getDefaultRepository().getName());

                String path = getView().getPath();

                context.with(Globals.PATH, path);

                String out;
                if (getView().getTemplate() != null) {
                    out = repositoryManager.getTemplatesRepository().getRepositoryWrapper(context)
                            .get(getView().getTemplate() + PathUtilities.extractType(path));
                } else {
                    Repository repository = repositoryManager.getRepository(repositoryName);
                    out = repository.getRepositoryWrapper(context).get(getView().getPath());
                }

                String contentType = Mime.mimeType(PathUtilities.extractType(path));

                if (response.getHeaders().get(Globals.HEADERS_CONTENT_TYPE) != null) {
                    contentType = response.getHeaders().get(Globals.HEADERS_CONTENT_TYPE);
                }

                response.withContentType(contentType)
                        .withContentLength(out.getBytes(Charset.forName(Globals.UTF8)).length)
                        .withBody(out);

                // We have a View served by
                // Faites vos jeux, rien ne va plus
View Full Code Here

Examples of org.jrack.RackResponse

                  ? param.getValue().get(0) :
                  param.getValue().toArray(new String[param.getValue().size()]);
              params.put(param.getKey(), paramValue);
            }

            RackResponse response = route.call(context);
            if (response != null) {
              context.setRackResponse(response);
            }

            // first matching route wins
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.