Search in sources :

Example 1 with MessageBodyReaderContext

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();
}
Also used : MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext) MessageBodyReadableContent(io.helidon.media.common.MessageBodyReadableContent)

Example 2 with MessageBodyReaderContext

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();
}
Also used : MessageBodyWriterContext(io.helidon.media.common.MessageBodyWriterContext) MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext)

Example 3 with MessageBodyReaderContext

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);
}
Also used : MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext) MediaType(io.helidon.common.http.MediaType)

Example 4 with MessageBodyReaderContext

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));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) JsonValue(jakarta.json.JsonValue) DataChunk(io.helidon.common.http.DataChunk) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuffer(java.nio.ByteBuffer) ByteArrayInputStream(java.io.ByteArrayInputStream) Flow(java.util.concurrent.Flow) MessageBodyStreamReader(io.helidon.media.common.MessageBodyStreamReader) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) Service(io.helidon.webserver.Service) Multi(io.helidon.common.reactive.Multi) JsonPointer(jakarta.json.JsonPointer) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) GenericType(io.helidon.common.GenericType) EOFException(java.io.EOFException) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext) CompletionStage(java.util.concurrent.CompletionStage) StringReader(java.io.StringReader) Routing(io.helidon.webserver.Routing) JsonString(jakarta.json.JsonString) JsonValue(jakarta.json.JsonValue) JsonString(jakarta.json.JsonString) IOException(java.io.IOException) Flow(java.util.concurrent.Flow) GZIPInputStream(java.util.zip.GZIPInputStream) MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) EOFException(java.io.EOFException) DataChunk(io.helidon.common.http.DataChunk)

Aggregations

MessageBodyReaderContext (io.helidon.media.common.MessageBodyReaderContext)4 GenericType (io.helidon.common.GenericType)1 DataChunk (io.helidon.common.http.DataChunk)1 MediaType (io.helidon.common.http.MediaType)1 Multi (io.helidon.common.reactive.Multi)1 Single (io.helidon.common.reactive.Single)1 MessageBodyReadableContent (io.helidon.media.common.MessageBodyReadableContent)1 MessageBodyStreamReader (io.helidon.media.common.MessageBodyStreamReader)1 MessageBodyWriterContext (io.helidon.media.common.MessageBodyWriterContext)1 Routing (io.helidon.webserver.Routing)1 ServerRequest (io.helidon.webserver.ServerRequest)1 ServerResponse (io.helidon.webserver.ServerResponse)1 Service (io.helidon.webserver.Service)1 Json (jakarta.json.Json)1 JsonPointer (jakarta.json.JsonPointer)1 JsonString (jakarta.json.JsonString)1 JsonValue (jakarta.json.JsonValue)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1