- 
- All Superinterfaces:
- MessageBodyFilters,- MessageBodyWriters
 
 public interface ServerResponse extends MessageBodyFilters, MessageBodyWriters Represents HTTP Response.LifecycleHTTP response is send to the client in two or more steps (chunks). First containsHTTP status codeandheaders. First part can be send explicitly by callingResponseHeaders.send()method or implicitly by sending a first part of the the response content. As soon as first part is send it become immutable -status(int)method and all muting operations ofResponseHeaderswill throwIllegalStateException.Response content (body/payload) can be constructed using send(...)methods.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Interface Description static classServerResponse.CachingStrategyDeclares common groups ofCache-Controlsettings.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default ServerResponseaddHeader(String name, Iterable<String> values)Adds header values for a specified name.default ServerResponseaddHeader(String name, String... values)Adds header values for a specified name.default ServerResponseaddHeaders(Parameters parameters)Copies all of the mappings from the specifiedparametersto this response headers instance.default ServerResponsecachingStrategy(ServerResponse.CachingStrategy cachingStrategy)Sets theCache-Controlheader values according to the specified strategy.ResponseHeadersheaders()Returns response headers.ServerResponseregisterFilter(MessageBodyFilter filter)Registers a message body filter.ServerResponseregisterFilter(Function<Flow.Publisher<DataChunk>,Flow.Publisher<DataChunk>> function)Deprecated.since 2.0.0, useregisterFilter(io.helidon.media.common.MessageBodyFilter)insteadServerResponseregisterWriter(MessageBodyStreamWriter<?> writer)Register a stream writer.ServerResponseregisterWriter(MessageBodyWriter<?> writer)Register a writer.<T> ServerResponseregisterWriter(Class<T> type, MediaType contentType, Function<? extends T,Flow.Publisher<DataChunk>> function)Deprecated.since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)instead<T> ServerResponseregisterWriter(Class<T> type, Function<T,Flow.Publisher<DataChunk>> function)Deprecated.Since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)instead<T> ServerResponseregisterWriter(Predicate<?> accept, MediaType contentType, Function<T,Flow.Publisher<DataChunk>> function)Deprecated.since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)instead<T> ServerResponseregisterWriter(Predicate<?> accept, Function<T,Flow.Publisher<DataChunk>> function)Deprecated.since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)insteadlongrequestId()A unique correlation ID that is associated with this response and its associated request.Single<ServerResponse>send()Sends an empty response.Voidsend(Throwable content)Send aThrowableand close the response.Single<ServerResponse>send(Flow.Publisher<DataChunk> content)Send a message as is without any other marshalling, registered filters are applied.Single<ServerResponse>send(Flow.Publisher<DataChunk> content, boolean applyFilters)Send a message as is without any other marshalling.<T> Single<ServerResponse>send(Flow.Publisher<T> content, Class<T> clazz)Send a message with the given entity stream as content and close the response.Single<ServerResponse>send(Function<MessageBodyWriterContext,Flow.Publisher<DataChunk>> function)Send a message using the given marshalling function.<T> Single<ServerResponse>send(T content)Send a message and close the response.Http.ResponseStatusstatus()Returns actual response status code.default ServerResponsestatus(int statusCode)Sets new HTTP status code.ServerResponsestatus(Http.ResponseStatus status)Sets new HTTP status.WebServerwebServer()Returns actualWebServerinstance.Single<ServerResponse>whenSent()Completion stage is completed when response is completed.MessageBodyWriterContextwriterContext()Get the writer context used to marshall data.
 
- 
- 
- 
Method Detail- 
webServerWebServer webServer() Returns actualWebServerinstance.- Returns:
- an actual WebServerinstance
 
 - 
statusHttp.ResponseStatus status() Returns actual response status code.Default value for handlers is 200and for failure handlers500. Value can be redefined usingstatus(int)method before headers are send.- Returns:
- an HTTP status code
 
 - 
statusdefault ServerResponse status(int statusCode) throws AlreadyCompletedException Sets new HTTP status code. Can be done before headers are completed - seeResponseHeadersdocumentation.- Parameters:
- statusCode- new status code
- Returns:
- this instance of ServerResponse
- Throws:
- AlreadyCompletedException- if headers were completed (sent to the client)
 
 - 
statusServerResponse status(Http.ResponseStatus status) throws AlreadyCompletedException, NullPointerException Sets new HTTP status. Can be done before headers are completed - seeResponseHeadersdocumentation.- Parameters:
- status- new status
- Returns:
- this instance of ServerResponse
- Throws:
- AlreadyCompletedException- if headers were completed (sent to the client)
- NullPointerException- if status parameter is- null
 
 - 
headersResponseHeaders headers() Returns response headers. It can be modified before headers are sent to the client.- Returns:
- a response headers
 
 - 
addHeaderdefault ServerResponse addHeader(String name, String... values) Adds header values for a specified name.- Parameters:
- name- header name
- values- header values
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if the specified name is null.
- See Also:
- headers(),- Parameters.add(String, String...),- header names constants
 
 - 
addHeaderdefault ServerResponse addHeader(String name, Iterable<String> values) Adds header values for a specified name.- Parameters:
- name- header name
- values- header values
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if the specified name is null.
- See Also:
- headers(),- Parameters.add(String, Iterable),- header names constants
 
 - 
addHeadersdefault ServerResponse addHeaders(Parameters parameters) Copies all of the mappings from the specifiedparametersto this response headers instance.- Parameters:
- parameters- to copy.
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if the specified- parametersare null.
- See Also:
- headers(),- Parameters.addAll(Parameters)
 
 - 
cachingStrategydefault ServerResponse cachingStrategy(ServerResponse.CachingStrategy cachingStrategy) Sets theCache-Controlheader values according to the specified strategy.- Parameters:
- cachingStrategy-- ServerResponse.CachingStrategyto apply to this response
- Returns:
- updated response
 
 - 
writerContextMessageBodyWriterContext writerContext() Get the writer context used to marshall data.- Returns:
- MessageBodyWriterContext
 
 - 
sendVoid send(Throwable content) Send aThrowableand close the response. Invokes error handlers if defined.- Parameters:
- content- the- Throwableto send
- Returns:
- nullwhen invoked
- Throws:
- IllegalStateException- if any- send(...)method was already called
- See Also:
- send(Object)
 
 - 
send<T> Single<ServerResponse> send(T content) Send a message and close the response.MarshallingData are marshaled using default orregisteredwriterto the format ofByteBufferPublisher. The last registered compatible writer is used.Default writers supports: - CharSequence
- byte[]
- Path
- File
 BlockingThe method blocks only during marshalling. It means untilregistered writerproduce aPublisherand subscribe HTTP IO implementation on it. If the thread is used for publishing is up to HTTP IO and generated Publisher implementations. Use returnedSingleto monitor and react on finished sending process.- Type Parameters:
- T- a type of the content
- Parameters:
- content- a response content to send
- Returns:
- a completion stage of the response - completed when response is transferred
- Throws:
- IllegalArgumentException- if there is no registered writer for a given type
- IllegalStateException- if any- send(...)method was already called
 
 - 
send<T> Single<ServerResponse> send(Flow.Publisher<T> content, Class<T> clazz) Send a message with the given entity stream as content and close the response.- Type Parameters:
- T- entity type
- Parameters:
- content- entity stream
- clazz- class representing the entity type
- Returns:
- a completion stage of the response - completed when response is transferred
 
 - 
sendSingle<ServerResponse> send(Flow.Publisher<DataChunk> content) Send a message as is without any other marshalling, registered filters are applied. The response is completed when publisher sendFlow.Subscriber.onComplete()method to its subscriber.A single Subscribersubscribes to the providedPublisherduring the method execution.BlockingIf the thread is used for publishing is up to HTTP IO and generated Publisher implementations. Use returnedSingleto monitor and react on finished sending process.- Parameters:
- content- a response content publisher
- Returns:
- a completion stage of the response - completed when response is transferred
- Throws:
- IllegalStateException- if any- send(...)method was already called
 
 - 
sendSingle<ServerResponse> send(Flow.Publisher<DataChunk> content, boolean applyFilters) Send a message as is without any other marshalling. The response is completed when publisher sendFlow.Subscriber.onComplete()method to its subscriber.A single Subscribersubscribes to the providedPublisherduring the method execution.BlockingIf the thread is used for publishing is up to HTTP IO and generated Publisher implementations. Use returnedSingleto monitor and react on finished sending process.- Parameters:
- content- a response content publisher
- applyFilters- if true all registered filters are applied
- Returns:
- a completion stage of the response - completed when response is transferred
- Throws:
- IllegalStateException- if any- send(...)method was already called
 
 - 
sendSingle<ServerResponse> send(Function<MessageBodyWriterContext,Flow.Publisher<DataChunk>> function) Send a message using the given marshalling function.- Parameters:
- function- marshalling function
- Returns:
- a completion stage of the response - completed when response is transferred
 
 - 
sendSingle<ServerResponse> send() Sends an empty response. Do nothing if response was already send.- Returns:
- a completion stage of the response - completed when response is transferred
 
 - 
registerWriter@Deprecated(since="2.0.0") <T> ServerResponse registerWriter(Class<T> type, Function<T,Flow.Publisher<DataChunk>> function) Deprecated.Since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)insteadRegisters a content writer for a given type.Registered writer is used to marshal response content of given type to the Publisherofresponse chunks.- Type Parameters:
- T- a type of the content
- Parameters:
- type- a type of the content. If- nullthen accepts any type.
- function- a writer function
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if- functionparameter is- null
 
 - 
registerWriter@Deprecated(since="2.0.0") <T> ServerResponse registerWriter(Class<T> type, MediaType contentType, Function<? extends T,Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)insteadRegisters a content writer for a given type and media type.Registered writer is used to marshal response content of given type to the Publisherofresponse chunks. It is used only ifContent-Typeheader is compatible with a given content type or if it isnull. IfContent-Typeisnulland it is still possible to modify headers (headers were not send yet), the provided content type will be set.- Type Parameters:
- T- a type of the content
- Parameters:
- type- a type of the content. If- nullthen accepts any type.
- contentType- a- Content-Typeof the entity
- function- a writer function
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if- functionparameter is- null
 
 - 
registerWriter@Deprecated <T> ServerResponse registerWriter(Predicate<?> accept, Function<T,Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)insteadRegisters a content writer for all accepted contents.Registered writer is used to marshal response content of given type to the Publisherofresponse chunks.- Type Parameters:
- T- a type of the content
- Parameters:
- accept- a predicate to test if content is marshallable by the writer. If- nullthen accepts any type.
- function- a writer function
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if- functionparameter is- null
 
 - 
registerWriter@Deprecated <T> ServerResponse registerWriter(Predicate<?> accept, MediaType contentType, Function<T,Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterWriter(io.helidon.media.common.MessageBodyWriter)insteadRegisters a content writer for all accepted contents.Registered writer is used to marshal response content of given type to the Publisherofresponse chunks. It is used only ifContent-Typeheader is compatible with a given content type or if it isnull. IfContent-Typeisnulland it is still possible to modify headers (headers were not send yet), the provided content type will be set.- Type Parameters:
- T- a type of the content
- Parameters:
- accept- a predicate to test if content is marshallable by the writer. If- nullthen accepts any type.
- contentType- a- Content-Typeof the entity
- function- a writer function
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if- functionparameter is- null
 
 - 
registerFilter@Deprecated ServerResponse registerFilter(Function<Flow.Publisher<DataChunk>,Flow.Publisher<DataChunk>> function) Deprecated.since 2.0.0, useregisterFilter(io.helidon.media.common.MessageBodyFilter)insteadRegisters a provider of the new response content publisher - typically a filter.All response content is always represented by a single Publisherofresponse chunks. This method can be used to filter or completely replace original publisher by a new one with different contract. For example data coding, logging, filtering, caching, etc.New publisher is created at the moment of content write by any send(...)method including the empty one.All registered filters are used as a chain from original content Publisher, first registered to the last registered.- Parameters:
- function- a function to map previously registered or original- Publisherto the new one. If returns- nullthen the result will be ignored.
- Returns:
- this instance of ServerResponse
- Throws:
- NullPointerException- if parameter- functionis- null
 
 - 
registerFilterServerResponse registerFilter(MessageBodyFilter filter) Description copied from interface:MessageBodyFiltersRegisters a message body filter.The registered filters are applied to form a chain from the first registered to the last registered. The first evaluation of the function transforms the original publisher to a new publisher. Any subsequent evaluation receives the publisher transformed by the last previously registered filter. - Specified by:
- registerFilterin interface- MessageBodyFilters
- Parameters:
- filter- a function to map previously registered or original- Publisherto the new one. If returns- nullthen the result will be ignored.
- Returns:
- this instance of MessageBodyFilters
- See Also:
- MessageBodyContext.applyFilters(Flow.Publisher)
 
 - 
registerWriterServerResponse registerWriter(MessageBodyWriter<?> writer) Description copied from interface:MessageBodyWritersRegister a writer.- Specified by:
- registerWriterin interface- MessageBodyWriters
- Parameters:
- writer- writer to register
- Returns:
- Writers
 
 - 
registerWriterServerResponse registerWriter(MessageBodyStreamWriter<?> writer) Description copied from interface:MessageBodyWritersRegister a stream writer.- Specified by:
- registerWriterin interface- MessageBodyWriters
- Parameters:
- writer- writer to register
- Returns:
- Writers
 
 - 
whenSentSingle<ServerResponse> whenSent() Completion stage is completed when response is completed.It can be used to react on the response completion without invocation of a closing event. - Returns:
- a completion stage of the response
 
 - 
requestIdlong requestId() A unique correlation ID that is associated with this response and its associated request.- Returns:
- a unique correlation ID associated with this response and its request
 
 
- 
 
-