Package io.micronaut.http.netty
Class NettyMutableHttpResponse<B>
java.lang.Object
io.micronaut.http.netty.NettyMutableHttpResponse<B>
- Type Parameters:
B
- The response body
- All Implemented Interfaces:
AttributeHolder
,MutableAttributeHolder
,HttpMessage<B>
,HttpResponse<B>
,MutableHttpMessage<B>
,MutableHttpResponse<B>
,NettyHttpResponseBuilder
@Internal
public final class NettyMutableHttpResponse<B>
extends Object
implements MutableHttpResponse<B>, NettyHttpResponseBuilder
Delegates to Netty's
FullHttpResponse
.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
ConstructorDescriptionNettyMutableHttpResponse
(ConversionService conversionService) NettyMutableHttpResponse
(io.netty.handler.codec.http.FullHttpResponse nettyResponse, ConversionService conversionService) NettyMutableHttpResponse
(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, ConversionService conversionService) Creates a new instance.NettyMutableHttpResponse
(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, io.netty.handler.codec.http.HttpHeaders nettyHeaders, Object body, ConversionService conversionService) Creates a new instance.NettyMutableHttpResponse
(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, Object body, ConversionService conversionService) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescription<T> MutableHttpResponse<T>
body
(T body) Sets the body.bodyWriter
(MessageBodyWriter<B> messageBodyWriter) Sets the message body writer to use.int
code()
contentType
(MediaType mediaType) Set the response content type.Adds the specified cookie to the response.Adds the specified cookies to the response.AMutableConvertibleValues
of the attributes for this HTTP message.getBody()
<T> Optional<T>
getBody
(ArgumentConversionContext<T> conversionContext) Return the body, will use the provided conversion context if needed.<T1> Optional<T1>
Return the body as the given type.io.netty.handler.codec.http.HttpHeaders
The netty headers.io.netty.handler.codec.http.HttpResponseStatus
The netty http response status.io.netty.handler.codec.http.HttpVersion
The netty http version.boolean
isStream()
reason()
setAttribute
(CharSequence name, Object value) Sets an attribute on the message.status
(int status, CharSequence message) Sets the response status.@NonNull io.netty.handler.codec.http.FullHttpResponse
Converts this object to a full http response.@NonNull io.netty.handler.codec.http.HttpResponse
Converts this object to the most appropriate http response type.Converts this object to a streamed http response.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttribute
Methods inherited from interface io.micronaut.http.HttpMessage
getBody, getCharacterEncoding, getContentLength, getContentType, getLocale
Methods inherited from interface io.micronaut.http.HttpResponse
body, getCookie, getCookies, getStatus, header, status
Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
Methods inherited from interface io.micronaut.http.MutableHttpMessage
basicAuth, bearerAuth
Methods inherited from interface io.micronaut.http.MutableHttpResponse
attribute, characterEncoding, characterEncoding, contentEncoding, contentLength, contentType, header, headers, headers, locale, status, status, status, toMutableResponse
-
Constructor Details
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.FullHttpResponse nettyResponse, ConversionService conversionService) - Parameters:
nettyResponse
- TheFullHttpResponse
conversionService
- The conversion service
-
NettyMutableHttpResponse
- Parameters:
conversionService
- The conversion service
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, ConversionService conversionService) Creates a new instance.- Parameters:
httpVersion
- The http versionhttpResponseStatus
- THe http response statusconversionService
- The conversion service
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, Object body, ConversionService conversionService) Creates a new instance.- Parameters:
httpVersion
- The http versionhttpResponseStatus
- THe http response statusbody
- The bodyconversionService
- The conversion service
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, io.netty.handler.codec.http.HttpHeaders nettyHeaders, Object body, ConversionService conversionService) Creates a new instance.- Parameters:
httpVersion
- The http versionhttpResponseStatus
- THe http response statusnettyHeaders
- The http headersbody
- The bodyconversionService
- The conversion service
-
-
Method Details
-
getBodyWriter
- Specified by:
getBodyWriter
in interfaceHttpMessage<B>
- Returns:
- The body writer.
-
bodyWriter
Description copied from interface:MutableHttpMessage
Sets the message body writer to use.- Specified by:
bodyWriter
in interfaceMutableHttpMessage<B>
- Parameters:
messageBodyWriter
- The message body writer.- Returns:
- This response
-
getNettyHttpVersion
public io.netty.handler.codec.http.HttpVersion getNettyHttpVersion()The netty http version.- Returns:
- http version
-
getNettyHttpStatus
public io.netty.handler.codec.http.HttpResponseStatus getNettyHttpStatus()The netty http response status.- Returns:
- http response status
-
getNettyHeaders
public io.netty.handler.codec.http.HttpHeaders getNettyHeaders()The netty headers.- Returns:
- netty headers
-
toString
-
getHeaders
- Specified by:
getHeaders
in interfaceHttpMessage<B>
- Specified by:
getHeaders
in interfaceMutableHttpMessage<B>
- Returns:
- The
HttpHeaders
object
-
getAttributes
Description copied from interface:HttpMessage
A
MutableConvertibleValues
of the attributes for this HTTP message.Attributes are designed for internal data sharing and hence are isolated from headers and parameters which are client supplied
- Specified by:
getAttributes
in interfaceAttributeHolder
- Specified by:
getAttributes
in interfaceHttpMessage<B>
- Specified by:
getAttributes
in interfaceMutableAttributeHolder
- Returns:
- The attributes of the message
-
setAttribute
Description copied from interface:MutableAttributeHolder
Sets an attribute on the message.- Specified by:
setAttribute
in interfaceHttpMessage<B>
- Specified by:
setAttribute
in interfaceHttpResponse<B>
- Specified by:
setAttribute
in interfaceMutableAttributeHolder
- Parameters:
name
- The name of the attributevalue
- The value of the attribute- Returns:
- This message
-
code
public int code()- Specified by:
code
in interfaceHttpResponse<B>
- Returns:
- The response status code
-
reason
- Specified by:
reason
in interfaceHttpResponse<B>
- Returns:
- The HTTP status reason phrase
-
cookie
Description copied from interface:MutableHttpResponse
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.- Specified by:
cookie
in interfaceMutableHttpResponse<B>
- Parameters:
cookie
- the Cookie to return to the client- Returns:
- This response object
-
cookies
Description copied from interface:MutableHttpResponse
Adds the specified cookies to the response.- Specified by:
cookies
in interfaceMutableHttpResponse<B>
- Parameters:
cookies
- the Set of Cookies to return to the client- Returns:
- This response object
-
getBody
- Specified by:
getBody
in interfaceHttpMessage<B>
- Returns:
- The request body
-
getBody
Description copied from interface:HttpMessage
Return the body as the given type.- Specified by:
getBody
in interfaceHttpMessage<B>
- Type Parameters:
T1
- The generic type- Parameters:
type
- The type of the body- Returns:
- An
Optional
of the type orOptional.empty()
if the body cannot be returned as the given type
-
getBody
Description copied from interface:HttpMessage
Return the body, will use the provided conversion context if needed.- Specified by:
getBody
in interfaceHttpMessage<B>
- Type Parameters:
T
- The generic type- Parameters:
conversionContext
- The body conversion context- Returns:
- An
Optional
of the type orOptional.empty()
if the body cannot be returned as the given type
-
status
Description copied from interface:MutableHttpResponse
Sets the response status.- Specified by:
status
in interfaceMutableHttpResponse<B>
- Parameters:
status
- The statusmessage
- The message- Returns:
- This response object
-
body
Description copied from interface:MutableHttpResponse
Sets the body.- Specified by:
body
in interfaceMutableHttpMessage<B>
- Specified by:
body
in interfaceMutableHttpResponse<B>
- Type Parameters:
T
- The new body type- Parameters:
body
- The body- Returns:
- This response object
-
contentType
Description copied from interface:MutableHttpMessage
Set the response content type.- Specified by:
contentType
in interfaceMutableHttpMessage<B>
- Specified by:
contentType
in interfaceMutableHttpResponse<B>
- Parameters:
mediaType
- The media type- Returns:
- This response
-
toFullHttpResponse
Description copied from interface:NettyHttpResponseBuilder
Converts this object to a full http response.- Specified by:
toFullHttpResponse
in interfaceNettyHttpResponseBuilder
- Returns:
- a full http response
-
toStreamHttpResponse
Description copied from interface:NettyHttpResponseBuilder
Converts this object to a streamed http response.- Specified by:
toStreamHttpResponse
in interfaceNettyHttpResponseBuilder
- Returns:
- The streamed response
-
toHttpResponse
Description copied from interface:NettyHttpResponseBuilder
Converts this object to the most appropriate http response type.- Specified by:
toHttpResponse
in interfaceNettyHttpResponseBuilder
- Returns:
- The http response
-
isStream
public boolean isStream()- Specified by:
isStream
in interfaceNettyHttpResponseBuilder
- Returns:
- Is the response a stream.
-