- 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 ofMessageBodyWriters
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.helidon.media.common.MessageBodyContext
MessageBodyContext.ErrorEvent, MessageBodyContext.Event, MessageBodyContext.EventListener, MessageBodyContext.EventType
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description List<MediaType>
acceptedTypes()
Get the inboundAccept
header.Charset
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.Optional<MediaType>
contentType()
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(Parameters headers)
Create a new empty writer context backed by the specified headers.static MessageBodyWriterContext
create(MediaContext mediaContext, MessageBodyContext.EventListener eventListener, Parameters headers, List<MediaType> acceptedTypes)
Create a new writer context.static MessageBodyWriterContext
create(MessageBodyWriterContext parent)
Create a new parented writer context.static MessageBodyWriterContext
create(MessageBodyWriterContext parent, Parameters headers)
Create a new parented writer context backed by the specified headers.static MessageBodyWriterContext
create(MessageBodyWriterContext parent, MessageBodyContext.EventListener eventListener, Parameters headers, List<MediaType> acceptedTypes)
Create a new writer context.MediaType
findAccepted(MediaType mediaType)
Find the given media type in the inboundAccept
header.MediaType
findAccepted(Predicate<MediaType> predicate, MediaType defaultType)
Find an media type in the inboundAccept
header with the given predicate and default value.Parameters
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.MessageBodyWriterContext
registerWriter(MessageBodyStreamWriter<?> writer)
Register a stream writer.MessageBodyWriterContext
registerWriter(MessageBodyWriter<?> writer)
Register a writer.<T> MessageBodyWriterContext
registerWriter(Class<T> type, MediaType contentType, Function<? extends T,Flow.Publisher<DataChunk>> function)
Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
instead<T> MessageBodyWriterContext
registerWriter(Class<T> type, Function<T,Flow.Publisher<DataChunk>> function)
Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
instead<T> MessageBodyWriterContext
registerWriter(Predicate<?> accept, MediaType contentType, Function<T,Flow.Publisher<DataChunk>> function)
Deprecated.since 2.0.0, useregisterWriter(MessageBodyWriter)
instead<T> MessageBodyWriterContext
registerWriter(Predicate<?> accept, Function<T,Flow.Publisher<DataChunk>> function)
Deprecated.since 2.0.0 useregisterWriter(MessageBodyWriter)
instead-
Methods 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 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 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(MessageBodyWriterContext parent, MessageBodyContext.EventListener eventListener, Parameters 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
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(MessageBodyWriterContext parent)
Create a new parented writer context.- Parameters:
parent
- parent writer context- Returns:
- MessageBodyWriterContext
-
create
public static MessageBodyWriterContext create(MessageBodyWriterContext parent, Parameters headers)
Create a new parented writer context backed by the specified headers.- Parameters:
parent
- parent writer contextheaders
- 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
-
registerWriter
public MessageBodyWriterContext registerWriter(MessageBodyWriter<?> writer)
Description copied from interface:MessageBodyWriters
Register a writer.- Specified by:
registerWriter
in interfaceMessageBodyWriters
- Parameters:
writer
- writer to register- Returns:
- Writers
-
registerWriter
public MessageBodyWriterContext registerWriter(MessageBodyStreamWriter<?> writer)
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
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 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
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 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
public Parameters headers()
Get the underlying headers.- Returns:
- Parameters, never
null
-
contentType
public Optional<MediaType> contentType()
Get theContent-Type
header.- Returns:
- Optional, never
null
-
acceptedTypes
public List<MediaType> acceptedTypes()
Get the inboundAccept
header.- Returns:
- List never
null
-
contentType
public void contentType(MediaType 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
public MediaType findAccepted(MediaType mediaType) throws IllegalStateException
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
public Charset charset() throws IllegalStateException
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
-
-