Class MessageBodyWriterContext

    • Method Detail

      • create

        public static MessageBodyWriterContext create​(MediaContext mediaContext,
                                                      MessageBodyContext.EventListener eventListener,
                                                      Parameters headers,
                                                      List<MediaType> acceptedTypes)
        Create a new writer context.
        Parameters:
        mediaContext - media support used to derive the parent context, may be null
        eventListener - message body subscription event listener, may be null
        headers - backing headers, must not be null
        acceptedTypes - accepted types, may be null
        Returns:
        MessageBodyWriterContext
      • create

        public static MessageBodyWriterContext create​(Parameters headers)
        Create a new empty writer context backed by the specified headers.
        Parameters:
        headers - headers
        Returns:
        MessageBodyWriterContext
      • create

        public static MessageBodyWriterContext create()
        Create a new empty writer context backed by empty read-only headers. Such writer context is typically the parent context that is used to hold application wide writers and outbound filters.
        Returns:
        MessageBodyWriterContext
      • marshall

        public <T> Flow.Publisher<DataChunk> marshall​(Single<T> content,
                                                      GenericType<T> type)
        Convert a given input publisher into HTTP payload by selecting a writer that accepts the specified type and current context.
        Type Parameters:
        T - entity type parameter
        Parameters:
        content - input publisher
        type - actual representation of the entity type
        Returns:
        publisher, never null
      • marshall

        public <T> Flow.Publisher<DataChunk> marshall​(Single<T> content,
                                                      MessageBodyWriter<T> writer,
                                                      GenericType<T> type)
        Convert a given input publisher into HTTP payload by selecting a writer with the specified class.
        Type Parameters:
        T - entity type parameter
        Parameters:
        content - input publisher
        writer - specific writer
        type - actual representation of the entity type
        Returns:
        publisher, never null
      • marshallStream

        public <T> Flow.Publisher<DataChunk> marshallStream​(Flow.Publisher<T> content,
                                                            GenericType<T> type)
        Convert a given input publisher into HTTP payload by selecting a stream writer that accepts the specified type and current context.
        Type Parameters:
        T - entity type parameter
        Parameters:
        content - input publisher
        type - actual representation of the entity type
        Returns:
        publisher, never null
      • marshallStream

        public <T> Flow.Publisher<DataChunk> marshallStream​(Flow.Publisher<T> content,
                                                            MessageBodyStreamWriter<T> writer,
                                                            GenericType<T> type)
        Convert a given input publisher into HTTP payload by selecting a stream writer with the specified class.
        Type Parameters:
        T - entity type parameter
        Parameters:
        content - input publisher
        writer - specific writer
        type - actual representation of the entity type
        Returns:
        publisher, never null
      • headers

        public Parameters headers()
        Get the underlying headers.
        Returns:
        Parameters, never null
      • contentType

        public Optional<MediaType> contentType()
        Get the Content-Type header.
        Returns:
        Optional, never null
      • acceptedTypes

        public List<MediaType> acceptedTypes()
        Get the inbound Accept header.
        Returns:
        List never null
      • contentType

        public void contentType​(MediaType contentType)
        Set the Content-Type header value in the underlying headers if not present.
        Parameters:
        contentType - Content-Type value to set, must not be null
      • contentLength

        public void contentLength​(long contentLength)
        Set the Content-Length header value in the underlying headers if not present.
        Parameters:
        contentLength - Content-Length value to set, must be a positive value
      • findAccepted

        public MediaType findAccepted​(Predicate<MediaType> predicate,
                                      MediaType defaultType)
                               throws IllegalStateException
        Find an media type in the inbound Accept header with the given predicate and default value.
        • The default value is returned if the predicate matches a media type with a wildcard subtype.
        • The default value if the current Content-Type header is not set and the inbound Accept header is empty or missing.
        • When the Content-Type header is set, if the predicate matches the Content-Type header value is returned.
        Parameters:
        predicate - a predicate to match against the inbound Accept header
        defaultType - a default media type
        Returns:
        MediaType, never null
        Throws:
        IllegalStateException - if no media type can be returned