当前位置: 首页>>代码示例>>Java>>正文


Java Route类代码示例

本文整理汇总了Java中akka.http.javadsl.server.Route的典型用法代码示例。如果您正苦于以下问题:Java Route类的具体用法?Java Route怎么用?Java Route使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Route类属于akka.http.javadsl.server包,在下文中一共展示了Route类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import akka.http.javadsl.server.Route; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    final ActorSystem system = ActorSystem.create();
    final ActorMaterializer materializer = ActorMaterializer.create(system);

    final Route route = InfillionRoutes.routes();
    final Flow<HttpRequest, HttpResponse, NotUsed> flow = route.flow(system, materializer);

    final Http http = Http.get(system);
    final CompletionStage<ServerBinding> bindings = http.bindAndHandle(flow, ConnectHttp.toHost("127.0.0.1", 8080), materializer);

    System.out.println("Type RETURN to exit");
    System.in.read();

    bindings
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());

}
 
开发者ID:knoldus,项目名称:Infillion,代码行数:19,代码来源:PingPongApiLauncher.java

示例2: createRoutes

import akka.http.javadsl.server.Route; //导入依赖的package包/类
private Route createRoutes() {
    CheckHeader<MyJavaSession> checkHeader = new CheckHeader<>(getSessionManager());
    return
        route(
            randomTokenCsrfProtection(checkHeader, () ->
                route(
                    path("logout", () ->
                        post(() ->
                            requiredSession(refreshable, sessionTransport, session ->
                                invalidateSession(refreshable, sessionTransport, () ->
                                    extractRequestContext(ctx -> {
                                            LOGGER.info("Logging out {}", session.getUsername());
                                            return onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                complete("ok")
                                            );
                                        }
                                    )
                                )
                            )
                        )
                    )
                )
            )
        );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:26,代码来源:SessionInvalidationJava.java

示例3: buildRoute

import akka.http.javadsl.server.Route; //导入依赖的package包/类
protected Route buildRoute(HttpSessionAwareDirectives<String> testDirectives, SessionContinuity<String> oneOff, SessionContinuity<String> refreshable, SetSessionTransport sessionTransport, CsrfCheckMode<String> checkHeader) {
    return
        route(
            path("set", () ->
                testDirectives.setSession(oneOff, sessionTransport, SESSION, () -> complete("ok"))
            ),
            path("getOpt", () ->
                testDirectives.optionalSession(refreshable, sessionTransport, session -> complete(session.toString()))
            ),
            path("touchReq", () ->
                testDirectives.touchRequiredSession(refreshable, sessionTransport, session -> complete(session))
            ),
            path("invalidate", () ->
                testDirectives.invalidateSession(refreshable, sessionTransport, () -> complete("ok"))
            )

        );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:19,代码来源:OneOffSetRefreshableGetTest.java

示例4: shouldReadAnOptionalSessionWhenOnlyTheSessionIsSet_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadAnOptionalSessionWhenOnlyTheSessionIsSet_UsingCookies() {
    // given
    final Route route = createRoute(CookieST);

    // and
    TestRouteResult setRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    HttpCookie sessionData = getSessionDataCookieValues(setRouteResult.response());

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(Cookie.create(sessionDataCookieName, sessionData.value()))
        );

    // then
    getOptRouteResult.assertStatusCode(StatusCodes.OK);
    getOptRouteResult.assertEntity(EXPECTED_SESSION);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:21,代码来源:OneOffSetRefreshableGetTest.java

示例5: shouldReadAnOptionalSessionWhenOnlyTheSessionIsSet_UsingHeaders

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadAnOptionalSessionWhenOnlyTheSessionIsSet_UsingHeaders() {
    // given
    final Route route = createRoute(HeaderST);

    // and
    TestRouteResult setRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    HttpHeader sessionData = getSessionDataHeaderValues(setRouteResult.response());

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(RawHeader.create(getSessionDataHeaderName, sessionData.value()))
        );

    // then
    getOptRouteResult.assertStatusCode(StatusCodes.OK);
    getOptRouteResult.assertEntity(EXPECTED_SESSION);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:21,代码来源:OneOffSetRefreshableGetTest.java

示例6: shouldInvalidateASession_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldInvalidateASession_UsingCookies() {
    // given
    final Route route = createRoute(CookieST);

    // and
    TestRouteResult setRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    HttpCookie sessionData = getSessionDataCookieValues(setRouteResult.response());

    // when
    TestRouteResult getInvalidationRouteResult = testRoute(route)
        .run(HttpRequest.GET("/invalidate")
            .addHeader(Cookie.create(sessionDataCookieName, sessionData.value()))
        );

    // then
    getInvalidationRouteResult.assertStatusCode(StatusCodes.OK);

    // and
    HttpCookie invalidationRefreshToken = getRefreshTokenCookieValues(getInvalidationRouteResult.response());
    HttpCookie invalidationSessionData = getSessionDataCookieValues(getInvalidationRouteResult.response());
    Assert.assertNull(invalidationRefreshToken);
    Assert.assertTrue(invalidationSessionData.getExpires().isPresent());

}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:27,代码来源:OneOffSetRefreshableGetTest.java

示例7: buildRoute

import akka.http.javadsl.server.Route; //导入依赖的package包/类
protected Route buildRoute(HttpSessionAwareDirectives<String> testDirectives, SessionContinuity<String> oneOff, SessionContinuity<String> refreshable, SetSessionTransport sessionTransport, CsrfCheckMode<String> checkHeader) {
    return
        route(
            path("set", () ->
                testDirectives.setSession(refreshable, sessionTransport, SESSION, () -> complete("ok"))
            ),
            path("getOpt", () ->
                testDirectives.optionalSession(refreshable, sessionTransport, session -> complete(session.toString()))
            ),
            path("getReq", () ->
                testDirectives.requiredSession(refreshable, sessionTransport, session -> complete(session))
            ),
            path("touchReq", () ->
                testDirectives.touchRequiredSession(refreshable, sessionTransport, session -> complete(session))
            ),
            path("invalidate", () ->
                testDirectives.invalidateSession(refreshable, sessionTransport, () -> complete("ok"))
            ),
            path("full", () ->
                testDirectives.session(refreshable, sessionTransport, sessionResult -> complete(sessionResult.toString()))
            )
        );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:24,代码来源:RefreshableTest.java

示例8: shouldSetTheRefreshTokenCookieToExpireWhen_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldSetTheRefreshTokenCookieToExpireWhen_UsingCookies() {

    // given
    final Route route = createRoute(CookieST);

    // when
    TestRouteResult testRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));

    // then
    testRouteResult
        .assertStatusCode(StatusCodes.OK)
        .assertEntity("ok");

    // and
    HttpCookie refreshToken = getRefreshTokenCookieValues(testRouteResult.response());
    Assert.assertEquals(refreshToken.getMaxAge().getAsLong(), 60L * 60L * 24L * 30L); // set to 30 days by default

}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:21,代码来源:RefreshableTest.java

示例9: shouldSetBoth_TheSessionAndRefreshTokenWhen_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldSetBoth_TheSessionAndRefreshTokenWhen_UsingCookies() {
    // given
    final Route route = createRoute(CookieST);

    // when
    TestRouteResult testRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));

    // then
    testRouteResult
        .assertStatusCode(StatusCodes.OK)
        .assertEntity("ok");

    // and
    HttpResponse response = testRouteResult.response();

    // check _refreshtoken cookie
    HttpCookie refreshTokenCookie = getRefreshTokenCookieValues(response);
    Assert.assertNotNull(refreshTokenCookie.value());

    // check _sessiondata cookie
    HttpCookie sessionDataCookie = getSessionDataCookieValues(response);
    Assert.assertNotNull(sessionDataCookie.value());
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:26,代码来源:RefreshableTest.java

示例10: shouldSetBoth_TheSessionAndRefreshTokenWhen_UsingHeaders

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldSetBoth_TheSessionAndRefreshTokenWhen_UsingHeaders() {
    // given
    final Route route = createRoute(HeaderST);

    // when
    TestRouteResult testRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));

    // then
    testRouteResult
        .assertStatusCode(StatusCodes.OK)
        .assertEntity("ok");

    // and
    HttpResponse response = testRouteResult.response();

    // check _refreshtoken header
    HttpHeader refreshTokenHeaderValues = getRefreshTokenHeaderValues(response);
    Assert.assertNotNull(refreshTokenHeaderValues.value());

    // check _sessiondata header
    HttpHeader sessionDataHeaderValues = getSessionDataHeaderValues(response);
    Assert.assertNotNull(sessionDataHeaderValues.value());
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:26,代码来源:RefreshableTest.java

示例11: shouldSetANewRefreshTokenWhenTheSessionIsSetAgain_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldSetANewRefreshTokenWhenTheSessionIsSetAgain_UsingCookies() {
    // given
    final Route route = createRoute(CookieST);

    // when
    TestRouteResult firstTestRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    String firstToken = getRefreshTokenCookieValues(firstTestRouteResult.response()).value();

    // and
    TestRouteResult secondTestRouteResult = testRoute(route).run(HttpRequest.GET("/set"));
    String secondToken = getRefreshTokenCookieValues(secondTestRouteResult.response()).value();

    // then
    Assert.assertNotEquals(firstToken, secondToken);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:18,代码来源:RefreshableTest.java

示例12: shouldSetANewRefreshTokenWhenTheSessionIsSetAgain_UsingHeaders

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldSetANewRefreshTokenWhenTheSessionIsSetAgain_UsingHeaders() {
    // given
    final Route route = createRoute(HeaderST);

    // when
    TestRouteResult firstTestRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    String firstToken = getRefreshTokenHeaderValues(firstTestRouteResult.response()).value();

    // and
    TestRouteResult secondTestRouteResult = testRoute(route).run(HttpRequest.GET("/set"));
    String secondToken = getRefreshTokenHeaderValues(secondTestRouteResult.response()).value();

    // then
    Assert.assertNotEquals(firstToken, secondToken);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:18,代码来源:RefreshableTest.java

示例13: shouldReadAnOptionalSessionWhenBoth_TheSessionAndRefreshTokenAreSet_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadAnOptionalSessionWhenBoth_TheSessionAndRefreshTokenAreSet_UsingCookies() {
    // given
    final Route route = createRoute(CookieST);

    // and
    TestRouteResult setRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    HttpCookie refreshToken = getRefreshTokenCookieValues(setRouteResult.response());
    HttpCookie sessionData = getSessionDataCookieValues(setRouteResult.response());

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(Cookie.create(refreshTokenCookieName, refreshToken.value()))
            .addHeader(Cookie.create(sessionDataCookieName, sessionData.value()))
        );

    // then
    getOptRouteResult.assertStatusCode(StatusCodes.OK);
    getOptRouteResult.assertEntity(EXPECTED_SESSION);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:23,代码来源:RefreshableTest.java

示例14: shouldReadAnOptionalSessionWhenBoth_TheSessionAndRefreshTokenAreSet_UsingHeaders

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadAnOptionalSessionWhenBoth_TheSessionAndRefreshTokenAreSet_UsingHeaders() {
    // given
    final Route route = createRoute(HeaderST);

    // and
    TestRouteResult setRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    HttpHeader refreshToken = getRefreshTokenHeaderValues(setRouteResult.response());
    HttpHeader sessionData = getSessionDataHeaderValues(setRouteResult.response());

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(RawHeader.create(getRefreshTokenHeaderName, refreshToken.value()))
            .addHeader(RawHeader.create(getSessionDataHeaderName, sessionData.value()))
        );

    // then
    getOptRouteResult.assertStatusCode(StatusCodes.OK);
    getOptRouteResult.assertEntity(EXPECTED_SESSION);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:23,代码来源:RefreshableTest.java

示例15: shouldReadAnOptionalSessionWhenOnlyTheRefreshTokenIsSet_RecreateTheSession_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadAnOptionalSessionWhenOnlyTheRefreshTokenIsSet_RecreateTheSession_UsingCookies() {
    // given
    final Route route = createRoute(CookieST);

    // and
    TestRouteResult setRouteResult = testRoute(route)
        .run(HttpRequest.GET("/set"));
    HttpCookie refreshToken = getRefreshTokenCookieValues(setRouteResult.response());

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(Cookie.create(refreshTokenCookieName, refreshToken.value()))
        );

    // then
    getOptRouteResult.assertStatusCode(StatusCodes.OK);
    getOptRouteResult.assertEntity(EXPECTED_SESSION);
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:21,代码来源:RefreshableTest.java


注:本文中的akka.http.javadsl.server.Route类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。