Search in sources :

Example 1 with SingleSource

use of io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource in project servicetalk by apple.

the class JacksonSerializerMessageBodyReaderWriter method readFrom.

@Override
public Object readFrom(final Class<Object> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws WebApplicationException {
    final boolean oldJacksonProviderPresent = providers.getContextResolver(JacksonSerializationProvider.class, mediaType) != null;
    // FIXME 0.43 - Remove this branch when deprecation go away.
    if (oldJacksonProviderPresent) {
        return readFromOld(type, genericType, annotations, mediaType, httpHeaders, entityStream);
    } else {
        final JacksonSerializerFactory serializerFactory = getJacksonSerializerFactory(mediaType);
        final ExecutionContext<?> executionContext = ctxRefProvider.get().get().executionContext();
        final BufferAllocator allocator = executionContext.bufferAllocator();
        final int contentLength = requestCtxProvider.get().getLength();
        if (Single.class.isAssignableFrom(type)) {
            return handleEntityStream(entityStream, allocator, (p, a) -> deserialize(p, serializerFactory.serializerDeserializer(getSourceClass(genericType)), contentLength, a), (is, a) -> new SingleSource<>(deserialize(toBufferPublisher(is, a), serializerFactory.serializerDeserializer(getSourceClass(genericType)), contentLength, a)));
        } else if (Publisher.class.isAssignableFrom(type)) {
            return handleEntityStream(entityStream, allocator, (p, a) -> serializerFactory.streamingSerializerDeserializer(getSourceClass(genericType)).deserialize(p, a), (is, a) -> new PublisherSource<>(serializerFactory.streamingSerializerDeserializer(getSourceClass(genericType)).deserialize(toBufferPublisher(is, a), a)));
        }
        return handleEntityStream(entityStream, allocator, (p, a) -> deserializeObject(p, serializerFactory.serializerDeserializer(type), contentLength, a), (is, a) -> deserializeObject(toBufferPublisher(is, a), serializerFactory.serializerDeserializer(type), contentLength, a));
    }
}
Also used : ENTITY_CODER(javax.ws.rs.Priorities.ENTITY_CODER) SingleSource(io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) Publisher(io.servicetalk.concurrent.api.Publisher) Deserializer(io.servicetalk.serializer.api.Deserializer) SerializationException(io.servicetalk.serializer.api.SerializationException) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) RequestProperties.setResponseBufferPublisher(io.servicetalk.http.router.jersey.internal.RequestProperties.setResponseBufferPublisher) WILDCARD(javax.ws.rs.core.MediaType.WILDCARD) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) ContextResolver(javax.ws.rs.ext.ContextResolver) MediaType(javax.ws.rs.core.MediaType) Ref(org.glassfish.jersey.internal.util.collection.Ref) Consumes(javax.ws.rs.Consumes) BadRequestException(javax.ws.rs.BadRequestException) NoSuchElementException(java.util.NoSuchElementException) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo) BufferPublisherInputStream.handleEntityStream(io.servicetalk.http.router.jersey.internal.BufferPublisherInputStream.handleEntityStream) ConnectionContext(io.servicetalk.transport.api.ConnectionContext) OutputStream(java.io.OutputStream) Serializer(io.servicetalk.serializer.api.Serializer) StreamingSerializer(io.servicetalk.serializer.api.StreamingSerializer) Context(javax.ws.rs.core.Context) Providers(javax.ws.rs.ext.Providers) Single(io.servicetalk.concurrent.api.Single) DefaultSerializer(io.servicetalk.serialization.api.DefaultSerializer) FutureUtils.awaitResult(io.servicetalk.concurrent.internal.FutureUtils.awaitResult) JacksonSerializerFactory(io.servicetalk.data.jackson.JacksonSerializerFactory) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Priority(javax.annotation.Priority) Buffer(io.servicetalk.buffer.api.Buffer) JacksonSerializationProvider(io.servicetalk.data.jackson.JacksonSerializationProvider) HttpHeaders(javax.ws.rs.core.HttpHeaders) ParameterizedType(java.lang.reflect.ParameterizedType) ExecutionContext(io.servicetalk.transport.api.ExecutionContext) Type(java.lang.reflect.Type) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) Publisher.fromInputStream(io.servicetalk.concurrent.api.Publisher.fromInputStream) PublisherSource(io.servicetalk.http.router.jersey.internal.SourceWrappers.PublisherSource) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) JacksonSerializerFactory(io.servicetalk.data.jackson.JacksonSerializerFactory) PublisherSource(io.servicetalk.http.router.jersey.internal.SourceWrappers.PublisherSource) JacksonSerializationProvider(io.servicetalk.data.jackson.JacksonSerializationProvider) Publisher(io.servicetalk.concurrent.api.Publisher) RequestProperties.setResponseBufferPublisher(io.servicetalk.http.router.jersey.internal.RequestProperties.setResponseBufferPublisher) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator)

Example 2 with SingleSource

use of io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource in project servicetalk by apple.

the class JacksonSerializerMessageBodyReaderWriter method readFromOld.

// FIXME 0.43 - Remove this branch when deprecation go away.
@Deprecated
private Object readFromOld(final Class<Object> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws WebApplicationException {
    final io.servicetalk.serialization.api.Serializer serializer = getSerializer(mediaType);
    final ExecutionContext<?> executionContext = ctxRefProvider.get().get().executionContext();
    final BufferAllocator allocator = executionContext.bufferAllocator();
    final int contentLength = requestCtxProvider.get().getLength();
    if (Single.class.isAssignableFrom(type)) {
        return handleEntityStream(entityStream, allocator, (p, a) -> deserializeOld(p, serializer, getSourceClass(genericType), contentLength, a), (is, a) -> new SingleSource<>(deserializeOld(toBufferPublisher(is, a), serializer, getSourceClass(genericType), contentLength, a)));
    } else if (Publisher.class.isAssignableFrom(type)) {
        return handleEntityStream(entityStream, allocator, (p, a) -> serializer.deserialize(p, getSourceClass(genericType)), (is, a) -> new PublisherSource<>(serializer.deserialize(toBufferPublisher(is, a), getSourceClass(genericType))));
    }
    return handleEntityStream(entityStream, allocator, (p, a) -> deserializeObjectOld(p, serializer, type, contentLength, a), (is, a) -> deserializeObjectOld(toBufferPublisher(is, a), serializer, type, contentLength, a));
}
Also used : ENTITY_CODER(javax.ws.rs.Priorities.ENTITY_CODER) SingleSource(io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) Publisher(io.servicetalk.concurrent.api.Publisher) Deserializer(io.servicetalk.serializer.api.Deserializer) SerializationException(io.servicetalk.serializer.api.SerializationException) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) RequestProperties.setResponseBufferPublisher(io.servicetalk.http.router.jersey.internal.RequestProperties.setResponseBufferPublisher) WILDCARD(javax.ws.rs.core.MediaType.WILDCARD) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) ContextResolver(javax.ws.rs.ext.ContextResolver) MediaType(javax.ws.rs.core.MediaType) Ref(org.glassfish.jersey.internal.util.collection.Ref) Consumes(javax.ws.rs.Consumes) BadRequestException(javax.ws.rs.BadRequestException) NoSuchElementException(java.util.NoSuchElementException) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo) BufferPublisherInputStream.handleEntityStream(io.servicetalk.http.router.jersey.internal.BufferPublisherInputStream.handleEntityStream) ConnectionContext(io.servicetalk.transport.api.ConnectionContext) OutputStream(java.io.OutputStream) Serializer(io.servicetalk.serializer.api.Serializer) StreamingSerializer(io.servicetalk.serializer.api.StreamingSerializer) Context(javax.ws.rs.core.Context) Providers(javax.ws.rs.ext.Providers) Single(io.servicetalk.concurrent.api.Single) DefaultSerializer(io.servicetalk.serialization.api.DefaultSerializer) FutureUtils.awaitResult(io.servicetalk.concurrent.internal.FutureUtils.awaitResult) JacksonSerializerFactory(io.servicetalk.data.jackson.JacksonSerializerFactory) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Priority(javax.annotation.Priority) Buffer(io.servicetalk.buffer.api.Buffer) JacksonSerializationProvider(io.servicetalk.data.jackson.JacksonSerializationProvider) HttpHeaders(javax.ws.rs.core.HttpHeaders) ParameterizedType(java.lang.reflect.ParameterizedType) ExecutionContext(io.servicetalk.transport.api.ExecutionContext) Type(java.lang.reflect.Type) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) Publisher.fromInputStream(io.servicetalk.concurrent.api.Publisher.fromInputStream) PublisherSource(io.servicetalk.http.router.jersey.internal.SourceWrappers.PublisherSource) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) PublisherSource(io.servicetalk.http.router.jersey.internal.SourceWrappers.PublisherSource) Publisher(io.servicetalk.concurrent.api.Publisher) RequestProperties.setResponseBufferPublisher(io.servicetalk.http.router.jersey.internal.RequestProperties.setResponseBufferPublisher) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator)

Aggregations

Buffer (io.servicetalk.buffer.api.Buffer)2 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)2 Publisher (io.servicetalk.concurrent.api.Publisher)2 Publisher.fromInputStream (io.servicetalk.concurrent.api.Publisher.fromInputStream)2 Single (io.servicetalk.concurrent.api.Single)2 FutureUtils.awaitResult (io.servicetalk.concurrent.internal.FutureUtils.awaitResult)2 JacksonSerializationProvider (io.servicetalk.data.jackson.JacksonSerializationProvider)2 JacksonSerializerFactory (io.servicetalk.data.jackson.JacksonSerializerFactory)2 BufferPublisherInputStream.handleEntityStream (io.servicetalk.http.router.jersey.internal.BufferPublisherInputStream.handleEntityStream)2 RequestProperties.setResponseBufferPublisher (io.servicetalk.http.router.jersey.internal.RequestProperties.setResponseBufferPublisher)2 PublisherSource (io.servicetalk.http.router.jersey.internal.SourceWrappers.PublisherSource)2 SingleSource (io.servicetalk.http.router.jersey.internal.SourceWrappers.SingleSource)2 DefaultSerializer (io.servicetalk.serialization.api.DefaultSerializer)2 Deserializer (io.servicetalk.serializer.api.Deserializer)2 SerializationException (io.servicetalk.serializer.api.SerializationException)2 Serializer (io.servicetalk.serializer.api.Serializer)2 StreamingSerializer (io.servicetalk.serializer.api.StreamingSerializer)2 ConnectionContext (io.servicetalk.transport.api.ConnectionContext)2 ExecutionContext (io.servicetalk.transport.api.ExecutionContext)2 InputStream (java.io.InputStream)2