Package org.jrack

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


     * @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

                  ? 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

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.