public abstract class AbstractBuiltResponse extends Response
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractBuiltResponse.InputStreamWrapper<T extends BuiltResponse> |
Response.ResponseBuilder, Response.Status, Response.StatusType| Modifier and Type | Field and Description |
|---|---|
protected Annotation[] |
annotations |
protected byte[] |
bufferedEntity |
protected Object |
entity |
protected Class |
entityClass |
protected Type |
genericType |
protected InputStream |
is |
protected boolean |
isClosed |
protected Headers<Object> |
metadata |
protected HeaderValueProcessor |
processor |
protected String |
reason |
protected int |
status |
protected boolean |
streamFullyRead |
protected boolean |
streamRead |
| Constructor and Description |
|---|
AbstractBuiltResponse() |
AbstractBuiltResponse(int status,
String reason,
Headers<Object> metadata,
Object entity,
Annotation[] entityAnnotations) |
| Modifier and Type | Method and Description |
|---|---|
void |
abortIfClosed() |
void |
addMethodAnnotations(Annotation[] methodAnnotations) |
void |
close()
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.
|
Annotation[] |
getAnnotations() |
Map<String,NewCookie> |
getCookies()
Get any new cookies set on the response message.
|
Date |
getDate()
Get message date.
|
Object |
getEntity()
Get the message entity Java instance.
|
Class |
getEntityClass() |
protected abstract InputStream |
getEntityStream() |
EntityTag |
getEntityTag()
Get the entity tag.
|
Type |
getGenericType() |
String |
getHeaderString(String name)
Get a message header as a single string value.
|
protected HeaderValueProcessor |
getHeaderValueProcessor() |
protected abstract InputStream |
getInputStream() |
Locale |
getLanguage()
Get the language of the message entity.
|
Date |
getLastModified()
Get the last modified date.
|
int |
getLength()
Get Content-Length value.
|
Link |
getLink(String relation)
Get the link for the relation.
|
Link.Builder |
getLinkBuilder(String relation)
Convenience method that returns a
Link.Builder for the relation. |
Set<Link> |
getLinks()
Get the links attached to the message as headers.
|
URI |
getLocation()
Get the location.
|
MediaType |
getMediaType()
Get the media type of the message entity.
|
MultivaluedMap<String,Object> |
getMetadata()
|
String |
getReasonPhrase() |
int |
getStatus()
Get the status code associated with the response.
|
Response.StatusType |
getStatusInfo()
Get the complete status information associated with the response.
|
MultivaluedMap<String,String> |
getStringHeaders()
Get view of the response headers and their string values.
|
boolean |
hasEntity()
Check if there is an entity available in the response.
|
boolean |
hasLink(String relation)
Check if link for relation exists.
|
boolean |
isClosed() |
<T> T |
readEntity(Class<T> type)
Read the message entity input stream as an instance of specified Java type
using a
MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
<T> T |
readEntity(Class<T> type,
Annotation[] annotations)
Read the message entity input stream as an instance of specified Java type
using a
MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
abstract <T> T |
readEntity(Class<T> type,
Type genericType,
Annotation[] anns) |
<T> T |
readEntity(GenericType<T> entityType)
Read the message entity input stream as an instance of specified Java type
using a
MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
<T> T |
readEntity(GenericType<T> entityType,
Annotation[] annotations)
Read the message entity input stream as an instance of specified Java type
using a
MessageBodyReader that supports mapping the
message entity stream onto the requested type. |
abstract void |
releaseConnection()
Release underlying connection but do not close.
|
abstract void |
releaseConnection(boolean consumeInputStream)
Release underlying connection but do not close.
|
protected void |
resetEntity() |
void |
setAnnotations(Annotation[] annotations) |
void |
setEntity(Object entity) |
void |
setEntityClass(Class entityClass) |
void |
setGenericType(Type genericType) |
protected abstract void |
setInputStream(InputStream is) |
void |
setMetadata(MultivaluedMap<String,Object> metadata) |
void |
setReasonPhrase(String reason) |
void |
setStatus(int status) |
void |
setStreamFullyRead(Boolean b) |
void |
setStreamRead(Boolean b) |
protected String |
toHeaderString(Object header) |
accepted, accepted, bufferEntity, created, fromResponse, getHeaders, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, status, temporaryRedirectprotected Object entity
protected int status
protected String reason
protected Annotation[] annotations
protected Class entityClass
protected Type genericType
protected HeaderValueProcessor processor
protected volatile boolean isClosed
protected InputStream is
protected byte[] bufferedEntity
protected volatile boolean streamRead
protected volatile boolean streamFullyRead
public AbstractBuiltResponse()
public AbstractBuiltResponse(int status,
String reason,
Headers<Object> metadata,
Object entity,
Annotation[] entityAnnotations)
protected abstract InputStream getInputStream()
protected abstract void setInputStream(InputStream is)
protected abstract InputStream getEntityStream()
public abstract void releaseConnection()
throws IOException
IOException - if I/O error occurredpublic abstract void releaseConnection(boolean consumeInputStream)
throws IOException
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.
IOException - if I/O error occuredpublic Class getEntityClass()
public void setEntityClass(Class entityClass)
protected HeaderValueProcessor getHeaderValueProcessor()
public Object getEntity()
Responsenull if the message
does not contain an entity body.
If the entity is represented by an un-consumed input stream
the method will return the input stream.
getEntity in class Responsenull if message does not contain an
entity body (i.e. when Response.hasEntity() returns false).public int getStatus()
Responsepublic String getReasonPhrase()
public Response.StatusType getStatusInfo()
ResponsegetStatusInfo in class Responsenull.public MultivaluedMap<String,Object> getMetadata()
ResponseResponse.getHeaders().
This method is considered deprecated. Users are encouraged to switch their
code to use the getHeaders() method instead. The method may be annotated
as @Deprecated in a future release of the API.getMetadata in class Responsepublic void setEntity(Object entity)
public void setStatus(int status)
public void setReasonPhrase(String reason)
public void setMetadata(MultivaluedMap<String,Object> metadata)
public Annotation[] getAnnotations()
public void addMethodAnnotations(Annotation[] methodAnnotations)
public void setAnnotations(Annotation[] annotations)
public Type getGenericType()
public void setGenericType(Type genericType)
public <T> T readEntity(Class<T> type, Annotation[] annotations)
ResponseMessageBodyReader that supports mapping the
message entity stream onto the requested type.
Method throws an ProcessingException if the content of the
message cannot be mapped to an entity of the requested type and
IllegalStateException in case the entity is not backed by an input
stream or if the original entity input stream has already been consumed
without buffering the 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 an input stream, this method automatically
closes the 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 of
readEntity(...) methods on this response.
readEntity in class ResponseT - entity instance Java type.type - the type of entity.annotations - annotations that will be passed to the MessageBodyReader.ProcessingException wrapping the
underlying NoContentException is thrown.MessageBodyReaderpublic <T> T readEntity(GenericType<T> entityType, Annotation[] annotations)
ResponseMessageBodyReader that supports mapping the
message entity stream onto the requested type.
Method throws an ProcessingException if the content of the
message cannot be mapped to an entity of the requested type and
IllegalStateException in case the entity is not backed by an input
stream or if the original entity input stream has already been consumed
without buffering the 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 an input stream, this method automatically
closes the 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 of
readEntity(...) methods on this response.
readEntity in class ResponseT - entity instance Java type.entityType - the type of entity; may be generic.annotations - annotations that will be passed to the MessageBodyReader.ProcessingException wrapping the
underlying NoContentException is thrown.MessageBodyReaderpublic <T> T readEntity(Class<T> type)
ResponseMessageBodyReader that supports mapping the
message entity stream onto the requested type.
Method throws an ProcessingException if the content of the
message cannot be mapped to an entity of the requested type and
IllegalStateException in case the entity is not backed by an input
stream or if the original entity input stream has already been consumed
without buffering the 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 an input stream, this method automatically
closes the 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 of
readEntity(...) methods on this response.
readEntity in class ResponseT - entity instance Java type.type - the type of entity.ProcessingException wrapping the
underlying NoContentException is thrown.MessageBodyReaderpublic <T> T readEntity(GenericType<T> entityType)
ResponseMessageBodyReader that supports mapping the
message entity stream onto the requested type.
Method throws an ProcessingException if the content of the
message cannot be mapped to an entity of the requested type and
IllegalStateException in case the entity is not backed by an input
stream or if the original entity input stream has already been consumed
without buffering the 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 an input stream, this method automatically
closes the 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 of
readEntity(...) methods on this response.
readEntity in class ResponseT - entity instance Java type.entityType - the type of entity; may be generic.ProcessingException wrapping the
underlying NoContentException is thrown.MessageBodyReaderpublic abstract <T> T readEntity(Class<T> type, Type genericType, Annotation[] anns)
protected void resetEntity()
public void setStreamRead(Boolean b)
public void setStreamFullyRead(Boolean b)
public boolean hasEntity()
Responsetrue if the entity is present, returns false otherwise.
Note that the method may return true also 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 the readEntity(...)
methods will return a corresponding instance representing a zero-length entity for a
given Java type or produce a ProcessingException in case no such instance
is available for the Java type.
public boolean isClosed()
public void abortIfClosed()
public void close()
Responsebuffered 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 IllegalStateException being thrown.
close in interface AutoCloseableclose in class Responsepublic Locale getLanguage()
ResponsegetLanguage in class Responsepublic int getLength()
Responsepublic MediaType getMediaType()
ResponsegetMediaType in class Responsenull if there is no response entity.public Map<String,NewCookie> getCookies()
ResponsegetCookies in class Responsepublic EntityTag getEntityTag()
ResponsegetEntityTag in class Responsenull if not present.public Date getLastModified()
ResponsegetLastModified in class Responsenull if not present.public Set<String> getAllowedMethods()
ResponsegetAllowedMethods in class Responsepublic MultivaluedMap<String,String> getStringHeaders()
ResponsegetStringHeaders in class ResponseResponse.getHeaders(),
Response.getHeaderString(java.lang.String)public String getHeaderString(String name)
ResponseRuntimeDelegate.HeaderDelegate if one is available
via RuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using its toString method if a header
delegate is not available.getHeaderString in class Responsename - the message header.null is 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.Response.getHeaders(),
Response.getStringHeaders()public URI getLocation()
ResponsegetLocation in class Responsenull if not present.public Set<Link> getLinks()
Responsepublic boolean hasLink(String relation)
ResponsehasLink in class Responserelation - link relation.true if the link for the relation is present in the
message headers, false otherwise.public Link getLink(String relation)
Responsepublic Link.Builder getLinkBuilder(String relation)
ResponseLink.Builder for the relation.
See Response.getLink(java.lang.String) for more information.getLinkBuilder in class Responserelation - link relation.null if not
present.Copyright © 2019 JBoss by Red Hat. All rights reserved.