use of io.helidon.media.common.MessageBodyReaderContext in project helidon by oracle.
the class MultiPartDecoder method createPart.
private ReadableBodyPart createPart() {
ReadableBodyPartHeaders headers = bodyPartHeaderBuilder.build();
// create a reader context for the part
MessageBodyReaderContext partContext = MessageBodyReaderContext.create(context, /* eventListener */
null, headers, Optional.of(headers.contentType()));
// create a readable content for the part
MessageBodyReadableContent partContent = MessageBodyReadableContent.create(bodyPartPublisher, partContext);
return bodyPartBuilder.headers(headers).content(partContent).build();
}
use of io.helidon.media.common.MessageBodyReaderContext in project helidon by oracle.
the class OpenAPISupport method registerJsonpSupport.
private void registerJsonpSupport(ServerRequest req, ServerResponse res) {
MessageBodyReaderContext readerContext = req.content().readerContext();
MessageBodyWriterContext writerContext = res.writerContext();
JsonpSupport.create().register(readerContext, writerContext);
req.next();
}
use of io.helidon.media.common.MessageBodyReaderContext in project helidon by oracle.
the class WebClientResponseImpl method content.
@Override
public MessageBodyReadableContent content() {
Optional<MediaType> mediaType = headers.contentType();
MessageBodyReaderContext readerContext = MessageBodyReaderContext.create(this.readerContext, null, headers, mediaType);
return MessageBodyReadableContent.create(publisher, readerContext);
}
use of io.helidon.media.common.MessageBodyReaderContext in project helidon by oracle.
the class MockZipkinService method mockZipkin.
private void mockZipkin(final ServerRequest request, final ServerResponse response) {
request.queryParams().all("serviceName").forEach(s -> System.out.println(">>>" + s));
request.content().registerReader(new MessageBodyStreamReader<JsonValue>() {
@Override
public PredicateResult accept(final GenericType<?> type, final MessageBodyReaderContext context) {
return PredicateResult.COMPATIBLE;
}
@Override
@SuppressWarnings("unchecked")
public <U extends JsonValue> Flow.Publisher<U> read(final Flow.Publisher<DataChunk> publisher, final GenericType<U> type, final MessageBodyReaderContext context) {
return (Flow.Publisher<U>) Multi.create(publisher).map(d -> ByteBuffer.wrap(d.bytes())).reduce((buf, buf2) -> ByteBuffer.allocate(buf.capacity() + buf2.capacity()).put(buf.array()).put(buf2.array())).flatMap(b -> {
try (ByteArrayInputStream bais = new ByteArrayInputStream(b.array());
GZIPInputStream gzipInputStream = new GZIPInputStream(bais)) {
return Single.just(Json.createReader(new StringReader(new String(gzipInputStream.readAllBytes()))).readArray());
} catch (EOFException e) {
// ignore
return Multi.empty();
} catch (IOException e) {
throw new RuntimeException(e);
}
}).flatMap(a -> Multi.create(a.stream()));
}
}).asStream(JsonValue.class).map(JsonValue::asJsonObject).filter(json -> TAGS_POINTER.containsValue(json) && COMPONENT_POINTER.containsValue(json) && filteredComponents.stream().anyMatch(s -> s.equals(((JsonString) COMPONENT_POINTER.getValue(json)).getString()))).onError(Throwable::printStackTrace).onError(t -> response.status(500).send(t)).onComplete(response::send).peek(json -> LOGGER.info(json.toString())).forEach(e -> next.getAndSet(new CompletableFuture<>()).complete(e));
}
Aggregations