public abstract class ClientResponse extends BuiltResponse
AbstractBuiltResponse.InputStreamWrapper<T extends BuiltResponse>
Response.ResponseBuilder, Response.Status, Response.StatusType
Modifier and Type | Field and Description |
---|---|
protected ClientConfiguration |
configuration |
protected Map<String,Object> |
properties |
annotations, bufferedEntity, entity, entityClass, genericType, is, isClosed, metadata, processor, reason, status, streamFullyRead, streamRead
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.
|
Class<?> |
getEntityClass() |
protected InputStream |
getEntityStream() |
protected HeaderValueProcessor |
getHeaderValueProcessor() |
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
|
protected <T> Object |
readFrom(Class<T> type,
Type genericType,
MediaType media,
Annotation[] annotations) |
void |
setClientConfiguration(ClientConfiguration configuration) |
void |
setHeaders(MultivaluedMap<String,String> headers) |
protected abstract void |
setInputStream(InputStream is) |
void |
setProperties(Map<String,Object> properties) |
getInputStream, readEntity, releaseConnection, releaseConnection
addMethodAnnotations, getAllowedMethods, getAnnotations, getCookies, getDate, getEntityTag, getGenericType, getHeaderString, getLanguage, getLastModified, getLength, getLink, getLinkBuilder, getLinks, getLocation, getMediaType, getMetadata, getReasonPhrase, getStatus, getStatusInfo, getStringHeaders, hasLink, isClosed, readEntity, readEntity, readEntity, readEntity, resetEntity, setAnnotations, setEntity, setEntityClass, setGenericType, setMetadata, setReasonPhrase, setStatus, setStreamFullyRead, setStreamRead, toHeaderString
accepted, accepted, created, fromResponse, getHeaders, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, status, temporaryRedirect
protected ClientConfiguration configuration
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 AbstractBuiltResponse
null
if message does not contain an
entity body (i.e. when Response.hasEntity()
returns false
).public Class<?> getEntityClass()
getEntityClass
in class AbstractBuiltResponse
public boolean hasEntity()
Response
true
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.
hasEntity
in class AbstractBuiltResponse
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 interface AutoCloseable
close
in class AbstractBuiltResponse
protected void finalize() throws Throwable
protected HeaderValueProcessor getHeaderValueProcessor()
getHeaderValueProcessor
in class AbstractBuiltResponse
protected InputStream getEntityStream()
getEntityStream
in class BuiltResponse
protected abstract void setInputStream(InputStream is)
setInputStream
in class BuiltResponse
protected <T> Object readFrom(Class<T> type, Type genericType, MediaType media, Annotation[] annotations)
readFrom
in class BuiltResponse
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 AbstractBuiltResponse
Copyright © 2021 JBoss by Red Hat. All rights reserved.