htp #20685 HttpEntity should not care about the materialized type of its Source (#20684)

This commit is contained in:
Jan Ypma 2016-06-01 16:56:48 +02:00 committed by Konrad Malawski
parent b95b60a6a5
commit 0a9283b8da
2 changed files with 21 additions and 10 deletions

View file

@ -66,25 +66,29 @@ public final class HttpEntities {
return HttpEntity$.MODULE$.fromPath((akka.http.scaladsl.model.ContentType) contentType, file, chunkSize);
}
public static HttpEntity.Default create(ContentType contentType, long contentLength, Source<ByteString, Object> data) {
return new akka.http.scaladsl.model.HttpEntity.Default((akka.http.scaladsl.model.ContentType) contentType, contentLength, data.asScala());
public static HttpEntity.Default create(ContentType contentType, long contentLength, Source<ByteString, ?> data) {
return new akka.http.scaladsl.model.HttpEntity.Default((akka.http.scaladsl.model.ContentType) contentType, contentLength, toScala(data));
}
public static HttpEntity.Chunked create(ContentType contentType, Source<ByteString, Object> data) {
return akka.http.scaladsl.model.HttpEntity.Chunked$.MODULE$.fromData((akka.http.scaladsl.model.ContentType) contentType, data.asScala());
public static HttpEntity.Chunked create(ContentType contentType, Source<ByteString, ?> data) {
return akka.http.scaladsl.model.HttpEntity.Chunked$.MODULE$.fromData((akka.http.scaladsl.model.ContentType) contentType, toScala(data));
}
public static HttpEntity.CloseDelimited createCloseDelimited(ContentType contentType, Source<ByteString, Object> data) {
return new akka.http.scaladsl.model.HttpEntity.CloseDelimited((akka.http.scaladsl.model.ContentType) contentType, data.asScala());
public static HttpEntity.CloseDelimited createCloseDelimited(ContentType contentType, Source<ByteString, ?> data) {
return new akka.http.scaladsl.model.HttpEntity.CloseDelimited((akka.http.scaladsl.model.ContentType) contentType, toScala(data));
}
public static HttpEntity.IndefiniteLength createIndefiniteLength(ContentType contentType, Source<ByteString, Object> data) {
return new akka.http.scaladsl.model.HttpEntity.IndefiniteLength((akka.http.scaladsl.model.ContentType) contentType, data.asScala());
public static HttpEntity.IndefiniteLength createIndefiniteLength(ContentType contentType, Source<ByteString, ?> data) {
return new akka.http.scaladsl.model.HttpEntity.IndefiniteLength((akka.http.scaladsl.model.ContentType) contentType, toScala(data));
}
public static HttpEntity.Chunked createChunked(ContentType contentType, Source<ByteString, Object> data) {
public static HttpEntity.Chunked createChunked(ContentType contentType, Source<ByteString, ?> data) {
return akka.http.scaladsl.model.HttpEntity.Chunked$.MODULE$.fromData(
(akka.http.scaladsl.model.ContentType) contentType,
data.asScala());
toScala(data));
}
private static akka.stream.scaladsl.Source<ByteString,Object> toScala(Source<ByteString, ?> javaSource) {
return (akka.stream.scaladsl.Source<ByteString,Object>)javaSource.asScala();
}
}

View file

@ -6,6 +6,8 @@ package akka.http.javadsl.model;
import akka.http.javadsl.model.headers.*;
import akka.japi.Pair;
import akka.stream.javadsl.Source;
import akka.util.ByteString;
public class JavaApiTestCases {
/**
@ -96,4 +98,9 @@ public class JavaApiTestCases {
return anything;
}
public static void HttpEntity_should_not_care_about_materialized_value_of_its_source() {
Source<ByteString, Integer> src = Source.single(ByteString.fromString("hello, world")).mapMaterializedValue(m -> 42);
HttpEntity entity = HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, src); // this needs to accept Source<ByteString, ?>
}
}