當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。