use of java.util.concurrent.Flow.Publisher in project julian-http-client by ljtfreitas.
the class DefaultHTTPClientResponse method valueOf.
static DefaultHTTPClientResponse valueOf(HttpResponse<Publisher<List<ByteBuffer>>> response) {
HTTPStatus status = HTTPStatusCode.select(response.statusCode()).map(HTTPStatus::new).orElseGet(() -> HTTPStatus.valueOf(response.statusCode()));
HTTPHeaders headers = response.headers().map().entrySet().stream().map(e -> HTTPHeader.create(e.getKey(), e.getValue())).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
HTTPResponseBody body = HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.lazy(response.body()));
return new DefaultHTTPClientResponse(status, headers, body);
}
use of java.util.concurrent.Flow.Publisher in project helidon by oracle.
the class ReadableByteChannelPublisherTest method negativeDelay.
@Test
void negativeDelay() throws Exception {
PeriodicalChannel pc = createChannelWithNoAvailableData(10, 1);
RetrySchema schema = (i, delay) -> i >= 3 ? -10 : 0;
ReadableByteChannelPublisher publisher = new ReadableByteChannelPublisher(pc, schema);
// assert
try {
ContentReaders.readBytes(publisher).get(5, TimeUnit.SECONDS);
fail("Did not throw expected ExecutionException!");
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(TimeoutException.class));
}
}
use of java.util.concurrent.Flow.Publisher in project helidon by oracle.
the class BodyPartBodyStreamReader method read.
@Override
@SuppressWarnings("unchecked")
public <U extends ReadableBodyPart> Publisher<U> read(Publisher<DataChunk> publisher, GenericType<U> type, MessageBodyReaderContext context) {
String boundary = null;
MediaType contentType = context.contentType().orElse(null);
if (contentType != null) {
boundary = contentType.parameters().get("boundary");
}
if (boundary == null) {
throw new IllegalStateException("boudary header is missing");
}
MultiPartDecoder decoder = MultiPartDecoder.create(boundary, context);
publisher.subscribe(decoder);
return (Publisher<U>) decoder;
}
use of java.util.concurrent.Flow.Publisher in project helidon by oracle.
the class JsonpBodyStreamWriter method write.
@Override
public Multi<DataChunk> write(Publisher<? extends JsonStructure> publisher, GenericType<? extends JsonStructure> type, MessageBodyWriterContext context) {
MediaType contentType = context.findAccepted(MediaType.JSON_PREDICATE, MediaType.APPLICATION_JSON);
context.contentType(contentType);
// we do not have join operator
AtomicBoolean first = new AtomicBoolean(true);
JsonStructureToChunks jsonToChunks = new JsonStructureToChunks(true, jsonWriterFactory, context.charset());
return Multi.create(publisher).map(jsonToChunks).flatMap(it -> {
if (first.getAndSet(false)) {
// first record, do not prepend a comma
return Multi.just(DataChunk.create(ARRAY_JSON_BEGIN_BYTES), it);
} else {
// any subsequent record starts with a comma
return Multi.just(DataChunk.create(COMMA_BYTES), it);
}
}).onCompleteResume(DataChunk.create(ARRAY_JSON_END_BYTES));
}
Aggregations