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


Java Unmarshaller类代码示例

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


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

示例1: callService

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
protected CompletableFuture<String> callService(String ids) throws ExecutionException, InterruptedException {
    return Http.get(this.getContext().getSystem())
            .singleRequest(
                    HttpRequest.create()
                            .withUri(URI + ids)
                            .withMethod(HttpMethods.GET),
                    materializer)
            .thenCompose(response ->
                    Unmarshaller.entityToString().unmarshal(
                            response.entity(), this.getContext().dispatcher(), materializer))
            .toCompletableFuture();
}
 
开发者ID:henrikengstrom,项目名称:ujug2017,代码行数:13,代码来源:BackendBaseActor.java

示例2: fromJSON

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
/**
 * Returns an unmarshaller that will read a JSON request into a T using [protocol],
 * if it has any of the given media types.
 */
public static <T> Unmarshaller<HttpEntity, T> fromJSON(ReadProtocol<JSONEvent, T> protocol, MediaType... mediaTypes) {
    Unmarshaller<HttpEntity, Source<T, NotUsed>> streamUnmarshaller = sourceFromJSON(protocol, mediaTypes);
    
    return AsyncUnmarshallers.<HttpEntity, T>withMaterializer((ctx, mat, entity) -> {
        return streamUnmarshaller.unmarshal(entity, ctx, mat).thenCompose(src -> src.runWith(Sink.head(), mat));
    });
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:12,代码来源:JSONMarshallers.java

示例3: sourceFromXML

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
/**
 * Returns an unmarshaller that will read an XML request into a stream of T using [protocol], accepting the following media types:
 *      MediaTypes.APPLICATION_ATOM_XML,
 *      MediaTypes.APPLICATION_RSS_XML,
 *      MediaTypes.APPLICATION_SOAP_XML,
 *      MediaTypes.APPLICATION_XML,
 *      MediaTypes.TEXT_XML
 */
public static <T> Unmarshaller<HttpEntity, Source<T,NotUsed>> sourceFromXML(ReadProtocol<XMLEvent, T> protocol) {
    return sourceFromXML(protocol,
        MediaTypes.APPLICATION_ATOM_XML,
        MediaTypes.APPLICATION_RSS_XML,
        MediaTypes.APPLICATION_SOAP_XML,
        MediaTypes.APPLICATION_XML,
        MediaTypes.TEXT_XML
    );
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:18,代码来源:XMLMarshallers.java

示例4: head

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
private static <T> Unmarshaller<HttpEntity, T> head(Unmarshaller<HttpEntity, Source<T, NotUsed>> streamUnmarshaller) {
    return AsyncUnmarshallers.<HttpEntity, T>withMaterializer((ctx, mat, entity) -> {
        return streamUnmarshaller.unmarshal(entity, ctx, mat).thenCompose(src -> src.runWith(Sink.head(), mat));
    });
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:6,代码来源:XMLMarshallers.java

示例5: createRoutes

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
private Route createRoutes() {
    CheckHeader<MyJavaSession> checkHeader = new CheckHeader<>(getSessionManager());
    return
        route(
            randomTokenCsrfProtection(checkHeader, () ->
                route(
                    path("login", () ->
                        post(() ->
                            entity(Unmarshaller.entityToString(), body -> {
                                    LOGGER.info("Logging in {}", body);
                                    return setSession(refreshable, sessionTransport, new MyJavaSession(body), () ->
                                        setNewCsrfToken(checkHeader, () ->
                                            extractRequestContext(ctx ->
                                                onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                    complete("ok")
                                                )
                                            )
                                        )
                                    );
                                }
                            )
                        )
                    )
                )
            )
        );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:28,代码来源:SetSessionJava.java

示例6: as

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
public static final <T> Unmarshaller<HttpEntity,T> as(Class<T> type) {
    return Jackson.unmarshaller(mapper, type);
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:4,代码来源:JacksonMarshallers.java

示例7: sourceFromJSON

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
/**
 * Returns an unmarshaller that will read a JSON request into a stream of T using [protocol],
 * if it has any of the given media types.
 */
public static <T> Unmarshaller<HttpEntity, Source<T,NotUsed>> sourceFromJSON(ReadProtocol<JSONEvent, T> protocol, MediaType... mediaTypes) {
    return Unmarshaller.forMediaTypes(Arrays.asList(mediaTypes), entityToStream().thenApply(source -> source
        .via(ActsonReader.instance)
        .via(ProtocolReader.of(protocol))));
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:10,代码来源:JSONMarshallers.java

示例8: fromXML

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
/**
 * Returns an unmarshaller that will read an XML request into a T using [protocol], accepting the given media types.
 */
public static <T> Unmarshaller<HttpEntity, T> fromXML(ReadProtocol<XMLEvent, T> protocol, MediaType... mediaTypes) {
    return head(sourceFromXML(protocol, mediaTypes));
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:7,代码来源:XMLMarshallers.java

示例9: createRoutes

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
private Route createRoutes() {
    CheckHeader<String> checkHeader = new CheckHeader<>(getSessionManager());
    return
        route(
            pathSingleSlash(() ->
                redirect(Uri.create("/site/index.html"), StatusCodes.FOUND)
            ),
            randomTokenCsrfProtection(checkHeader, () ->
                route(
                    pathPrefix("api", () ->
                        route(
                            path("do_login", () ->
                                post(() ->
                                    entity(Unmarshaller.entityToString(), body -> {
                                            LOGGER.info("Logging in {}", body);
                                            return setSession(refreshable, sessionTransport, body, () ->
                                                setNewCsrfToken(checkHeader, () ->
                                                    extractRequestContext(ctx ->
                                                        onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                            complete("ok")
                                                        )
                                                    )
                                                )
                                            );
                                        }
                                    )
                                )
                            ),

                            // This should be protected and accessible only when logged in
                            path("do_logout", () ->
                                post(() ->
                                    requiredSession(refreshable, sessionTransport, session ->
                                        invalidateSession(refreshable, sessionTransport, () ->
                                            extractRequestContext(ctx -> {
                                                    LOGGER.info("Logging out {}", session);
                                                    return onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                        complete("ok")
                                                    );
                                                }
                                            )
                                        )
                                    )
                                )
                            ),

                            // This should be protected and accessible only when logged in
                            path("current_login", () ->
                                get(() ->
                                    requiredSession(refreshable, sessionTransport, session ->
                                        extractRequestContext(ctx -> {
                                                LOGGER.info("Current session: " + session);
                                                return onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                    complete(session)
                                                );
                                            }
                                        )
                                    )
                                )
                            )
                        )
                    ),
                    pathPrefix("site", () ->
                        getFromResourceDirectory(""))
                )
            )
        );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:69,代码来源:JavaJwtExample.java

示例10: createRoutes

import akka.http.javadsl.unmarshalling.Unmarshaller; //导入依赖的package包/类
private Route createRoutes() {
    CheckHeader<MyJavaSession> checkHeader = new CheckHeader<>(getSessionManager());
    return
        route(
            pathSingleSlash(() ->
                redirect(Uri.create("/site/index.html"), StatusCodes.FOUND)
            ),
            randomTokenCsrfProtection(checkHeader, () ->
                route(
                    pathPrefix("api", () ->
                        route(
                            path("do_login", () ->
                                post(() ->
                                    entity(Unmarshaller.entityToString(), body -> {
                                            LOGGER.info("Logging in {}", body);
                                            return setSession(refreshable, sessionTransport, new MyJavaSession(body), () ->
                                                setNewCsrfToken(checkHeader, () ->
                                                    extractRequestContext(ctx ->
                                                        onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                            complete("ok")
                                                        )
                                                    )
                                                )
                                            );
                                        }
                                    )
                                )
                            ),

                            // This should be protected and accessible only when logged in
                            path("do_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")
                                                    );
                                                }
                                            )
                                        )
                                    )
                                )
                            ),

                            // This should be protected and accessible only when logged in
                            path("current_login", () ->
                                get(() ->
                                    requiredSession(refreshable, sessionTransport, session ->
                                        extractRequestContext(ctx -> {
                                                LOGGER.info("Current session: " + session);
                                                return onSuccess(() -> ctx.completeWith(HttpResponse.create()), routeResult ->
                                                    complete(session.getUsername())
                                                );
                                            }
                                        )
                                    )
                                )
                            )
                        )
                    ),
                    pathPrefix("site", () ->
                        getFromResourceDirectory(""))
                )
            )
        );
}
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:69,代码来源:JavaExample.java


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