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 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
-
Constructor Summary
ModifierConstructorDescriptionprotected
DefaultServletHttpResponse
(io.micronaut.core.convert.ConversionService conversionService, DefaultServletHttpRequest<B> request, jakarta.servlet.http.HttpServletResponse delegate) Default constructor. -
Method Summary
Modifier and TypeMethodDescription<T> io.micronaut.http.MutableHttpResponse<T>
body
(T body) int
code()
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.MutableHttpHeaders
jakarta.servlet.http.HttpServletResponse
Returns anOutputStream
that can be used to write the body of the response.Returns aBufferedWriter
that can be used to write the text body of the response.io.micronaut.http.MutableHttpResponse<B>
header
(CharSequence name, CharSequence value) 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) 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, wait
Methods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttribute
Methods inherited from interface io.micronaut.http.HttpMessage
getBody, getBody, getBody, getBodyWriter, getCharacterEncoding, getContentLength, getLocale
Methods inherited from interface io.micronaut.http.HttpResponse
body, getCookie, getCookies, getStatus, header, setAttribute, status
Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
Methods inherited from interface io.micronaut.http.MutableHttpMessage
basicAuth, bearerAuth, bodyWriter
Methods inherited from interface io.micronaut.http.MutableHttpResponse
attribute, characterEncoding, characterEncoding, contentEncoding, cookies, headers, headers, status, toMutableResponse
-
Constructor Details
-
DefaultServletHttpResponse
protected DefaultServletHttpResponse(io.micronaut.core.convert.ConversionService conversionService, DefaultServletHttpRequest<B> request, jakarta.servlet.http.HttpServletResponse delegate) Default constructor.- Parameters:
conversionService
- The conversion servicerequest
- The servlet requestdelegate
- The servlet response
-
-
Method Details
-
stream
public org.reactivestreams.Publisher<io.micronaut.http.MutableHttpResponse<?>> stream(org.reactivestreams.Publisher<?> dataPublisher) Description copied from interface:ServletHttpResponse
Streams data using the given data publisher.- Specified by:
stream
in interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,
B> - Parameters:
dataPublisher
- The data publisher- Returns:
- Emits the response once the stream has completed
-
getContentType
- Specified by:
getContentType
in interfaceio.micronaut.http.HttpMessage<B>
-
contentType
-
contentType
-
contentLength
-
locale
- Specified by:
locale
in interfaceio.micronaut.http.MutableHttpResponse<B>
-
header
-
status
- Specified by:
status
in interfaceio.micronaut.http.MutableHttpResponse<B>
-
status
- Specified by:
status
in interfaceio.micronaut.http.MutableHttpResponse<B>
-
getNativeResponse
public jakarta.servlet.http.HttpServletResponse getNativeResponse()- Specified by:
getNativeResponse
in interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,
B> - Returns:
- The native response type.
-
getOutputStream
Description copied from interface:ServletHttpResponse
Returns anOutputStream
that 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:
getOutputStream
in interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,
B> - Returns:
- The output stream
- Throws:
IOException
- if a validOutputStream
cannot be returned for some reason.
-
getWriter
Description copied from interface:ServletHttpResponse
Returns aBufferedWriter
that 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:
getWriter
in interfaceServletHttpResponse<jakarta.servlet.http.HttpServletResponse,
B> - Returns:
- The writer
- Throws:
IOException
- if a validBufferedWriter
cannot be returned for some reason.
-
cookie
- Specified by:
cookie
in 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:
getAttributes
in interfaceio.micronaut.core.attr.AttributeHolder
- Specified by:
getAttributes
in interfaceio.micronaut.http.HttpMessage<B>
- Specified by:
getAttributes
in interfaceio.micronaut.core.attr.MutableAttributeHolder
-
getBody
- Specified by:
getBody
in interfaceio.micronaut.http.HttpMessage<B>
-
body
public <T> io.micronaut.http.MutableHttpResponse<T> body(@Nullable T body) -
status
- Specified by:
status
in interfaceio.micronaut.http.MutableHttpResponse<B>
-
code
public int code()- Specified by:
code
in interfaceio.micronaut.http.HttpResponse<B>
-
reason
- Specified by:
reason
in interfaceio.micronaut.http.HttpResponse<B>
-