Package io.micronaut.servlet.engine
Class DefaultServletHttpResponse<B>
java.lang.Object
io.micronaut.servlet.engine.DefaultServletHttpResponse<B>
- Type Parameters:
B- The body type
- All Implemented Interfaces:
io.micronaut.core.attr.AttributeHolder,io.micronaut.core.attr.MutableAttributeHolder,io.micronaut.http.HttpMessage<B>,io.micronaut.http.HttpResponse<B>,io.micronaut.http.MutableHttpMessage<B>,io.micronaut.http.MutableHttpResponse<B>,ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
@Internal
public final class DefaultServletHttpResponse<B>
extends Object
implements ServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B>
Implementation of
ServletHttpResponse for the Servlet API.- Since:
- 1.0.0
- Author:
- graemerocher
-
Method Summary
Modifier and TypeMethodDescription<T> io.micronaut.http.MutableHttpResponse<T> body(T body) intcode()io.micronaut.http.MutableHttpResponse<B> contentLength(long length) io.micronaut.http.MutableHttpResponse<B> contentType(io.micronaut.http.MediaType mediaType) io.micronaut.http.MutableHttpResponse<B> contentType(CharSequence contentType) io.micronaut.http.MutableHttpResponse<B> cookie(io.micronaut.http.cookie.Cookie cookie) @NonNull io.micronaut.core.convert.value.MutableConvertibleValues<Object> getBody()@NonNull Optional<io.micronaut.http.MediaType> @NonNull io.micronaut.http.MutableHttpHeadersjakarta.servlet.http.HttpServletResponseReturns anOutputStreamthat can be used to write the body of the response.Returns aBufferedWriterthat can be used to write the text body of the response.io.micronaut.http.MutableHttpResponse<B> header(CharSequence name, CharSequence value) booleanIf native response is commited and cannot be modified anymore.io.micronaut.http.MutableHttpResponse<B> reason()io.micronaut.http.MutableHttpResponse<B> status(int status) io.micronaut.http.MutableHttpResponse<B> status(int status, CharSequence message) io.micronaut.http.MutableHttpResponse<B> status(io.micronaut.http.HttpStatus status) stream(io.micronaut.http.body.CloseableByteBody body) Stream data from the given ByteBody.org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>> stream(org.reactivestreams.Publisher<?> dataPublisher) Streams data using the given data publisher.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttributeMethods inherited from interface io.micronaut.http.HttpMessage
getBody, getBody, getBody, getBodyWriter, getCharacterEncoding, getContentLength, getLocaleMethods inherited from interface io.micronaut.http.HttpResponse
body, getCookie, getCookies, getStatus, header, setAttribute, statusMethods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttributeMethods inherited from interface io.micronaut.http.MutableHttpMessage
basicAuth, bearerAuth, bodyWriterMethods inherited from interface io.micronaut.http.MutableHttpResponse
attribute, cacheControl, characterEncoding, characterEncoding, contentEncoding, cookies, headers, headers, status, toMutableResponse
-
Method Details
-
isCommitted
public boolean isCommitted()Description copied from interface:ServletHttpResponseIf native response is commited and cannot be modified anymore.- Specified by:
isCommittedin interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B> - Returns:
- Is commited native response
-
stream
public org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>> stream(org.reactivestreams.Publisher<?> dataPublisher) Description copied from interface:ServletHttpResponseStreams data using the given data publisher.- Specified by:
streamin interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B> - Parameters:
dataPublisher- The data publisher- Returns:
- Emits the response once the stream has completed
-
stream
Description copied from interface:ServletHttpResponseStream data from the given ByteBody.- Specified by:
streamin interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B> - Parameters:
body- The body to write- Returns:
- A future that completes when the body is fully written
-
getContentType
- Specified by:
getContentTypein interfaceio.micronaut.http.HttpMessage<B>
-
contentType
-
contentType
-
contentLength
-
locale
- Specified by:
localein interfaceio.micronaut.http.MutableHttpResponse<B>
-
header
-
status
- Specified by:
statusin interfaceio.micronaut.http.MutableHttpResponse<B>
-
status
- Specified by:
statusin interfaceio.micronaut.http.MutableHttpResponse<B>
-
getNativeResponse
public jakarta.servlet.http.HttpServletResponse getNativeResponse()- Specified by:
getNativeResponsein interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B> - Returns:
- The native response type.
-
getOutputStream
Description copied from interface:ServletHttpResponseReturns anOutputStreamthat can be used to write the body of the response. This method is typically used to write binary data. If the body is text, theServletHttpResponse.getWriter()method is more appropriate.- Specified by:
getOutputStreamin interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B> - Returns:
- The output stream
- Throws:
IOException- if a validOutputStreamcannot be returned for some reason.
-
getWriter
Description copied from interface:ServletHttpResponseReturns aBufferedWriterthat can be used to write the text body of the response. If the written text will not be US-ASCII, you should specify a character encoding by callingMutableHttpResponse.contentEncoding(CharSequence)before calling this method.- Specified by:
getWriterin interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,B> - Returns:
- The writer
- Throws:
IOException- if a validBufferedWritercannot be returned for some reason.
-
cookie
- Specified by:
cookiein interfaceio.micronaut.http.MutableHttpResponse<B>
-
getHeaders
@NonNull public @NonNull io.micronaut.http.MutableHttpHeaders getHeaders() -
getAttributes
@NonNull public @NonNull io.micronaut.core.convert.value.MutableConvertibleValues<Object> getAttributes()- Specified by:
getAttributesin interfaceio.micronaut.core.attr.AttributeHolder- Specified by:
getAttributesin interfaceio.micronaut.http.HttpMessage<B>- Specified by:
getAttributesin interfaceio.micronaut.core.attr.MutableAttributeHolder
-
getBody
- Specified by:
getBodyin interfaceio.micronaut.http.HttpMessage<B>
-
body
public <T> io.micronaut.http.MutableHttpResponse<T> body(@Nullable T body) -
status
- Specified by:
statusin interfaceio.micronaut.http.MutableHttpResponse<B>
-
code
public int code()- Specified by:
codein interfaceio.micronaut.http.HttpResponse<B>
-
reason
- Specified by:
reasonin interfaceio.micronaut.http.HttpResponse<B>
-