Package net.paoding.rose.web.impl.thread

Examples of net.paoding.rose.web.impl.thread.LinkedEngine


    }

    private MappingNode prepareMappingTree(List<Module> modules) {
        Mapping rootMapping = new ConstantMapping("");
        MappingNode mappingTree = new MappingNode(rootMapping);
        LinkedEngine rootEngine = new LinkedEngine(null, new RootEngine(instructionExecutor),
                mappingTree);
        mappingTree.getMiddleEngines().addEngine(ReqMethod.ALL, rootEngine);

        TreeBuilder treeBuilder = new TreeBuilder();
        treeBuilder.create(mappingTree, modules);
View Full Code Here


    }

    private MappingNode prepareMappingTree(List<Module> modules) {
        Mapping rootMapping = new ConstantMapping("");
        MappingNode mappingTree = new MappingNode(rootMapping);
        LinkedEngine rootEngine = new LinkedEngine(null, new RootEngine(instructionExecutor),
                mappingTree);
        mappingTree.getMiddleEngines().addEngine(ReqMethod.ALL, rootEngine);

        TreeBuilder treeBuilder = new TreeBuilder();
        treeBuilder.create(mappingTree, modules);
View Full Code Here

        }
    };

    public void testGetPost() {
        EngineGroup engineGroup = new EngineGroupImpl();
        engineGroup.addEngine(ReqMethod.GET, new LinkedEngine(null, getEngine, null));
        engineGroup.addEngine(ReqMethod.POST, new LinkedEngine(null, postEngine, null));

        assertSame(getEngine, engineGroup.getEngines(ReqMethod.GET)[0].getTarget());
        assertSame(postEngine, engineGroup.getEngines(ReqMethod.POST)[0].getTarget());

        String msg = "not allowed method should return engines with length is zero";
View Full Code Here

        assertEquals("[GET, POST]", engineGroup.toString());
    }

    public void testNotOverrideByAll() {
        EngineGroup engineGroup = new EngineGroupImpl();
        engineGroup.addEngine(ReqMethod.GET, new LinkedEngine(null, getEngine, null));
        engineGroup.addEngine(ReqMethod.ALL, new LinkedEngine(null, defEngine, null));
        engineGroup.addEngine(ReqMethod.POST, new LinkedEngine(null, postEngine, null));

        assertSame(getEngine, engineGroup.getEngines(ReqMethod.GET)[0].getTarget());
        assertSame(defEngine, engineGroup.getEngines(ReqMethod.GET)[1].getTarget());
        assertSame(defEngine, engineGroup.getEngines(ReqMethod.POST)[0].getTarget());
        assertSame(postEngine, engineGroup.getEngines(ReqMethod.POST)[1].getTarget());
View Full Code Here

    }

    private MappingNode prepareMappingTree(List<Module> modules) {
        Mapping rootMapping = new ConstantMapping("");
        MappingNode mappingTree = new MappingNode(rootMapping);
        LinkedEngine rootEngine = new LinkedEngine(null, new RootEngine(instructionExecutor),
                mappingTree);
        mappingTree.getMiddleEngines().addEngine(ReqMethod.ALL, rootEngine);

        TreeBuilder treeBuilder = new TreeBuilder();
        treeBuilder.create(mappingTree, modules);
View Full Code Here

    }

    private MappingNode prepareMappingTree(List<Module> modules) {
        Mapping rootMapping = new ConstantMapping("");
        MappingNode mappingTree = new MappingNode(rootMapping);
        LinkedEngine rootEngine = new LinkedEngine(null, new RootEngine(instructionExecutor),
                mappingTree);
        mappingTree.getMiddleEngines().addEngine(ReqMethod.ALL, rootEngine);

        TreeBuilder treeBuilder = new TreeBuilder();
        treeBuilder.create(mappingTree, modules);
View Full Code Here

            return ("@404: <br>not rose uri: '" + testUri + "'");
        }

        final MatchResult lastMatched = matchResults.get(matchResults.size() - 1);
        final EngineGroup leafEngineGroup = lastMatched.getMappingNode().getLeafEngines();
        final LinkedEngine leafEngine = select(leafEngineGroup.getEngines(testMethod), inv
                .getRequest());
        if (leafEngine == null) {
            if (leafEngineGroup.size() == 0) {
                // not rose uri
                return ("@404: <br>not rose uri, not exits leaf engines for it: '" + testUri + "'");

            } else {
                // 405 Method Not Allowed
                StringBuilder allow = new StringBuilder();
                final String gap = ", ";

                for (ReqMethod m : leafEngineGroup.getAllowedMethods()) {
                    allow.append(m.toString()).append(gap);
                }
                if (allow.length() > 0) {
                    allow.setLength(allow.length() - gap.length());
                }

                // true: don't forward to next filter or servlet
                return "@405: allowed=" + allow.toString();
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append("@200:");
        ActionEngine actionEngine = (ActionEngine) leafEngine.getTarget();
        sb.append(" <br>mapped '" + testUri + "' to " + actionEngine.getControllerClass().getName()
                + "#" + actionEngine.getMethod().getName());

        sb.append("<br>intectptors:");
        for (InterceptorDelegate i : actionEngine.getRegisteredInterceptors()) {
View Full Code Here

     * @param engines
     * @param request
     * @return
     */
    private LinkedEngine select(LinkedEngine[] engines, HttpServletRequest request) {
        LinkedEngine selectedEngine = null;
        int score = 0;

        for (LinkedEngine engine : engines) {
            int candidate = engine.isAccepted(request);
            if (candidate > score) {
View Full Code Here

        }
    }

    private void addModule(final MappingNode rootNode, Module module) {
        List<Mapping> terms = MappingFactory.parse(module.getMappingPath());
        LinkedEngine rootEngine = rootNode.getMiddleEngines().getEngines(ReqMethod.GET)[0];

        MappingNode parent = rootNode;
        for (Mapping mapping : terms) {
            if (mapping.getDefinition().length() == 0) {
                continue;
            }
            MappingNode temp = parent.getChild(mapping.getDefinition());
            if (temp == null) {
                temp = new MappingNode(mapping);
                parent.linkAsChild(temp);
            }
            parent = temp;
        }
        LinkedEngine moduleEngine = new LinkedEngine(rootEngine, new ModuleEngine(module), parent);
        parent.getMiddleEngines().addEngine(ReqMethod.ALL, moduleEngine);

        // controllers
        List<ControllerRef> controllers = module.getControllers();
        for (ControllerRef controller : controllers) {
View Full Code Here

                    target.linkAsChild(temp);
                }
                target = temp;
            }

            LinkedEngine controllerEngine = new LinkedEngine(moduleEngine, engine, target);
            target.getMiddleEngines().addEngine(ReqMethod.ALL, controllerEngine);
            //

            // actions
            MethodRef[] actions = controller.getActions();
View Full Code Here

TOP

Related Classes of net.paoding.rose.web.impl.thread.LinkedEngine

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.