本文整理汇总了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();
}
示例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));
});
}
示例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
);
}
示例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));
});
}
示例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")
)
)
)
);
}
)
)
)
)
)
);
}
示例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);
}
示例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))));
}
示例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));
}
示例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(""))
)
)
);
}
示例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(""))
)
)
);
}