• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Route类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: shouldReadAnOptionalSessionWhenOnlyTheRefreshTokenIsSet_RecreateTheSession_UsingHeaders

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

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

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

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


示例17: shouldSetANewRefreshTokenAfterTheSessionIsRecreated_UsingCookies

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

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

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(Cookie.create(refreshTokenCookieName, refreshToken1.value()))
        );
    HttpCookie refreshToken2 = getRefreshTokenCookieValues(getOptRouteResult.response());

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


示例18: shouldSetANewRefreshTokenAfterTheSessionIsRecreated_UsingHeaders

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

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

    // when
    TestRouteResult getOptRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getOpt")
            .addHeader(RawHeader.create(getRefreshTokenHeaderName, refreshToken1.value()))
        );
    HttpHeader refreshToken2 = getRefreshTokenHeaderValues(getOptRouteResult.response());

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


示例19: shouldReadARequiredSessionWhenBoth_TheSessionAndRefreshTokensAreSet_UsingCookies

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadARequiredSessionWhenBoth_TheSessionAndRefreshTokensAreSet_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 getReqRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getReq")
            .addHeader(Cookie.create(refreshTokenCookieName, refreshToken.value()))
            .addHeader(Cookie.create(sessionDataCookieName, sessionData.value()))
        );

    // then
    getReqRouteResult.assertStatusCode(StatusCodes.OK);
    getReqRouteResult.assertEntity(SESSION);

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


示例20: shouldReadARequiredSessionWhenBoth_TheSessionAndRefreshTokensAreSet_UsingHeaders

import akka.http.javadsl.server.Route; //导入依赖的package包/类
@Test
public void shouldReadARequiredSessionWhenBoth_TheSessionAndRefreshTokensAreSet_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 getReqRouteResult = testRoute(route)
        .run(HttpRequest.GET("/getReq")
            .addHeader(RawHeader.create(getRefreshTokenHeaderName, refreshToken.value()))
            .addHeader(RawHeader.create(getSessionDataHeaderName, sessionData.value()))
        );

    // then
    getReqRouteResult.assertStatusCode(StatusCodes.OK);
    getReqRouteResult.assertEntity(SESSION);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SimpleCacheErrorHandler类代码示例发布时间:2022-05-22
下一篇:
Java Credentials类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap