Package net.paoding.rose.mock.controllers

Source Code of net.paoding.rose.mock.controllers.OncePerRequestController

package net.paoding.rose.mock.controllers;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.rest.Get;

//测试 OncePerRequestInterceptor不会被调用2次!随便测试PreInvocation
public class OncePerRequestController {

    @Get
    public Object a(Invocation inv) throws Exception {
        Object value = "ok";
        inv.getHeadInvocation().setAttribute("once", value);
        inv.getRequest().setAttribute("preInv", inv);
        inv.getRequest().getRequestDispatcher("/oncePerRequest/b").forward(inv.getRequest(),
                inv.getResponse());
        return inv.getRequest().getAttribute("msg");
    }

    public String b(Invocation inv) {
        System.out.println("===success to forward  [OncePerRequestController]");
        Invocation preByActionA = (Invocation) inv.getRequest().getAttribute("preInv");
        if (preByActionA == null) {
            return "preInvocation.error.null";
        }
        if (preByActionA != inv.getPreInvocation()) {
            return "preInvocation.error";
        }
        inv.getRequest().setAttribute("msg", "ok");
        String ok = (String) inv.getHeadInvocation().getAttribute("once");
        if (!"ok".equals(ok)) {
            throw new IllegalArgumentException("setOncePerRequestAttribute");
        }
        return ok;
    }
}
TOP

Related Classes of net.paoding.rose.mock.controllers.OncePerRequestController

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.