java.lang.Object
io.helidon.media.common.MessageBodyContext
io.helidon.media.common.MessageBodyWriterContext
- All Implemented Interfaces:
MessageBodyFilters
,MessageBodyWriters
public final class MessageBodyWriterContext
extends MessageBodyContext
implements MessageBodyWriters, MessageBodyFilters
Implementation of
MessageBodyWriters
.-
Nested Class Summary
Nested classes/interfaces inherited from class io.helidon.media.common.MessageBodyContext
MessageBodyContext.ErrorEvent, MessageBodyContext.Event, MessageBodyContext.EventListener, MessageBodyContext.EventType
-
Method Summary
Modifier and TypeMethodDescriptionGet the inboundAccept
header.charset()
Derive the charset to use from theContent-Type
header value or using a default charset as fallback.void
contentLength
(long contentLength) Set theContent-Length
header value in the underlying headers if not present.Get theContent-Type
header.void
contentType
(MediaType contentType) Set theContent-Type
header value in the underlying headers if not present.static MessageBodyWriterContext
create()
Create a new empty writer context backed by empty read-only headers.static MessageBodyWriterContext
Create a new empty writer context backed by the specified headers.static MessageBodyWriterContext
create
(Parameters headers) Deprecated, for removal: This API element is subject to removal in a future version.static MessageBodyWriterContext
create
(MediaContext mediaContext, MessageBodyContext.EventListener eventListener, Headers headers, List<MediaType> acceptedTypes) Create a new writer context.static MessageBodyWriterContext
create
(MediaContext mediaContext, MessageBodyContext.EventListener eventListener, Parameters headers, List<MediaType> acceptedTypes) Deprecated, for removal: This API element is subject to removal in a future version.Usecreate(MediaContext, io.helidon.media.common.MessageBodyContext.EventListener, io.helidon.common.http.Headers, java.util.List)
instead, passingHeaders
instead ofParameters
.static MessageBodyWriterContext
create
(MessageBodyWriterContext parent) Create a new parented writer context.static MessageBodyWriterContext
create
(MessageBodyWriterContext parent, Headers headers) Create a new parented writer context backed by the specified headers.static MessageBodyWriterContext
create
(MessageBodyWriterContext parent, Parameters headers) Deprecated, for removal: This API element is subject to removal in a future version.Use (@linkcreate(MessageBodyWriterContext, io.helidon.common.http.Headers)
instead passingHeaders
instead ofParameters
.static MessageBodyWriterContext
create
(MessageBodyWriterContext parent, MessageBodyContext.EventListener eventListener, Headers headers, List<MediaType> acceptedTypes) Create a new writer context.static MessageBodyWriterContext
create
(MessageBodyWriterContext parent, MessageBodyContext.EventListener eventListener, Parameters headers, List<MediaType> acceptedTypes) Deprecated, for removal: This API element is subject to removal in a future version.Usecreate(MessageBodyWriterContext, io.helidon.media.common.MessageBodyContext.EventListener, io.helidon.common.http.Headers, java.util.List)
instead, passingHeaders
instead ofParameters
.findAccepted
(MediaType mediaType) Find the given media type in the inboundAccept
header.findAccepted
(Predicate<MediaType> predicate, MediaType defaultType) Find an media type in the inboundAccept
header with the given predicate and default value.headers()
Get the underlying headers.<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.<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.<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.<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.registerWriter
(MessageBodyStreamWriter<?> writer) Register a stream writer.registerWriter
(MessageBodyWriter<?> writer) Register a writer.registerWriter
(Class<T> type, MediaType contentType, Function<? extends T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
insteadregisterWriter
(Class<T> type, Function<T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
insteadregisterWriter
(Predicate<?> accept, MediaType contentType, Function<T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
insteadregisterWriter
(Predicate<?> accept, Function<T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0 useregisterWriter(MessageBodyWriter)
insteadMethods inherited from class io.helidon.media.common.MessageBodyContext
applyFilters, applyFilters, registerFilter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.media.common.MessageBodyFilters
registerFilter
-
Method Details
-
create
@Deprecated(since="3.0.3", forRemoval=true) public static MessageBodyWriterContext create(MediaContext mediaContext, MessageBodyContext.EventListener eventListener, Parameters headers, List<MediaType> acceptedTypes) Deprecated, for removal: This API element is subject to removal in a future version.Usecreate(MediaContext, io.helidon.media.common.MessageBodyContext.EventListener, io.helidon.common.http.Headers, java.util.List)
instead, passingHeaders
instead ofParameters
.Create a new writer context.- Parameters:
mediaContext
- media support used to derive the parent context, may benull
eventListener
- message body subscription event listener, may benull
headers
- backing headers, must not benull
acceptedTypes
- accepted types, may benull
- Returns:
- MessageBodyWriterContext
-
create
public static MessageBodyWriterContext create(MediaContext mediaContext, MessageBodyContext.EventListener eventListener, Headers headers, List<MediaType> acceptedTypes) Create a new writer context.- Parameters:
mediaContext
- media support used to derive the parent context, may benull
eventListener
- message body subscription event listener, may benull
headers
- backing headers, must not benull
acceptedTypes
- accepted types, may benull
- Returns:
- MessageBodyWriterContext
-
create
@Deprecated(since="3.0.3", forRemoval=true) public static MessageBodyWriterContext create(MessageBodyWriterContext parent, MessageBodyContext.EventListener eventListener, Parameters headers, List<MediaType> acceptedTypes) Deprecated, for removal: This API element is subject to removal in a future version.Usecreate(MessageBodyWriterContext, io.helidon.media.common.MessageBodyContext.EventListener, io.helidon.common.http.Headers, java.util.List)
instead, passingHeaders
instead ofParameters
.Create a new writer context.- Parameters:
parent
- parent context,may be null
eventListener
- message body subscription event listener, may benull
headers
- backing headers, must not benull
acceptedTypes
- accepted types, may benull
- Returns:
- MessageBodyWriterContext
-
create
public static MessageBodyWriterContext create(MessageBodyWriterContext parent, MessageBodyContext.EventListener eventListener, Headers headers, List<MediaType> acceptedTypes) Create a new writer context.- Parameters:
parent
- parent context,may be null
eventListener
- message body subscription event listener, may benull
headers
- backing headers, must not benull
acceptedTypes
- accepted types, may benull
- Returns:
- MessageBodyWriterContext
-
create
@Deprecated(since="3.0.3", forRemoval=true) public static MessageBodyWriterContext create(Parameters headers) Deprecated, for removal: This API element is subject to removal in a future version.Create a new empty writer context backed by the specified headers.- Parameters:
headers
- headers- Returns:
- MessageBodyWriterContext
-
create
Create a new empty writer context backed by the specified headers.- Parameters:
headers
- headers- Returns:
- MessageBodyWriterContext
-
create
Create a new parented writer context.- Parameters:
parent
- parent writer context- Returns:
- MessageBodyWriterContext
-
create
@Deprecated(since="3.0.3", forRemoval=true) public static MessageBodyWriterContext create(MessageBodyWriterContext parent, Parameters headers) Deprecated, for removal: This API element is subject to removal in a future version.Use (@linkcreate(MessageBodyWriterContext, io.helidon.common.http.Headers)
instead passingHeaders
instead ofParameters
.Create a new parented writer context backed by the specified headers.- Parameters:
parent
- parent writer contextheaders
- headers- Returns:
- MessageBodyWriterContext
-
create
Create a new parented writer context backed by the specified headers.- Parameters:
parent
- parent writer contextheaders
- headers- Returns:
- 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
-
registerWriter
Description copied from interface:MessageBodyWriters
Register a writer.- Specified by:
registerWriter
in interfaceMessageBodyWriters
- Parameters:
writer
- writer to register- Returns:
- Writers
-
registerWriter
Description copied from interface:MessageBodyWriters
Register a stream writer.- Specified by:
registerWriter
in interfaceMessageBodyWriters
- Parameters:
writer
- writer to register- Returns:
- Writers
-
registerWriter
@Deprecated public <T> MessageBodyWriterContext registerWriter(Class<T> type, Function<T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
insteadRegisters a writer function with a given type.- Type Parameters:
T
- entity type- Parameters:
type
- class representing the type supported by this writerfunction
- writer function- Returns:
- this
MessageBodyWriteableContent
instance
-
registerWriter
@Deprecated public <T> MessageBodyWriterContext registerWriter(Class<T> type, MediaType contentType, Function<? extends T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
insteadRegisters a writer function with a given type and media type.- Type Parameters:
T
- entity type- Parameters:
type
- class representing the type supported by this writercontentType
- the media typefunction
- writer function- Returns:
- this
MessageBodyWriteableContent
instance
-
registerWriter
@Deprecated public <T> MessageBodyWriterContext registerWriter(Predicate<?> accept, Function<T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0 useregisterWriter(MessageBodyWriter)
insteadRegisters a writer function with a given predicate.- Type Parameters:
T
- entity type- Parameters:
accept
- the object predicatefunction
- writer function- Returns:
- this
MessageBodyWriteableContent
instance
-
registerWriter
@Deprecated public <T> MessageBodyWriterContext registerWriter(Predicate<?> accept, MediaType contentType, Function<T, Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
insteadRegisters a writer function with a given predicate and media type.- Type Parameters:
T
- entity type- Parameters:
accept
- the object predicatecontentType
- the media typefunction
- writer function- Returns:
- this
MessageBodyWriteableContent
instance
-
marshall
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 publishertype
- 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 publisherwriter
- specific writertype
- actual representation of the entity type- Returns:
- publisher, never
null
-
marshallStream
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 publishertype
- 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 publisherwriter
- specific writertype
- actual representation of the entity type- Returns:
- publisher, never
null
-
headers
Get the underlying headers.- Returns:
- headers, never
null
-
contentType
Get theContent-Type
header.- Returns:
- Optional, never
null
-
acceptedTypes
Get the inboundAccept
header.- Returns:
- List never
null
-
contentType
Set theContent-Type
header value in the underlying headers if not present.- Parameters:
contentType
-Content-Type
value to set, must not benull
-
contentLength
public void contentLength(long contentLength) Set theContent-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 inboundAccept
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 inboundAccept
header is empty or missing. - When the
Content-Type
header is set, if the predicate matches theContent-Type
header value is returned.
- Parameters:
predicate
- a predicate to match against the inboundAccept
headerdefaultType
- a default media type- Returns:
- MediaType, never
null
- Throws:
IllegalStateException
- if no media type can be returned
-
findAccepted
Find the given media type in the inboundAccept
header.- Parameters:
mediaType
- media type to search for- Returns:
- MediaType, never
null
- Throws:
IllegalStateException
- if the media type is not found
-
charset
Description copied from class:MessageBodyContext
Derive the charset to use from theContent-Type
header value or using a default charset as fallback.- Specified by:
charset
in classMessageBodyContext
- Returns:
- Charset, never
null
- Throws:
IllegalStateException
- if an error occurs loading the charset specified by theContent-Type
header value
-
create(io.helidon.common.http.Headers)
instead, passingHeaders
instead ofParameters
.