Package org.jboss.resteasy.client.core
Class BaseClientResponse<T>
- java.lang.Object
-
- javax.ws.rs.core.Response
-
- org.jboss.resteasy.client.ClientResponse<T>
-
- org.jboss.resteasy.client.core.BaseClientResponse<T>
-
public class BaseClientResponse<T> extends ClientResponse<T>
- Version:
- $Revision: 1 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BaseClientResponse.BaseClientResponseStreamFactory
private static class
BaseClientResponse.InputStreamWrapper
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
alternateMediaType
protected java.lang.annotation.Annotation[]
annotations
protected java.lang.String
attributeExceptionsTo
protected java.util.Map<java.lang.String,java.lang.Object>
attributes
protected java.lang.Exception
exception
protected ClientExecutor
executor
protected java.lang.reflect.Type
genericReturnType
protected javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>
headers
protected LinkHeader
linkHeader
protected Link
location
protected ResteasyProviderFactory
providerFactory
protected javax.ws.rs.ext.ReaderInterceptor[]
readerInterceptors
protected java.lang.Class<?>
returnType
protected int
status
protected BaseClientResponse.BaseClientResponseStreamFactory
streamFactory
protected java.lang.Object
unmarshaledEntity
protected boolean
wasReleased
-
Constructor Summary
Constructors Constructor Description BaseClientResponse(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)
BaseClientResponse(BaseClientResponse.BaseClientResponseStreamFactory streamFactory, ClientExecutor executor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
bufferEntity()
void
checkFailureStatus()
void
close()
static ClientResponse
copyFromError(ClientResponse copy)
Store entity within a byte array input stream because we want to release the connection if a ClientResponseFailure is thrown.ClientResponseFailure
createResponseFailure(java.lang.String message)
ClientResponseFailure
createResponseFailure(java.lang.String message, java.lang.Exception e)
protected void
finalize()
java.util.Set<java.lang.String>
getAllowedMethods()
java.lang.annotation.Annotation[]
getAnnotations()
private <T2> java.lang.annotation.Annotation[]
getAnnotations(java.lang.Class<T2> type, java.lang.reflect.Type genericType)
java.lang.String
getAttributeExceptionsTo()
java.util.Map<java.lang.String,java.lang.Object>
getAttributes()
Used to pass information to and between interceptors.java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie>
getCookies()
java.util.Date
getDate()
T
getEntity()
Unmarshal the target entity from the response OutputStream.<T2> T2
getEntity(java.lang.Class<T2> type)
Extract the response body with the provided type information<T2> T2
getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType)
Extract the response body with the provided type information<T2> T2
getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] anns)
<T2> T2
getEntity(GenericType<T2> genericType)
Extract the response body with the provided type information.<T2> T2
getEntity(GenericType<T2> genericType, java.lang.annotation.Annotation[] ann)
javax.ws.rs.core.EntityTag
getEntityTag()
java.lang.Exception
getException()
Link
getHeaderAsLink(java.lang.String headerName)
Header is assumed to be a URL, a Link object is created from it if it exists.java.lang.String
getHeaderString(java.lang.String name)
java.util.Locale
getLanguage()
java.util.Date
getLastModified()
int
getLength()
javax.ws.rs.core.Link
getLink(java.lang.String relation)
javax.ws.rs.core.Link.Builder
getLinkBuilder(java.lang.String relation)
LinkHeader
getLinkHeader()
Get the link headers of the response.java.util.Set<javax.ws.rs.core.Link>
getLinks()
java.net.URI
getLocation()
Link
getLocationLink()
Get the Location header as a Link so you can easily execute on it.javax.ws.rs.core.MediaType
getMediaType()
javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object>
getMetadata()
java.lang.String
getResponseHeader(java.lang.String headerKey)
javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>
getResponseHeaders()
This method returns the same exact map as Response.getMetadata() except as a map of strings rather than objectsjavax.ws.rs.core.Response.Status
getResponseStatus()
java.lang.Class<?>
getReturnType()
int
getStatus()
javax.ws.rs.core.Response.StatusType
getStatusInfo()
BaseClientResponse.BaseClientResponseStreamFactory
getStreamFactory()
javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>
getStringHeaders()
boolean
hasEntity()
boolean
hasLink(java.lang.String relation)
<T> T
readEntity(java.lang.Class<T> entityType)
<T> T
readEntity(java.lang.Class<T> entityType, java.lang.annotation.Annotation[] annotations)
<T> T
readEntity(javax.ws.rs.core.GenericType<T> entityType)
<T> T
readEntity(javax.ws.rs.core.GenericType<T> entityType, java.lang.annotation.Annotation[] annotations)
protected <T2> java.lang.Object
readFrom(java.lang.Class<T2> type, java.lang.reflect.Type genericType, javax.ws.rs.core.MediaType media, java.lang.annotation.Annotation[] annotations)
void
releaseConnection()
void
resetStream()
Attempts to reset the InputStream of the response.void
setAlternateMediaType(java.lang.String alternateMediaType)
void
setAnnotations(java.lang.annotation.Annotation[] annotations)
void
setAttributeExceptionsTo(java.lang.String attributeExceptionsTo)
void
setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
void
setException(java.lang.Exception exception)
void
setGenericReturnType(java.lang.reflect.Type genericReturnType)
void
setHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers)
void
setProviderFactory(ResteasyProviderFactory providerFactory)
void
setReaderInterceptors(javax.ws.rs.ext.ReaderInterceptor[] readerInterceptors)
void
setReturnType(java.lang.Class<T> returnType)
void
setStatus(int status)
void
setStreamFactory(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)
void
setWasReleased(boolean wasReleased)
boolean
wasReleased()
-
-
-
Field Detail
-
providerFactory
protected ResteasyProviderFactory providerFactory
-
attributeExceptionsTo
protected java.lang.String attributeExceptionsTo
-
headers
protected javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers
-
alternateMediaType
protected java.lang.String alternateMediaType
-
returnType
protected java.lang.Class<?> returnType
-
genericReturnType
protected java.lang.reflect.Type genericReturnType
-
annotations
protected java.lang.annotation.Annotation[] annotations
-
status
protected int status
-
wasReleased
protected boolean wasReleased
-
unmarshaledEntity
protected java.lang.Object unmarshaledEntity
-
readerInterceptors
protected javax.ws.rs.ext.ReaderInterceptor[] readerInterceptors
-
exception
protected java.lang.Exception exception
-
streamFactory
protected BaseClientResponse.BaseClientResponseStreamFactory streamFactory
-
linkHeader
protected LinkHeader linkHeader
-
location
protected Link location
-
executor
protected ClientExecutor executor
-
attributes
protected java.util.Map<java.lang.String,java.lang.Object> attributes
-
-
Constructor Detail
-
BaseClientResponse
public BaseClientResponse(BaseClientResponse.BaseClientResponseStreamFactory streamFactory, ClientExecutor executor)
-
BaseClientResponse
public BaseClientResponse(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)
-
-
Method Detail
-
copyFromError
public static ClientResponse copyFromError(ClientResponse copy)
Store entity within a byte array input stream because we want to release the connection if a ClientResponseFailure is thrown. Copy status and headers, but ignore all type information stored in the ClientResponse.- Parameters:
copy
-- Returns:
-
getAttributes
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Description copied from class:ClientResponse
Used to pass information to and between interceptors.- Specified by:
getAttributes
in classClientResponse<T>
- Returns:
-
setAttributes
public void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
-
setReaderInterceptors
public void setReaderInterceptors(javax.ws.rs.ext.ReaderInterceptor[] readerInterceptors)
-
setStatus
public void setStatus(int status)
-
setHeaders
public void setHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers)
-
setProviderFactory
public void setProviderFactory(ResteasyProviderFactory providerFactory)
-
setReturnType
public void setReturnType(java.lang.Class<T> returnType)
-
getReturnType
public java.lang.Class<?> getReturnType()
-
setGenericReturnType
public void setGenericReturnType(java.lang.reflect.Type genericReturnType)
-
setAnnotations
public void setAnnotations(java.lang.annotation.Annotation[] annotations)
-
getAttributeExceptionsTo
public java.lang.String getAttributeExceptionsTo()
-
setAttributeExceptionsTo
public void setAttributeExceptionsTo(java.lang.String attributeExceptionsTo)
-
getException
public java.lang.Exception getException()
-
setException
public void setException(java.lang.Exception exception)
-
getAnnotations
public java.lang.annotation.Annotation[] getAnnotations()
-
getResponseHeader
public java.lang.String getResponseHeader(java.lang.String headerKey)
-
getLinkHeader
public LinkHeader getLinkHeader()
Description copied from class:ClientResponse
Get the link headers of the response. All Link objects returned will automatically have the same ClientExecutor as the request.- Specified by:
getLinkHeader
in classClientResponse<T>
- Returns:
- non-null
-
getLocationLink
public Link getLocationLink()
Description copied from class:ClientResponse
Get the Location header as a Link so you can easily execute on it. All Link objects returned will automatically have the same ClientExecutor as the request.- Specified by:
getLocationLink
in classClientResponse<T>
- Returns:
-
getHeaderAsLink
public Link getHeaderAsLink(java.lang.String headerName)
Description copied from class:ClientResponse
Header is assumed to be a URL, a Link object is created from it if it exists. Also, the type field of the link with be initialized if there is another header appended with -Type. i.e. if the header was "custom" it will also look for a header of custom-type and expect that this is a media type. All Link objects returned will automatically have the same ClientExecutor as the request.- Specified by:
getHeaderAsLink
in classClientResponse<T>
- Returns:
- null if it doesn't exist
-
setAlternateMediaType
public void setAlternateMediaType(java.lang.String alternateMediaType)
-
getStreamFactory
public BaseClientResponse.BaseClientResponseStreamFactory getStreamFactory()
-
setStreamFactory
public void setStreamFactory(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)
-
resetStream
public void resetStream()
Description copied from class:ClientResponse
Attempts to reset the InputStream of the response. Useful for refetching an entity after a marshalling failure- Specified by:
resetStream
in classClientResponse<T>
-
getEntity
public T getEntity()
Description copied from class:ClientResponse
Unmarshal the target entity from the response OutputStream. You must have type information set viaotherwise, this will not work. This method actually does the reading on the OutputStream. It will only do the read once. Afterwards, it will cache the result and return the cached result. - Specified by:
getEntity
in classClientResponse<T>
-
getEntity
public <T2> T2 getEntity(java.lang.Class<T2> type)
Description copied from class:ClientResponse
Extract the response body with the provided type information This method actually does the reading on the OutputStream. It will only do the read once. Afterwards, it will cache the result and return the cached result.- Specified by:
getEntity
in classClientResponse<T>
- Returns:
-
getEntity
public <T2> T2 getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType)
Description copied from class:ClientResponse
Extract the response body with the provided type information This method actually does the reading on the OutputStream. It will only do the read once. Afterwards, it will cache the result and return the cached result.- Specified by:
getEntity
in classClientResponse<T>
- Returns:
-
getAnnotations
private <T2> java.lang.annotation.Annotation[] getAnnotations(java.lang.Class<T2> type, java.lang.reflect.Type genericType)
-
getEntity
public <T2> T2 getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] anns)
- Specified by:
getEntity
in classClientResponse<T>
- Returns:
-
getMediaType
public javax.ws.rs.core.MediaType getMediaType()
- Specified by:
getMediaType
in classjavax.ws.rs.core.Response
-
readFrom
protected <T2> java.lang.Object readFrom(java.lang.Class<T2> type, java.lang.reflect.Type genericType, javax.ws.rs.core.MediaType media, java.lang.annotation.Annotation[] annotations)
-
getEntity
public <T2> T2 getEntity(GenericType<T2> genericType)
Description copied from class:ClientResponse
Extract the response body with the provided type information. GenericType is a trick used to pass in generic type information to the resteasy runtime. For example:List
list = response.getEntity(new GenericType - () {});
This method actually does the reading on the OutputStream. It will only do the read once. Afterwards, it will
cache the result and return the cached result.
- Specified by:
getEntity
in classClientResponse<T>
- Returns:
-
getEntity
public <T2> T2 getEntity(GenericType<T2> genericType, java.lang.annotation.Annotation[] ann)
- Specified by:
getEntity
in classClientResponse<T>
- Returns:
-
getResponseHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getResponseHeaders()
Description copied from class:ClientResponse
This method returns the same exact map as Response.getMetadata() except as a map of strings rather than objects- Specified by:
getResponseHeaders
in classClientResponse<T>
- Returns:
-
getMetadata
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> getMetadata()
- Specified by:
getMetadata
in classjavax.ws.rs.core.Response
-
getStatus
public int getStatus()
- Specified by:
getStatus
in classjavax.ws.rs.core.Response
-
getStatusInfo
public javax.ws.rs.core.Response.StatusType getStatusInfo()
- Specified by:
getStatusInfo
in classjavax.ws.rs.core.Response
-
checkFailureStatus
public void checkFailureStatus()
-
createResponseFailure
public ClientResponseFailure createResponseFailure(java.lang.String message)
-
createResponseFailure
public ClientResponseFailure createResponseFailure(java.lang.String message, java.lang.Exception e)
-
getResponseStatus
public javax.ws.rs.core.Response.Status getResponseStatus()
- Specified by:
getResponseStatus
in classClientResponse<T>
-
wasReleased
public boolean wasReleased()
-
setWasReleased
public void setWasReleased(boolean wasReleased)
-
releaseConnection
public final void releaseConnection()
- Specified by:
releaseConnection
in classClientResponse<T>
-
finalize
protected final void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
readEntity
public <T> T readEntity(java.lang.Class<T> entityType)
- Specified by:
readEntity
in classjavax.ws.rs.core.Response
-
readEntity
public <T> T readEntity(javax.ws.rs.core.GenericType<T> entityType)
- Specified by:
readEntity
in classjavax.ws.rs.core.Response
-
readEntity
public <T> T readEntity(java.lang.Class<T> entityType, java.lang.annotation.Annotation[] annotations)
- Specified by:
readEntity
in classjavax.ws.rs.core.Response
-
readEntity
public <T> T readEntity(javax.ws.rs.core.GenericType<T> entityType, java.lang.annotation.Annotation[] annotations)
- Specified by:
readEntity
in classjavax.ws.rs.core.Response
-
hasEntity
public boolean hasEntity()
- Specified by:
hasEntity
in classjavax.ws.rs.core.Response
-
bufferEntity
public boolean bufferEntity()
- Specified by:
bufferEntity
in classjavax.ws.rs.core.Response
-
close
public void close()
- Specified by:
close
in classjavax.ws.rs.core.Response
-
getHeaderString
public java.lang.String getHeaderString(java.lang.String name)
- Specified by:
getHeaderString
in classjavax.ws.rs.core.Response
-
getLanguage
public java.util.Locale getLanguage()
- Specified by:
getLanguage
in classjavax.ws.rs.core.Response
-
getLength
public int getLength()
- Specified by:
getLength
in classjavax.ws.rs.core.Response
-
getCookies
public java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie> getCookies()
- Specified by:
getCookies
in classjavax.ws.rs.core.Response
-
getEntityTag
public javax.ws.rs.core.EntityTag getEntityTag()
- Specified by:
getEntityTag
in classjavax.ws.rs.core.Response
-
getDate
public java.util.Date getDate()
- Specified by:
getDate
in classjavax.ws.rs.core.Response
-
getLastModified
public java.util.Date getLastModified()
- Specified by:
getLastModified
in classjavax.ws.rs.core.Response
-
getLinks
public java.util.Set<javax.ws.rs.core.Link> getLinks()
- Specified by:
getLinks
in classjavax.ws.rs.core.Response
-
hasLink
public boolean hasLink(java.lang.String relation)
- Specified by:
hasLink
in classjavax.ws.rs.core.Response
-
getLink
public javax.ws.rs.core.Link getLink(java.lang.String relation)
- Specified by:
getLink
in classjavax.ws.rs.core.Response
-
getLinkBuilder
public javax.ws.rs.core.Link.Builder getLinkBuilder(java.lang.String relation)
- Specified by:
getLinkBuilder
in classjavax.ws.rs.core.Response
-
getLocation
public java.net.URI getLocation()
- Specified by:
getLocation
in classjavax.ws.rs.core.Response
-
getAllowedMethods
public java.util.Set<java.lang.String> getAllowedMethods()
- Specified by:
getAllowedMethods
in classjavax.ws.rs.core.Response
-
getStringHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getStringHeaders()
- Specified by:
getStringHeaders
in classjavax.ws.rs.core.Response
-
-