Class AbstractBuiltResponse
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
BuiltResponse
- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classNested classes/interfaces inherited from class jakarta.ws.rs.core.Response
Response.ResponseBuilder, Response.Status, Response.StatusType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Annotation[]protected byte[]protected Objectprotected Classprotected Typeprotected InputStreamprotected booleanprotected HeaderValueProcessorprotected Stringprotected intprotected booleanprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBuiltResponse(int status, String reason, Headers<Object> metadata, Object entity, Annotation[] entityAnnotations) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddMethodAnnotations(Annotation[] methodAnnotations) 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.Get the allowed HTTP methods from the Allow HTTP header.Get any new cookies set on the response message.getDate()Get message date.Get the message entity Java instance.protected abstract InputStreamGet the entity tag.getHeaderString(String name) Get a message header as a single string value.protected HeaderValueProcessorprotected abstract InputStreamGet the language of the message entity.Get the last modified date.intGet Content-Length value.Get the link for the relation.getLinkBuilder(String relation) Convenience method that returns aLink.Builderfor the relation.getLinks()Get the links attached to the message as headers.Get the location.Get the media type of the message entity.intGet the status code associated with the response.Get the complete status information associated with the response.Get view of the response headers and their string values.booleanCheck if there is an entity available in the response.booleanCheck if link for relation exists.booleanisClosed()Check if the response is closed.<T> TreadEntity(GenericType<T> 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.<T> TreadEntity(GenericType<T> 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.<T> TreadEntity(Class<T> type) 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.<T> TreadEntity(Class<T> type, 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.abstract <T> TreadEntity(Class<T> type, Type genericType, Annotation[] anns) abstract voidRelease underlying connection but do not close.abstract voidreleaseConnection(boolean consumeInputStream) Release underlying connection but do not close.protected voidvoidsetAnnotations(Annotation[] annotations) voidvoidsetEntityClass(Class entityClass) voidsetGenericType(Type genericType) protected abstract voidvoidsetMetadata(MultivaluedMap<String, Object> metadata) voidsetReasonPhrase(String reason) voidsetStatus(int status) voidvoidprotected StringtoHeaderString(Object header) Methods inherited from class jakarta.ws.rs.core.Response
accepted, accepted, bufferEntity, created, fromResponse, getHeaders, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, status, temporaryRedirect
-
Field Details
-
entity
-
status
protected int status -
reason
-
metadata
-
annotations
-
entityClass
-
genericType
-
processor
-
isClosed
protected volatile boolean isClosed -
is
-
bufferedEntity
protected byte[] bufferedEntity -
streamRead
protected volatile boolean streamRead -
streamFullyRead
protected volatile boolean streamFullyRead
-
-
Constructor Details
-
AbstractBuiltResponse
public AbstractBuiltResponse() -
AbstractBuiltResponse
public AbstractBuiltResponse(int status, String reason, Headers<Object> metadata, Object entity, Annotation[] entityAnnotations)
-
-
Method Details
-
getInputStream
-
setInputStream
-
getEntityStream
-
releaseConnection
Release underlying connection but do not close.- Throws:
IOException- if I/O error occurred
-
releaseConnection
Release underlying connection but do not close.- Parameters:
consumeInputStream- boolean to indicate either the underlying input stream must be fully read before releasing the connection or not.For most HTTP connection implementations, consuming the underlying input stream before releasing the connection will help to ensure connection reusability with respect of Keep-Alive policy.
- Throws:
IOException- if I/O error occured
-
getEntityClass
-
setEntityClass
-
getHeaderValueProcessor
-
getEntity
Description copied from class:ResponseGet 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 classResponse- Returns:
- the message entity or
nullif message does not contain an entity body (i.e. whenResponse.hasEntity()returnsfalse).
-
getStatus
public int getStatus()Description copied from class:ResponseGet the status code associated with the response. -
getReasonPhrase
-
getStatusInfo
Description copied from class:ResponseGet the complete status information associated with the response.- Specified by:
getStatusInfoin classResponse- Returns:
- the response status information. The returned value is never
null.
-
getMetadata
Description copied from class:ResponseSeeResponse.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 JAX-RS API.- Specified by:
getMetadatain classResponse- Returns:
- response headers as a multivalued map.
-
setEntity
-
setStatus
public void setStatus(int status) -
setReasonPhrase
-
setMetadata
-
getAnnotations
-
addMethodAnnotations
-
setAnnotations
-
getGenericType
-
setGenericType
-
readEntity
Description copied from class:ResponseRead 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
Response.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 classResponse- Type Parameters:
T- entity instance Java type.- Parameters:
type- 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:
-
readEntity
Description copied from class:ResponseRead 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
Response.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 classResponse- Type Parameters:
T- 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:
-
readEntity
Description copied from class:ResponseRead 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
Response.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 classResponse- Type Parameters:
T- entity instance Java type.- Parameters:
type- 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:
-
readEntity
Description copied from class:ResponseRead 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
Response.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 classResponse- Type Parameters:
T- 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:
-
readEntity
-
resetEntity
protected void resetEntity() -
setStreamRead
-
setStreamFullyRead
-
hasEntity
public boolean hasEntity()Description copied from class:ResponseCheck 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. -
isClosed
public boolean isClosed()Description copied from class:ResponseCheck if the response is closed. The method returnstrueif the response is closed, returnsfalseotherwise. -
abortIfClosed
public void abortIfClosed() -
close
public void close()Description copied from class:ResponseClose 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 classResponse
-
getLanguage
Description copied from class:ResponseGet the language of the message entity.- Specified by:
getLanguagein classResponse- Returns:
- the language of the entity or null if not specified.
-
getLength
public int getLength()Description copied from class:ResponseGet Content-Length value. -
getMediaType
Description copied from class:ResponseGet the media type of the message entity.- Specified by:
getMediaTypein classResponse- Returns:
- the media type or
nullif there is no response entity.
-
getCookies
Description copied from class:ResponseGet any new cookies set on the response message.- Specified by:
getCookiesin classResponse- Returns:
- a read-only map of cookie name (String) to Cookie.
-
getEntityTag
Description copied from class:ResponseGet the entity tag.- Specified by:
getEntityTagin classResponse- Returns:
- the entity tag, otherwise
nullif not present.
-
getDate
Description copied from class:ResponseGet message date. -
getLastModified
Description copied from class:ResponseGet the last modified date.- Specified by:
getLastModifiedin classResponse- Returns:
- the last modified date, otherwise
nullif not present.
-
getAllowedMethods
Description copied from class:ResponseGet the allowed HTTP methods from the Allow HTTP header.- Specified by:
getAllowedMethodsin classResponse- Returns:
- the allowed HTTP methods, all methods will returned as upper case strings.
-
toHeaderString
-
getStringHeaders
Description copied from class:ResponseGet view of the response headers and their string values. The underlying header data may be subsequently modified by the JAX-RS runtime on the server side. Changes in the underlying header data are reflected in this view.- Specified by:
getStringHeadersin classResponse- Returns:
- response headers as a string view of header values.
- See Also:
-
getHeaderString
Description copied from class:ResponseGet 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 classResponse- 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:
-
getLocation
Description copied from class:ResponseGet the location.- Specified by:
getLocationin classResponse- Returns:
- the location URI, otherwise
nullif not present.
-
getLinks
Description copied from class:ResponseGet 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. -
hasLink
Description copied from class:ResponseCheck if link for relation exists.- Specified by:
hasLinkin classResponse- Parameters:
relation- link relation.- Returns:
trueif the link for the relation is present in themessage headers,falseotherwise.
-
getLink
Description copied from class:ResponseGet 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. -
getLinkBuilder
Description copied from class:ResponseConvenience method that returns aLink.Builderfor the relation. SeeResponse.getLink(java.lang.String)for more information.- Specified by:
getLinkBuilderin classResponse- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-