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 interfaceBaseClientResponse.BaseClientResponseStreamFactoryprivate static classBaseClientResponse.InputStreamWrapper
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringalternateMediaTypeprotected java.lang.annotation.Annotation[]annotationsprotected java.lang.StringattributeExceptionsToprotected java.util.Map<java.lang.String,java.lang.Object>attributesprotected java.lang.Exceptionexceptionprotected ClientExecutorexecutorprotected java.lang.reflect.TypegenericReturnTypeprotected javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>headersprotected LinkHeaderlinkHeaderprotected Linklocationprotected ResteasyProviderFactoryproviderFactoryprotected javax.ws.rs.ext.ReaderInterceptor[]readerInterceptorsprotected java.lang.Class<?>returnTypeprotected intstatusprotected BaseClientResponse.BaseClientResponseStreamFactorystreamFactoryprotected java.lang.ObjectunmarshaledEntityprotected booleanwasReleased
-
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 booleanbufferEntity()voidcheckFailureStatus()voidclose()static ClientResponsecopyFromError(ClientResponse copy)Store entity within a byte array input stream because we want to release the connection if a ClientResponseFailure is thrown.ClientResponseFailurecreateResponseFailure(java.lang.String message)ClientResponseFailurecreateResponseFailure(java.lang.String message, java.lang.Exception e)protected voidfinalize()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.StringgetAttributeExceptionsTo()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.DategetDate()TgetEntity()Unmarshal the target entity from the response OutputStream.<T2> T2getEntity(java.lang.Class<T2> type)Extract the response body with the provided type information<T2> T2getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType)Extract the response body with the provided type information<T2> T2getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType, java.lang.annotation.Annotation[] anns)<T2> T2getEntity(GenericType<T2> genericType)Extract the response body with the provided type information.<T2> T2getEntity(GenericType<T2> genericType, java.lang.annotation.Annotation[] ann)javax.ws.rs.core.EntityTaggetEntityTag()java.lang.ExceptiongetException()LinkgetHeaderAsLink(java.lang.String headerName)Header is assumed to be a URL, a Link object is created from it if it exists.java.lang.StringgetHeaderString(java.lang.String name)java.util.LocalegetLanguage()java.util.DategetLastModified()intgetLength()javax.ws.rs.core.LinkgetLink(java.lang.String relation)javax.ws.rs.core.Link.BuildergetLinkBuilder(java.lang.String relation)LinkHeadergetLinkHeader()Get the link headers of the response.java.util.Set<javax.ws.rs.core.Link>getLinks()java.net.URIgetLocation()LinkgetLocationLink()Get the Location header as a Link so you can easily execute on it.javax.ws.rs.core.MediaTypegetMediaType()javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object>getMetadata()java.lang.StringgetResponseHeader(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.StatusgetResponseStatus()java.lang.Class<?>getReturnType()intgetStatus()javax.ws.rs.core.Response.StatusTypegetStatusInfo()BaseClientResponse.BaseClientResponseStreamFactorygetStreamFactory()javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>getStringHeaders()booleanhasEntity()booleanhasLink(java.lang.String relation)<T> TreadEntity(java.lang.Class<T> entityType)<T> TreadEntity(java.lang.Class<T> entityType, java.lang.annotation.Annotation[] annotations)<T> TreadEntity(javax.ws.rs.core.GenericType<T> entityType)<T> TreadEntity(javax.ws.rs.core.GenericType<T> entityType, java.lang.annotation.Annotation[] annotations)protected <T2> java.lang.ObjectreadFrom(java.lang.Class<T2> type, java.lang.reflect.Type genericType, javax.ws.rs.core.MediaType media, java.lang.annotation.Annotation[] annotations)voidreleaseConnection()voidresetStream()Attempts to reset the InputStream of the response.voidsetAlternateMediaType(java.lang.String alternateMediaType)voidsetAnnotations(java.lang.annotation.Annotation[] annotations)voidsetAttributeExceptionsTo(java.lang.String attributeExceptionsTo)voidsetAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)voidsetException(java.lang.Exception exception)voidsetGenericReturnType(java.lang.reflect.Type genericReturnType)voidsetHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers)voidsetProviderFactory(ResteasyProviderFactory providerFactory)voidsetReaderInterceptors(javax.ws.rs.ext.ReaderInterceptor[] readerInterceptors)voidsetReturnType(java.lang.Class<T> returnType)voidsetStatus(int status)voidsetStreamFactory(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)voidsetWasReleased(boolean wasReleased)booleanwasReleased()
-
-
-
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:ClientResponseUsed to pass information to and between interceptors.- Specified by:
getAttributesin 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:ClientResponseGet the link headers of the response. All Link objects returned will automatically have the same ClientExecutor as the request.- Specified by:
getLinkHeaderin classClientResponse<T>- Returns:
- non-null
-
getLocationLink
public Link getLocationLink()
Description copied from class:ClientResponseGet 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:
getLocationLinkin classClientResponse<T>- Returns:
-
getHeaderAsLink
public Link getHeaderAsLink(java.lang.String headerName)
Description copied from class:ClientResponseHeader 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:
getHeaderAsLinkin 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:ClientResponseAttempts to reset the InputStream of the response. Useful for refetching an entity after a marshalling failure- Specified by:
resetStreamin classClientResponse<T>
-
getEntity
public T getEntity()
Description copied from class:ClientResponseUnmarshal 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:
getEntityin classClientResponse<T>
-
getEntity
public <T2> T2 getEntity(java.lang.Class<T2> type)
Description copied from class:ClientResponseExtract 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:
getEntityin classClientResponse<T>- Returns:
-
getEntity
public <T2> T2 getEntity(java.lang.Class<T2> type, java.lang.reflect.Type genericType)Description copied from class:ClientResponseExtract 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:
getEntityin 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:
getEntityin classClientResponse<T>- Returns:
-
getMediaType
public javax.ws.rs.core.MediaType getMediaType()
- Specified by:
getMediaTypein 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:ClientResponseExtract 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:
getEntityin classClientResponse<T>- Returns:
-
getEntity
public <T2> T2 getEntity(GenericType<T2> genericType, java.lang.annotation.Annotation[] ann)
- Specified by:
getEntityin classClientResponse<T>- Returns:
-
getResponseHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getResponseHeaders()
Description copied from class:ClientResponseThis method returns the same exact map as Response.getMetadata() except as a map of strings rather than objects- Specified by:
getResponseHeadersin classClientResponse<T>- Returns:
-
getMetadata
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> getMetadata()
- Specified by:
getMetadatain classjavax.ws.rs.core.Response
-
getStatus
public int getStatus()
- Specified by:
getStatusin classjavax.ws.rs.core.Response
-
getStatusInfo
public javax.ws.rs.core.Response.StatusType getStatusInfo()
- Specified by:
getStatusInfoin 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:
getResponseStatusin classClientResponse<T>
-
wasReleased
public boolean wasReleased()
-
setWasReleased
public void setWasReleased(boolean wasReleased)
-
releaseConnection
public final void releaseConnection()
- Specified by:
releaseConnectionin classClientResponse<T>
-
finalize
protected final void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
readEntity
public <T> T readEntity(java.lang.Class<T> entityType)
- Specified by:
readEntityin classjavax.ws.rs.core.Response
-
readEntity
public <T> T readEntity(javax.ws.rs.core.GenericType<T> entityType)
- Specified by:
readEntityin classjavax.ws.rs.core.Response
-
readEntity
public <T> T readEntity(java.lang.Class<T> entityType, java.lang.annotation.Annotation[] annotations)- Specified by:
readEntityin classjavax.ws.rs.core.Response
-
readEntity
public <T> T readEntity(javax.ws.rs.core.GenericType<T> entityType, java.lang.annotation.Annotation[] annotations)- Specified by:
readEntityin classjavax.ws.rs.core.Response
-
hasEntity
public boolean hasEntity()
- Specified by:
hasEntityin classjavax.ws.rs.core.Response
-
bufferEntity
public boolean bufferEntity()
- Specified by:
bufferEntityin classjavax.ws.rs.core.Response
-
close
public void close()
- Specified by:
closein classjavax.ws.rs.core.Response
-
getHeaderString
public java.lang.String getHeaderString(java.lang.String name)
- Specified by:
getHeaderStringin classjavax.ws.rs.core.Response
-
getLanguage
public java.util.Locale getLanguage()
- Specified by:
getLanguagein classjavax.ws.rs.core.Response
-
getLength
public int getLength()
- Specified by:
getLengthin classjavax.ws.rs.core.Response
-
getCookies
public java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie> getCookies()
- Specified by:
getCookiesin classjavax.ws.rs.core.Response
-
getEntityTag
public javax.ws.rs.core.EntityTag getEntityTag()
- Specified by:
getEntityTagin classjavax.ws.rs.core.Response
-
getDate
public java.util.Date getDate()
- Specified by:
getDatein classjavax.ws.rs.core.Response
-
getLastModified
public java.util.Date getLastModified()
- Specified by:
getLastModifiedin classjavax.ws.rs.core.Response
-
getLinks
public java.util.Set<javax.ws.rs.core.Link> getLinks()
- Specified by:
getLinksin classjavax.ws.rs.core.Response
-
hasLink
public boolean hasLink(java.lang.String relation)
- Specified by:
hasLinkin classjavax.ws.rs.core.Response
-
getLink
public javax.ws.rs.core.Link getLink(java.lang.String relation)
- Specified by:
getLinkin classjavax.ws.rs.core.Response
-
getLinkBuilder
public javax.ws.rs.core.Link.Builder getLinkBuilder(java.lang.String relation)
- Specified by:
getLinkBuilderin classjavax.ws.rs.core.Response
-
getLocation
public java.net.URI getLocation()
- Specified by:
getLocationin classjavax.ws.rs.core.Response
-
getAllowedMethods
public java.util.Set<java.lang.String> getAllowedMethods()
- Specified by:
getAllowedMethodsin classjavax.ws.rs.core.Response
-
getStringHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getStringHeaders()
- Specified by:
getStringHeadersin classjavax.ws.rs.core.Response
-
-