當前位置: 首頁>>代碼示例>>Java>>正文


Java Interceptor類代碼示例

本文整理匯總了Java中org.wisdom.api.interception.Interceptor的典型用法代碼示例。如果您正苦於以下問題:Java Interceptor類的具體用法?Java Interceptor怎麽用?Java Interceptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Interceptor類屬於org.wisdom.api.interception包,在下文中一共展示了Interceptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testThatWeAcceptRequestWithATokenInTheQuery

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeAcceptRequestWithATokenInTheQuery() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .addToSession(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .setParameter(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNotNull().isNotEmpty()
            .isNotEqualTo("token");

}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:26,代碼來源:CSRFInterceptorTest.java

示例2: testThatWeAcceptRequestWithATokenInTheForm

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeAcceptRequestWithATokenInTheForm() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setFormField(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .addToSession(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNotNull().isNotEmpty()
            .isNotEqualTo("token");
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:25,代碼來源:CSRFInterceptorTest.java

示例3: testThatWeAcceptRequestWithATokenInTheFormWhenUsingCookie

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeAcceptRequestWithATokenInTheFormWhenUsingCookie() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    when(service.configuration.get("cookie.name")).thenReturn(CSRFServiceImplTest.CSRF_COOKIE);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setFormField(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .setCookie(Cookie.cookie(CSRFServiceImplTest.CSRF_COOKIE, "token").build())
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(result.getCookie(CSRFServiceImplTest.CSRF_COOKIE).value()).isNotNull().isNotEmpty()
            .isNotEqualTo("token");
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:26,代碼來源:CSRFInterceptorTest.java

示例4: testThatWeRejectRequestWithAnInvalidTokenInBody

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeRejectRequestWithAnInvalidTokenInBody() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setFormField(CSRFServiceImplTest.CSRF_TOKEN, "another token")
            .addToSession(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.FORBIDDEN);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNull();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:24,代碼來源:CSRFInterceptorTest.java

示例5: testThatWeRejectRequestWithTokenInBodyButNotInSession

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeRejectRequestWithTokenInBodyButNotInSession() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setFormField(CSRFServiceImplTest.CSRF_TOKEN, "token")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.FORBIDDEN);
    // Cleared.
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNull();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:24,代碼來源:CSRFInterceptorTest.java

示例6: testThatWeRejectRequestWithInvalidTokenInBodyUsingCookie

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeRejectRequestWithInvalidTokenInBodyUsingCookie() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    when(service.configuration.get("cookie.name")).thenReturn(CSRFServiceImplTest.CSRF_COOKIE);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setFormField(CSRFServiceImplTest.CSRF_TOKEN, "another token")
            .setCookie(Cookie.cookie(CSRFServiceImplTest.CSRF_COOKIE, "token").build())
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.FORBIDDEN);
    // Discarded cookie
    assertThat(result.getCookie(CSRFServiceImplTest.CSRF_COOKIE).value()).isEmpty();
    assertThat(result.getCookie(CSRFServiceImplTest.CSRF_COOKIE).maxAge()).isEqualTo(0);
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:27,代碼來源:CSRFInterceptorTest.java

示例7: testThatATokenIsAddedOnEligibleRequests

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatATokenIsAddedOnEligibleRequests() throws Exception {
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    when(service.configuration.get("cookie.name")).thenReturn(CSRFServiceImplTest.CSRF_COOKIE);
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.GET, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setParameter("key", "value")
            .setHeader(HeaderNames.ACCEPT, MimeTypes.HTML)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(annotation, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    // Cookie created.
    assertThat(result.getCookie(CSRFServiceImplTest.CSRF_COOKIE).value()).isNotEmpty();
    assertThat(result.getCookie(CSRFServiceImplTest.CSRF_COOKIE).maxAge()).isGreaterThan(100);
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:25,代碼來源:CSRFInterceptorTest.java

示例8: testThatWeAddTokenWhenNotThere

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeAddTokenWhenNotThere() throws Exception {
    FakeContext context = new FakeContext();
    when(service.configuration.getWithDefault("token.name", "csrfToken")).thenReturn(
            CSRFServiceImplTest.CSRF_TOKEN);
    route = new Route(HttpMethod.GET, "/", controller, controller.getClass().getMethod("doSomething", String
            .class));
    context
            .setParameter("key", "value")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(add, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNotNull().isNotEmpty();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:23,代碼來源:AddCSRFTokenInterceptorTest.java

示例9: testThatWeDoNotAddTokenWhenThereIsOne

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeDoNotAddTokenWhenThereIsOne() throws Exception {
    FakeContext context = new FakeContext();
    String token = service.crypto.generateToken();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .addToSession(CSRFServiceImplTest.CSRF_TOKEN, token)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(add, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isEqualTo(token);
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:22,代碼來源:AddCSRFTokenInterceptorTest.java

示例10: testThatWeDoNotAddATokenOnANonEligibleRequest

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatWeDoNotAddATokenOnANonEligibleRequest() throws Exception {
    FakeContext context = new FakeContext();
    route = new Route(HttpMethod.POST, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setFormField("key", "value")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .setHeader(HeaderNames.ACCEPT, MimeTypes.JSON)
            .route(route);

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(add, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNull();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:21,代碼來源:AddCSRFTokenInterceptorTest.java

示例11: switchToHeadWhenGetRouteExist

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void switchToHeadWhenGetRouteExist() throws Exception {
    DefaultPageErrorHandler handler = new DefaultPageErrorHandler();
    handler.router = mock(Router.class);

    handler.configuration = mock(ApplicationConfiguration.class);
    when(handler.configuration.isDev()).thenReturn(false);

    Controller controller = new MyController();
    Route route = new Route(HttpMethod.GET, "/", controller, controller.getClass().getMethod("action"));
    Route reqRoute = new Route(HttpMethod.HEAD, "/", null, null);


    when(handler.router.getRouteFor(HttpMethod.HEAD, "/")).thenReturn(new Route(HttpMethod.HEAD, "/", null, null));
    when(handler.router.getRouteFor(HttpMethod.GET, "/")).thenReturn(route);

    RequestContext rc = new RequestContext(reqRoute, Collections.<Filter>emptyList(),
            Collections.<Interceptor<?>, Object>emptyMap(), new Object[0], null);

    Result result = handler.call(reqRoute, rc);
    assertThat(result).isNotNull();
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(result.getRenderable().length()).isEqualTo(0);
    assertThat(result.getContentType()).isEqualTo(MimeTypes.JSON);
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:26,代碼來源:DefaultPageErrorHandlerTest.java

示例12: switchToHeadWhenGetRouteDoesNotExist

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void switchToHeadWhenGetRouteDoesNotExist() throws Exception {
    DefaultPageErrorHandler handler = new DefaultPageErrorHandler();
    handler.configuration = mock(ApplicationConfiguration.class);
    when(handler.configuration.isDev()).thenReturn(false);
    handler.router = mock(Router.class);

    Route reqRoute = new Route(HttpMethod.HEAD, "/", null, null);

    when(handler.router.getRouteFor(HttpMethod.HEAD, "/")).thenReturn(new Route(HttpMethod.HEAD, "/", null, null));
    when(handler.router.getRouteFor(HttpMethod.GET, "/")).thenReturn(new Route(HttpMethod.GET, "/", null, null));

    RequestContext rc = new RequestContext(reqRoute, Collections.<Filter>emptyList(),
            Collections.<Interceptor<?>, Object>emptyMap(), new Object[0], null);

    Result result = handler.call(reqRoute, rc);
    assertThat(result).isNotNull();
    assertThat(result.getStatusCode()).isEqualTo(Status.NOT_FOUND);
    assertThat(result.getRenderable().length()).isEqualTo(0);
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:21,代碼來源:DefaultPageErrorHandlerTest.java

示例13: testThatTokenAreDifferentForEachRequest

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatTokenAreDifferentForEachRequest() throws Exception {
    when(add.newTokenOnEachRequest()).thenReturn(true);
    FakeContext context = new FakeContext();
    when(service.configuration.getBooleanWithDefault("token.sign", true)).thenReturn(true);
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    final String token = service.crypto.generateSignedToken();
    route = new Route(HttpMethod.GET, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setParameter("key", "value")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .addToSession(CSRFServiceImplTest.CSRF_TOKEN, token)
            .setHeader(HeaderNames.CACHE_CONTROL, HeaderNames.NOCACHE_VALUE)
            .setHeader(HeaderNames.ACCEPT, MimeTypes.HTML)
            .route(route);

    assertThat(service.eligibleForCSRF(context)).isTrue();

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(add, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNotEqualTo(token);
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:30,代碼來源:AddCSRFTokenInterceptorTest.java

示例14: testThatTokensAreNotAddedToRequestThatSetCacheHeaders

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatTokensAreNotAddedToRequestThatSetCacheHeaders() throws Exception {
    when(add.newTokenOnEachRequest()).thenReturn(true);
    FakeContext context = new FakeContext();
    when(service.configuration.getBooleanWithDefault("token.sign", true)).thenReturn(true);
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    final String token = service.crypto.generateSignedToken();
    route = new Route(HttpMethod.GET, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setParameter("key", "value")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .setHeader(HeaderNames.CACHE_CONTROL, "public, max-age=3600")
            .setHeader(HeaderNames.ACCEPT, MimeTypes.HTML)
            .route(route);

    assertThat(service.eligibleForCSRF(context)).isTrue();

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(add, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNull();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:29,代碼來源:AddCSRFTokenInterceptorTest.java

示例15: testThatTokensAreAddedToRequestThatSetCacheHeadersToNoCache

import org.wisdom.api.interception.Interceptor; //導入依賴的package包/類
@Test
public void testThatTokensAreAddedToRequestThatSetCacheHeadersToNoCache() throws Exception {
    when(add.newTokenOnEachRequest()).thenReturn(true);
    FakeContext context = new FakeContext();
    when(service.configuration.getBooleanWithDefault("token.sign", true)).thenReturn(true);
    when(service.configuration.getWithDefault("token.name", "csrfToken"))
            .thenReturn(CSRFServiceImplTest.CSRF_TOKEN);
    route = new Route(HttpMethod.GET, "/", controller, controller.getClass().getMethod("doSomething", String.class));
    context
            .setParameter("key", "value")
            .setHeader(HeaderNames.CONTENT_TYPE, MimeTypes.FORM)
            .setHeader(HeaderNames.CACHE_CONTROL, HeaderNames.NOCACHE_VALUE)
            .setHeader(HeaderNames.ACCEPT, MimeTypes.HTML)
            .route(route);

    assertThat(service.eligibleForCSRF(context)).isTrue();

    Context.CONTEXT.set(context);

    RequestContext rc = new RequestContext(route,
            Collections.<Filter>emptyList(), Collections.<Interceptor<?>, Object>emptyMap(),
            new Object[]{"value"}, null);

    Result result = interceptor.call(add, rc);
    assertThat(result.getStatusCode()).isEqualTo(Status.OK);
    assertThat(context.session().get(CSRFServiceImplTest.CSRF_TOKEN)).isNotEmpty();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:28,代碼來源:AddCSRFTokenInterceptorTest.java


注:本文中的org.wisdom.api.interception.Interceptor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。