Class RestResponseImpl<T>
- java.lang.Object
-
- org.jboss.resteasy.reactive.RestResponse<T>
-
- org.jboss.resteasy.reactive.common.jaxrs.RestResponseImpl<T>
-
- All Implemented Interfaces:
AutoCloseable
public class RestResponseImpl<T> extends RestResponse<T>
This is the Response class for user-created responses. The client response object has more deserialising powers in @{linkio.quarkus.rest.server.runtime.client.QuarkusRestClientResponse.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jboss.resteasy.reactive.RestResponse
RestResponse.ResponseBuilder<T>, RestResponse.Status, RestResponse.StatusCode
-
-
Constructor Summary
Constructors Constructor Description RestResponseImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbufferEntity()Buffer the message entity data.protected voidcheckClosed()voidclose()Close the underlying message entity input stream (if available and open) as well as releases any other resources associated with the response (e.g.Set<String>getAllowedMethods()Get the allowed HTTP methods from the Allow HTTP header.Map<String,jakarta.ws.rs.core.NewCookie>getCookies()Get any new cookies set on the response message.DategetDate()Get message date.TgetEntity()Get the message entity Java instance.Annotation[]getEntityAnnotations()InputStreamgetEntityStream()jakarta.ws.rs.core.EntityTaggetEntityTag()Get the entity tag.StringgetHeaderString(String name)Get a message header as a single string value.LocalegetLanguage()Get the language of the message entity.DategetLastModified()Get the last modified date.intgetLength()Get Content-Length value.jakarta.ws.rs.core.LinkgetLink(String relation)Get the link for the relation.jakarta.ws.rs.core.Link.BuildergetLinkBuilder(String relation)Convenience method that returns aLink.Builderfor the relation.Set<jakarta.ws.rs.core.Link>getLinks()Get the links attached to the message as headers.URIgetLocation()Get the location.jakarta.ws.rs.core.MediaTypegetMediaType()Get the media type of the message entity.jakarta.ws.rs.core.MultivaluedMap<String,Object>getMetadata()intgetStatus()Get the status code associated with the response.jakarta.ws.rs.core.Response.StatusTypegetStatusInfo()Get the complete status information associated with the response.jakarta.ws.rs.core.MultivaluedMap<String,String>getStringHeaders()Get view of the response headers and their string values.booleanhasEntity()Check if there is an entity available in the response.booleanhasLink(String relation)Check if link for relation exists.voidpopulateStringHeaders(String headerName, List<Object> values)<OtherT> OtherTreadEntity(jakarta.ws.rs.core.GenericType<OtherT> entityType)Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.<OtherT> OtherTreadEntity(jakarta.ws.rs.core.GenericType<OtherT> entityType, Annotation[] annotations)Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.<OtherT> OtherTreadEntity(Class<OtherT> entityType)Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.<OtherT> OtherTreadEntity(Class<OtherT> entityType, Annotation[] annotations)Read the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.protected <T> TreadEntity(Class<T> entityType, Type genericType, Annotation[] annotations)protected voidsetEntity(T entity)voidsetEntityStream(InputStream entityStream)voidsetStatus(int status)Internal: this is just cheaper than duplicating the response just to change the statusvoidsetStatusInfo(jakarta.ws.rs.core.Response.StatusType statusType)Internal: this is just cheaper than duplicating the response just to change the statusjakarta.ws.rs.core.ResponsetoResponse()Turns thisRestResponseinto a JAX-RSResponse.-
Methods inherited from class org.jboss.resteasy.reactive.RestResponse
accepted, accepted, created, fromResponse, getHeaders, noContent, notAcceptable, notFound, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, status, status, status, temporaryRedirect
-
-
-
-
Field Detail
-
entity
protected T entity
-
consumed
protected boolean consumed
-
closed
protected boolean closed
-
buffered
protected boolean buffered
-
-
Method Detail
-
toResponse
public jakarta.ws.rs.core.Response toResponse()
Description copied from class:RestResponseTurns thisRestResponseinto a JAX-RSResponse.- Specified by:
toResponsein classRestResponse<T>- Returns:
- a JAX-RS
Responserepresenting this response.
-
getStatus
public int getStatus()
Description copied from class:RestResponseGet the status code associated with the response.- Specified by:
getStatusin classRestResponse<T>- Returns:
- the response status code.
-
setStatus
public void setStatus(int status)
Internal: this is just cheaper than duplicating the response just to change the status
-
getStatusInfo
public jakarta.ws.rs.core.Response.StatusType getStatusInfo()
Description copied from class:RestResponseGet the complete status information associated with the response.- Specified by:
getStatusInfoin classRestResponse<T>- Returns:
- the response status information. The returned value is never
null.
-
setStatusInfo
public void setStatusInfo(jakarta.ws.rs.core.Response.StatusType statusType)
Internal: this is just cheaper than duplicating the response just to change the status
-
getEntity
public T getEntity()
Description copied from class:RestResponseGet the message entity Java instance. Returnsnullif the message does not contain an entity body.If the entity is represented by an un-consumed
input streamthe method will return the input stream.- Specified by:
getEntityin classRestResponse<T>- Returns:
- the message entity or
nullif message does not contain an entity body (i.e. whenRestResponse.hasEntity()returnsfalse).
-
setEntity
protected void setEntity(T entity)
-
getEntityStream
public InputStream getEntityStream()
-
setEntityStream
public void setEntityStream(InputStream entityStream)
-
readEntity
protected <T> T readEntity(Class<T> entityType, Type genericType, Annotation[] annotations)
-
readEntity
public <OtherT> OtherT readEntity(Class<OtherT> entityType)
Description copied from class:RestResponseRead the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
RestResponse.getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Specified by:
readEntityin classRestResponse<T>- Type Parameters:
OtherT- entity instance Java type.- Parameters:
entityType- the type of entity.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - See Also:
MessageBodyReader
-
readEntity
public <OtherT> OtherT readEntity(jakarta.ws.rs.core.GenericType<OtherT> entityType)
Description copied from class:RestResponseRead the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
RestResponse.getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Specified by:
readEntityin classRestResponse<T>- Type Parameters:
OtherT- entity instance Java type.- Parameters:
entityType- the type of entity; may be generic.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - See Also:
MessageBodyReader
-
readEntity
public <OtherT> OtherT readEntity(Class<OtherT> entityType, Annotation[] annotations)
Description copied from class:RestResponseRead the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
RestResponse.getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Specified by:
readEntityin classRestResponse<T>- Type Parameters:
OtherT- entity instance Java type.- Parameters:
entityType- the type of entity.annotations- annotations that will be passed to theMessageBodyReader.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - See Also:
MessageBodyReader
-
readEntity
public <OtherT> OtherT readEntity(jakarta.ws.rs.core.GenericType<OtherT> entityType, Annotation[] annotations)Description copied from class:RestResponseRead the message entity input stream as an instance of specified Java type using aMessageBodyReaderthat supports mapping the message entity stream onto the requested type.Method throws an
ProcessingExceptionif the content of the message cannot be mapped to an entity of the requested type andIllegalStateExceptionin case the entity is not backed by an input stream or if the original entity input stream has already been consumed withoutbufferingthe entity data prior consuming.A message instance returned from this method will be cached for subsequent retrievals via
RestResponse.getEntity(). Unless the supplied entity type is aninput stream, this method automaticallyclosesthe an unconsumed original response entity data stream if open. In case the entity data has been buffered, the buffer will be reset prior consuming the buffered data to enable subsequent invocations ofreadEntity(...)methods on this response.- Specified by:
readEntityin classRestResponse<T>- Type Parameters:
OtherT- entity instance Java type.- Parameters:
entityType- the type of entity; may be generic.annotations- annotations that will be passed to theMessageBodyReader.- Returns:
- the message entity; for a zero-length response entities returns a corresponding
Java object that represents zero-length data. In case no zero-length representation
is defined for the Java type, a
ProcessingExceptionwrapping the underlyingNoContentExceptionis thrown. - See Also:
MessageBodyReader
-
hasEntity
public boolean hasEntity()
Description copied from class:RestResponseCheck if there is an entity available in the response. The method returnstrueif the entity is present, returnsfalseotherwise.Note that the method may return
truealso for response messages with a zero-length content, in case the"Content-Length"and"Content-Type"headers are specified in the message. In such case, an attempt to read the entity using one of thereadEntity(...)methods will return a corresponding instance representing a zero-length entity for a given Java type or produce aProcessingExceptionin case no such instance is available for the Java type.- Specified by:
hasEntityin classRestResponse<T>- Returns:
trueif there is an entity present in the message,falseotherwise.
-
bufferEntity
public boolean bufferEntity()
Description copied from class:RestResponseBuffer the message entity data.In case the message entity is backed by an unconsumed entity input stream, all the bytes of the original entity input stream are read and stored in a local buffer. The original entity input stream is consumed and automatically closed as part of the operation and the method returns
true.In case the response entity instance is not backed by an unconsumed input stream an invocation of
bufferEntitymethod is ignored and the method returnsfalse.This operation is idempotent, i.e. it can be invoked multiple times with the same effect which also means that calling the
bufferEntity()method on an already buffered (and thus closed) message instance is legal and has no further effect. Also, the result returned by thebufferEntity()method is consistent across all invocations of the method on the sameRestResponseinstance.Buffering the message entity data allows for multiple invocations of
readEntity(...)methods on the response instance. Note however, that once the response instance itself isclosed, the implementations are expected to release the buffered message entity data too. Therefore any subsequent attempts to read a message entity stream on such closed response will result in anIllegalStateExceptionbeing thrown.- Specified by:
bufferEntityin classRestResponse<T>- Returns:
trueif the message entity input stream was available and was buffered successfully, returnsfalseif the entity stream was not available.
-
checkClosed
protected void checkClosed()
-
close
public void close()
Description copied from class:RestResponseClose the underlying message entity input stream (if available and open) as well as releases any other resources associated with the response (e.g.buffered message entity data).This operation is idempotent, i.e. it can be invoked multiple times with the same effect which also means that calling the
close()method on an already closed message instance is legal and has no further effect.The
close()method should be invoked on all instances that contain an un-consumed entity input stream to ensure the resources associated with the instance are properly cleaned-up and prevent potential memory leaks. This is typical for client-side scenarios where application layer code processes only the response headers and ignores the response entity.Any attempts to manipulate (read, get, buffer) a message entity on a closed response will result in an
IllegalStateExceptionbeing thrown.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein classRestResponse<T>
-
getMediaType
public jakarta.ws.rs.core.MediaType getMediaType()
Description copied from class:RestResponseGet the media type of the message entity.- Specified by:
getMediaTypein classRestResponse<T>- Returns:
- the media type or
nullif there is no response entity.
-
getLanguage
public Locale getLanguage()
Description copied from class:RestResponseGet the language of the message entity.- Specified by:
getLanguagein classRestResponse<T>- Returns:
- the language of the entity or null if not specified.
-
getLength
public int getLength()
Description copied from class:RestResponseGet Content-Length value.- Specified by:
getLengthin classRestResponse<T>- Returns:
- Content-Length as integer if present and valid number. In other
cases returns
-1.
-
getAllowedMethods
public Set<String> getAllowedMethods()
Description copied from class:RestResponseGet the allowed HTTP methods from the Allow HTTP header.- Specified by:
getAllowedMethodsin classRestResponse<T>- Returns:
- the allowed HTTP methods, all methods will returned as upper case strings.
-
getCookies
public Map<String,jakarta.ws.rs.core.NewCookie> getCookies()
Description copied from class:RestResponseGet any new cookies set on the response message.- Specified by:
getCookiesin classRestResponse<T>- Returns:
- a read-only map of cookie name (String) to Cookie.
-
getEntityTag
public jakarta.ws.rs.core.EntityTag getEntityTag()
Description copied from class:RestResponseGet the entity tag.- Specified by:
getEntityTagin classRestResponse<T>- Returns:
- the entity tag, otherwise
nullif not present.
-
getDate
public Date getDate()
Description copied from class:RestResponseGet message date.- Specified by:
getDatein classRestResponse<T>- Returns:
- the message date, otherwise
nullif not present.
-
getLastModified
public Date getLastModified()
Description copied from class:RestResponseGet the last modified date.- Specified by:
getLastModifiedin classRestResponse<T>- Returns:
- the last modified date, otherwise
nullif not present.
-
getLocation
public URI getLocation()
Description copied from class:RestResponseGet the location.- Specified by:
getLocationin classRestResponse<T>- Returns:
- the location URI, otherwise
nullif not present.
-
getLinks
public Set<jakarta.ws.rs.core.Link> getLinks()
Description copied from class:RestResponseGet the links attached to the message as headers. Any links in the message that are relative must be resolved with respect to the actual request URI that produced this response. Note that request URIs may be updated by filters, so the actual request URI may differ from that in the original invocation.- Specified by:
getLinksin classRestResponse<T>- Returns:
- links, may return empty
Setif no links are present. Does not returnnull.
-
hasLink
public boolean hasLink(String relation)
Description copied from class:RestResponseCheck if link for relation exists.- Specified by:
hasLinkin classRestResponse<T>- Parameters:
relation- link relation.- Returns:
trueif the link for the relation is present in themessage headers,falseotherwise.
-
getLink
public jakarta.ws.rs.core.Link getLink(String relation)
Description copied from class:RestResponseGet the link for the relation. A relative link is resolved with respect to the actual request URI that produced this response. Note that request URIs may be updated by filters, so the actual request URI may differ from that in the original invocation.- Specified by:
getLinkin classRestResponse<T>- Parameters:
relation- link relation.- Returns:
- the link for the relation, otherwise
nullif not present.
-
getLinkBuilder
public jakarta.ws.rs.core.Link.Builder getLinkBuilder(String relation)
Description copied from class:RestResponseConvenience method that returns aLink.Builderfor the relation. SeeRestResponse.getLink(java.lang.String)for more information.- Specified by:
getLinkBuilderin classRestResponse<T>- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-
getMetadata
public jakarta.ws.rs.core.MultivaluedMap<String,Object> getMetadata()
Description copied from class:RestResponseSeeRestResponse.getHeaders(). This method is considered deprecated. Users are encouraged to switch their code to use thegetHeaders()method instead. The method may be annotated as@Deprecatedin a future release of the API.- Specified by:
getMetadatain classRestResponse<T>- Returns:
- response headers as a multivalued map.
-
getStringHeaders
public jakarta.ws.rs.core.MultivaluedMap<String,String> getStringHeaders()
Description copied from class:RestResponseGet view of the response headers and their string values. The underlying header data may be subsequently modified by the runtime on the server side. Changes in the underlying header data are reflected in this view.- Specified by:
getStringHeadersin classRestResponse<T>- Returns:
- response headers as a string view of header values.
- See Also:
RestResponse.getHeaders(),RestResponse.getHeaderString(java.lang.String)
-
getHeaderString
public String getHeaderString(String name)
Description copied from class:RestResponseGet a message header as a single string value. Each single header value is converted to String using aRuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.- Specified by:
getHeaderStringin classRestResponse<T>- Parameters:
name- the message header.- Returns:
- the message header value. If the message header is not present then
nullis returned. If the message header is present but has no value then the empty string is returned. If the message header is present more than once then the values of joined together and separated by a ',' character. - See Also:
RestResponse.getHeaders(),RestResponse.getStringHeaders()
-
getEntityAnnotations
public Annotation[] getEntityAnnotations()
-
-