public abstract class ClientResponse extends BuiltResponse
Response.ResponseBuilder, Response.Status, Response.StatusType
Modifier and Type | Field and Description |
---|---|
protected byte[] |
bufferedEntity |
protected ClientConfiguration |
configuration |
protected Map<String,Object> |
properties |
annotations, entity, entityClass, genericType, isClosed, metadata, processor, status
Modifier | Constructor and Description |
---|---|
protected |
ClientResponse(ClientConfiguration configuration) |
Modifier and Type | Method and Description |
---|---|
void |
abortIfClosed() |
boolean |
bufferEntity()
Buffer the message entity data.
|
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.
|
protected void |
finalize() |
Object |
getEntity()
Get the message entity Java instance.
|
protected InputStream |
getEntityStream() |
protected HeaderValueProcessor |
getHeaderValueProcessor() |
protected abstract InputStream |
getInputStream() |
Map<String,Object> |
getProperties() |
boolean |
hasEntity()
Check if there is an entity available in the response.
|
void |
noReleaseConnection()
In case of an InputStream or Reader and a invocation that returns no Response object, we need to make
sure the GC does not close the returned InputStream or Reader
|
<T> T |
readEntity(Class<T> type,
Type genericType,
Annotation[] anns) |
protected <T> Object |
readFrom(Class<T> type,
Type genericType,
MediaType media,
Annotation[] annotations) |
abstract void |
releaseConnection()
release underlying connection but do not close
|
void |
setClientConfiguration(ClientConfiguration configuration) |
void |
setHeaders(MultivaluedMap<String,String> headers) |
protected abstract void |
setInputStream(InputStream is) |
void |
setProperties(Map<String,Object> properties) |
addMethodAnnotations, getAllowedMethods, getAnnotations, getCookies, getDate, getEntityClass, getEntityTag, getGenericType, getHeaderString, getLanguage, getLastModified, getLength, getLink, getLinkBuilder, getLinkHeaders, getLinks, getLocation, getMediaType, getMetadata, getStatus, getStatusInfo, getStringHeaders, hasLink, isClosed, readEntity, readEntity, readEntity, readEntity, setAnnotations, setEntity, setEntityClass, setGenericType, setMetadata, setStatus, toHeaderString
accepted, accepted, created, fromResponse, getHeaders, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, temporaryRedirect
protected ClientConfiguration configuration
protected byte[] bufferedEntity
protected ClientResponse(ClientConfiguration configuration)
public void setHeaders(MultivaluedMap<String,String> headers)
public void setClientConfiguration(ClientConfiguration configuration)
public Object getEntity()
Response
null
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 BuiltResponse
null
if message does not contain an
entity body.public boolean hasEntity()
Response
true
if the entity is present, returns false
otherwise.hasEntity
in class BuiltResponse
true
if there is an entity present in the message,
false
otherwise.public void noReleaseConnection()
public void close()
Response
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 IllegalStateException
being thrown.
close
in class BuiltResponse
protected void finalize() throws Throwable
protected HeaderValueProcessor getHeaderValueProcessor()
getHeaderValueProcessor
in class BuiltResponse
protected abstract InputStream getInputStream()
protected InputStream getEntityStream()
protected abstract void setInputStream(InputStream is)
public abstract void releaseConnection() throws IOException
IOException
public <T> T readEntity(Class<T> type, Type genericType, Annotation[] anns)
readEntity
in class BuiltResponse
protected <T> Object readFrom(Class<T> type, Type genericType, MediaType media, Annotation[] annotations)
public boolean bufferEntity()
Response
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 bufferEntity
method is ignored and the method returns
false
.
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 the bufferEntity()
method is consistent across all invocations of the method on the same
Response
instance.
Buffering the message entity data allows for multiple invocations of
readEntity(...)
methods on the response instance. Note however, that
once the response instance itself is closed
, 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 an
IllegalStateException
being thrown.
bufferEntity
in class BuiltResponse
true
if the message entity input stream was available and
was buffered successfully, returns false
if the entity stream
was not available.public void abortIfClosed()
abortIfClosed
in class BuiltResponse
Copyright © 2017 JBoss by Red Hat. All rights reserved.