Search in sources :

Example 1 with Interceptor

use of core.framework.web.Interceptor in project core-ng-project by neowu.

the class InvocationImpl method proceed.

@Override
public Response proceed() throws Exception {
    if (controller.skipInterceptor || currentStack >= interceptors.interceptors.size()) {
        logger.debug("execute controller, controller={}", controller.controllerInfo);
        return controller.controller.execute(request);
    } else {
        Interceptor interceptor = interceptors.interceptors.get(currentStack);
        currentStack++;
        logger.debug("intercept, interceptorClass={}", interceptor.getClass().getCanonicalName());
        return interceptor.intercept(this);
    }
}
Also used : Interceptor(core.framework.web.Interceptor)

Example 2 with Interceptor

use of core.framework.web.Interceptor in project core-ng-project by neowu.

the class InvocationImplTest method process.

@Test
void process() throws Exception {
    Stack stack = new Stack();
    TestController controller = new TestController(stack, 3);
    Interceptors interceptors = new Interceptors();
    interceptors.add(new TestInterceptor(stack, 0));
    interceptors.add(new TestInterceptor(stack, 1));
    interceptors.add(new TestInterceptor(stack, 2));
    InvocationImpl invocation = new InvocationImpl(new ControllerHolder(controller, null, null, null, false), interceptors, mock(Request.class), new WebContextImpl());
    Response response = invocation.proceed();
    assertEquals(HTTPStatus.NO_CONTENT, response.status());
    assertTrue(controller.executed);
    for (Interceptor interceptor : interceptors.interceptors) {
        assertTrue(((TestInterceptor) interceptor).executed);
    }
}
Also used : Response(core.framework.web.Response) Request(core.framework.web.Request) Interceptor(core.framework.web.Interceptor) Test(org.junit.jupiter.api.Test)

Example 3 with Interceptor

use of core.framework.web.Interceptor in project core-ng-project by neowu.

the class InvocationImplTest method skipInterceptor.

@Test
void skipInterceptor() throws Exception {
    Stack stack = new Stack();
    TestController controller = new TestController(stack, 0);
    Interceptors interceptors = new Interceptors();
    interceptors.add(new TestInterceptor(stack, 0));
    InvocationImpl invocation = new InvocationImpl(new ControllerHolder(controller, null, null, null, true), interceptors, mock(Request.class), new WebContextImpl());
    Response response = invocation.proceed();
    assertEquals(HTTPStatus.NO_CONTENT, response.status());
    assertTrue(controller.executed);
    for (Interceptor interceptor : interceptors.interceptors) {
        assertFalse(((TestInterceptor) interceptor).executed);
    }
}
Also used : Response(core.framework.web.Response) Request(core.framework.web.Request) Interceptor(core.framework.web.Interceptor) Test(org.junit.jupiter.api.Test)

Aggregations

Interceptor (core.framework.web.Interceptor)3 Request (core.framework.web.Request)2 Response (core.framework.web.Response)2 Test (org.junit.jupiter.api.Test)2