Interface RoutingResponse
- All Superinterfaces:
ServerResponse
- All Known Implementing Classes:
ServerResponseBase
-
Method Summary
Modifier and TypeMethodDescriptiondefault RoutingResponseautomaticContentEncoding(boolean enabled) Configure whether the WebServer response layer may automatically encode the response entity using the listener content encoding context.voidcommit()Commit the response.default RoutingResponsecontentEncoder(ContentEncoder encoder) Configure an explicit response content encoder.default voidentityBeforeSend(Runnable listener) Register an infrastructure listener associated with the current response entity.default voidentityStreamFilter(UnaryOperator<OutputStream> filterFunction) Configure an infrastructure output stream filter associated with the current response entity.booleanWhether this request has an entity.booleanisNexted()Whether this request is nexted (ServerResponse.next()was called).reroutePrologue(HttpPrologue prologue) A new, rerouted prologue.booleanreset()Return true if the underlying response buffers and headers can be reset and a new response can be sent.default booleanReset the response entity so an unsent response can be replaced while preserving response metadata unrelated to the entity, such as CORS, cookies, cache controls, andVaryheaders.voidReset routing information (nexted, rerouted etc.).default booleanReturn true if the underlying response buffers can be reset and a new response can be sent.booleanShould we reroute this exchange.Methods inherited from interface ServerResponse
beforeSend, beforeTrailers, bytesWritten, contentLength, header, header, header, headers, isResponseHandled, isSent, next, outputStream, reroute, reroute, send, send, send, send, send, sink, status, status, status, streamFilter, streamResult, trailers, whenSentModifier and TypeMethodDescriptiondefault ServerResponsebeforeSend(Runnable listener) Executed right before the first byte is written to the socket (including response status and headers).default ServerResponsebeforeTrailers(Consumer<ServerResponseTrailers> beforeTrailers) Callback to update any last minute trailers before they are written to the output stream.longNumber of bytes written to response.default voidcontentLength(long length) Configure a content length header for this response.Set header with a value.default ServerResponseheader(HeaderName name, String... values) Set a header.default ServerResponseNot optimized method for setting a header.headers()Response headers (mutable).default booleanWhether this response has already been handled by the application.booleanisSent()Whether this response has been sent.next()Continue processing with the next route (and if none found, return aStatus.NOT_FOUND_404).Alternative way to send an entity, using an output stream.Re-route using a different path.Re-route using a different path and query.voidsend()Send a response with no entity.voidsend(byte[] bytes) Send a byte array response.default voidsend(byte[] bytes, int position, int length) Send a byte array response.voidSend an entity, aMediaContextwill be used to serialize the entity.default voidSend an entity if present, throwNotFoundExceptionif empty.default <T extends Sink<?>>
Tsink(GenericType<T> sinkType) Returns a sink from this response based on the sink type.status()Configured HTTP status, if not configured, returnsStatus.OK_200.default ServerResponsestatus(int status) Status of the response.Status of the response.voidstreamFilter(UnaryOperator<OutputStream> filterFunction) Configure a custom output stream to wrap the output stream of the response.voidstreamResult(String result) Description of the result of output stream processing.trailers()Response trailers (mutable).Completed when last byte is buffered for socket write.
-
Method Details
-
resetRouting
void resetRouting()Reset routing information (nexted, rerouted etc.). -
shouldReroute
boolean shouldReroute()Should we reroute this exchange.- Returns:
- whether rerouting was requested
-
reroutePrologue
A new, rerouted prologue.- Parameters:
prologue- current prologue- Returns:
- prologue to use when rerouting
-
isNexted
boolean isNexted()Whether this request is nexted (ServerResponse.next()was called).- Returns:
- if nexted
-
hasEntity
boolean hasEntity()Whether this request has an entity.- Returns:
- whether has entity
-
automaticContentEncoding
Configure whether the WebServer response layer may automatically encode the response entity using the listener content encoding context. This does not remove or rewrite any explicitly configuredContent-Encodingheader. Repeated calls replace the previous setting until response content encoding is selected.- Specified by:
automaticContentEncodingin interfaceServerResponse- Parameters:
enabled- whether automatic response content encoding is enabled- Returns:
- this instance
- Throws:
IllegalStateException- if response content encoding was already selected, or the response was sent
-
contentEncoder
Configure an explicit response content encoder. Repeated calls replace the previous encoder until response content encoding is selected. The selected encoder's headers are applied once during selection.- Specified by:
contentEncoderin interfaceServerResponse- Parameters:
encoder- content encoder- Returns:
- this instance
- Throws:
NullPointerException- ifencoderisnullIllegalStateException- if response content encoding was already selected, or the response was sent
-
reset
boolean reset()Return true if the underlying response buffers and headers can be reset and a new response can be sent.- Returns:
trueif reset was successful and a new response can be created instead of the existing one,falseif reset failed and status and headers (and maybe entity bytes) were already sent
-
commit
void commit()Commit the response. This is mostly useful for output stream based responses, where we may want to delay closing the output stream to handle errors, when route uses try with resources. After this method is called, response cannot bereset(). -
resetStream
default boolean resetStream()Return true if the underlying response buffers can be reset and a new response can be sent.As opposed to
reset(), this method is not expected to reset headers already configured on the responseThis method calls
reset()by default.- Returns:
trueif reset was successful and a new response can be created instead of the existing one,falseif reset failed and status and headers (and maybe entity bytes) were already sent
-
resetEntity
default boolean resetEntity()Reset the response entity so an unsent response can be replaced while preserving response metadata unrelated to the entity, such as CORS, cookies, cache controls, andVaryheaders.This method is intended for Helidon infrastructure that replaces a failed response entity.
Implementations that track entity metadata must override this method to reset entity buffers and remove framing, representation, validator, range, and trailer headers. Implementations with separate trailer state must reset that state as well. This method does not change the response status. An error handler that replaces the entity is responsible for configuring or deliberately retaining an appropriate status before sending the replacement response.
For compatibility with existing
RoutingResponseimplementations, the default implementation callsresetStream().- Returns:
trueif reset was successful and a new entity can be created instead of the existing one,falseif reset failed and status and headers (and maybe entity bytes) were already sent
-
entityStreamFilter
Configure an infrastructure output stream filter associated with the current response entity.Implementations which distinguish entity-scoped filters remove the filter if error handling replaces the unsent entity. Application filters should use
ServerResponse.streamFilter(UnaryOperator)so they also apply to a replacement error response. The default fallback registers the filter through the public method and therefore retains it.- Parameters:
filterFunction- function that wraps the response output stream
-
entityBeforeSend
Register an infrastructure listener associated with the current response entity.Implementations which distinguish entity-scoped listeners remove the listener if error handling replaces the unsent entity. Application listeners should use
ServerResponse.beforeSend(Runnable)so they also apply to a replacement error response. The default fallback registers the listener through the public method and therefore retains it.- Parameters:
listener- listener invoked before the response is sent
-