org.jboss.resteasy.client.core
Class BaseClientResponse<T>

java.lang.Object
  extended by javax.ws.rs.core.Response
      extended by org.jboss.resteasy.client.ClientResponse<T>
          extended by org.jboss.resteasy.client.core.BaseClientResponse<T>

public class BaseClientResponse<T>
extends ClientResponse<T>

Version:
$Revision: 1 $
Author:
Bill Burke

Nested Class Summary
static interface BaseClientResponse.BaseClientResponseStreamFactory
           
 
Nested classes/interfaces inherited from class javax.ws.rs.core.Response
Response.ResponseBuilder, Response.Status, Response.StatusType
 
Field Summary
protected  String alternateMediaType
           
protected  Annotation[] annotations
           
protected  String attributeExceptionsTo
           
protected  Map<String,Object> attributes
           
protected  Exception exception
           
protected  ClientExecutor executor
           
protected  Type genericReturnType
           
protected  MultivaluedMap<String,String> headers
           
protected  LinkHeader linkHeader
           
protected  Link location
           
protected  MessageBodyReaderInterceptor[] messageBodyReaderInterceptors
           
protected  ResteasyProviderFactory providerFactory
           
protected  Class<?> returnType
           
protected  int status
           
protected  BaseClientResponse.BaseClientResponseStreamFactory streamFactory
           
protected  Object unmarshaledEntity
           
protected  boolean wasReleased
           
 
Constructor Summary
BaseClientResponse(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)
           
BaseClientResponse(BaseClientResponse.BaseClientResponseStreamFactory streamFactory, ClientExecutor executor)
           
 
Method Summary
 void checkFailureStatus()
           
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(String message)
           
 ClientResponseFailure createResponseFailure(String message, Exception e)
           
protected  void finalize()
           
 Annotation[] getAnnotations()
           
 String getAttributeExceptionsTo()
           
 Map<String,Object> getAttributes()
          Used to pass information to and between interceptors.
 T getEntity()
          Unmarshal the target entity from the response OutputStream.
<T2> T2
getEntity(Class<T2> type)
          Extract the response body with the provided type information

This method actually does the reading on the OutputStream.

<T2> T2
getEntity(Class<T2> type, Type genericType)
          Extract the response body with the provided type information

This method actually does the reading on the OutputStream.

<T2> T2
getEntity(Class<T2> type, Type genericType, Annotation[] anns)
           
<T2> T2
getEntity(GenericType<T2> genericType)
          Extract the response body with the provided type information.
<T2> T2
getEntity(GenericType<T2> genericType, Annotation[] ann)
           
 Exception getException()
           
 Link getHeaderAsLink(String headerName)
          Header is assumed to be a URL, a Link object is created from it if it exists.
 MultivaluedMap<String,String> getHeaders()
          This method returns the same exact map as Response.getMetadata() except as a map of strings rather than objects
 LinkHeader getLinkHeader()
          Get the link headers of the response.
 Link getLocation()
          Get the Location header as a Link so you can easily execute on it.
protected  MediaType getMediaType()
           
 MultivaluedMap<String,Object> getMetadata()
          Get metadata associated with the response as a map.
 String getResponseHeader(String headerKey)
           
 Response.Status getResponseStatus()
           
 Class<?> getReturnType()
           
 int getStatus()
          Get the status code associated with the response.
 BaseClientResponse.BaseClientResponseStreamFactory getStreamFactory()
           
protected
<T2> Object
readFrom(Class<T2> type, Type genericType, MediaType media, Annotation[] annotations)
           
 void releaseConnection()
           
 void resetStream()
          Attempts to reset the InputStream of the response.
 void setAlternateMediaType(String alternateMediaType)
           
 void setAnnotations(Annotation[] annotations)
           
 void setAttributeExceptionsTo(String attributeExceptionsTo)
           
 void setAttributes(Map<String,Object> attributes)
           
 void setException(Exception exception)
           
 void setGenericReturnType(Type genericReturnType)
           
 void setHeaders(MultivaluedMap<String,String> headers)
           
 void setMessageBodyReaderInterceptors(MessageBodyReaderInterceptor[] messageBodyReaderInterceptors)
           
 void setProviderFactory(ResteasyProviderFactory providerFactory)
           
 void setReturnType(Class<T> returnType)
           
 void setStatus(int status)
           
 void setStreamFactory(BaseClientResponse.BaseClientResponseStreamFactory streamFactory)
           
 boolean wasReleased()
           
 
Methods inherited from class javax.ws.rs.core.Response
created, fromResponse, noContent, notAcceptable, notModified, notModified, notModified, ok, ok, ok, ok, ok, seeOther, serverError, status, status, status, temporaryRedirect
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

providerFactory

protected ResteasyProviderFactory providerFactory

attributeExceptionsTo

protected String attributeExceptionsTo

headers

protected MultivaluedMap<String,String> headers

alternateMediaType

protected String alternateMediaType

returnType

protected Class<?> returnType

genericReturnType

protected Type genericReturnType

annotations

protected Annotation[] annotations

status

protected int status

wasReleased

protected boolean wasReleased

unmarshaledEntity

protected Object unmarshaledEntity

messageBodyReaderInterceptors

protected MessageBodyReaderInterceptor[] messageBodyReaderInterceptors

exception

protected Exception exception

streamFactory

protected BaseClientResponse.BaseClientResponseStreamFactory streamFactory

linkHeader

protected LinkHeader linkHeader

location

protected Link location

executor

protected ClientExecutor executor

attributes

protected Map<String,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 Map<String,Object> getAttributes()
Description copied from class: ClientResponse
Used to pass information to and between interceptors.

Specified by:
getAttributes in class ClientResponse<T>
Returns:

setAttributes

public void setAttributes(Map<String,Object> attributes)

setMessageBodyReaderInterceptors

public void setMessageBodyReaderInterceptors(MessageBodyReaderInterceptor[] messageBodyReaderInterceptors)

setStatus

public void setStatus(int status)

setHeaders

public void setHeaders(MultivaluedMap<String,String> headers)

setProviderFactory

public void setProviderFactory(ResteasyProviderFactory providerFactory)

setReturnType

public void setReturnType(Class<T> returnType)

getReturnType

public Class<?> getReturnType()

setGenericReturnType

public void setGenericReturnType(Type genericReturnType)

setAnnotations

public void setAnnotations(Annotation[] annotations)

getAttributeExceptionsTo

public String getAttributeExceptionsTo()

setAttributeExceptionsTo

public void setAttributeExceptionsTo(String attributeExceptionsTo)

getException

public Exception getException()

setException

public void setException(Exception exception)

getAnnotations

public Annotation[] getAnnotations()

getResponseHeader

public String getResponseHeader(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 class ClientResponse<T>
Returns:
non-null

getLocation

public Link getLocation()
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:
getLocation in class ClientResponse<T>
Returns:

getHeaderAsLink

public Link getHeaderAsLink(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 class ClientResponse<T>
Returns:
null if it doesn't exist

setAlternateMediaType

public void setAlternateMediaType(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 class ClientResponse<T>

getEntity

public T getEntity()
Description copied from class: ClientResponse
Unmarshal the target entity from the response OutputStream. You must have type information set via otherwise, 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 class ClientResponse<T>
Returns:
an object instance or null if there is no entity
See Also:
MessageBodyWriter

getEntity

public <T2> T2 getEntity(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 class ClientResponse<T>
Returns:

getEntity

public <T2> T2 getEntity(Class<T2> type,
                         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 class ClientResponse<T>
Returns:

getEntity

public <T2> T2 getEntity(Class<T2> type,
                         Type genericType,
                         Annotation[] anns)
Specified by:
getEntity in class ClientResponse<T>
Returns:

getMediaType

protected MediaType getMediaType()

readFrom

protected <T2> Object readFrom(Class<T2> type,
                               Type genericType,
                               MediaType media,
                               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 class ClientResponse<T>
Returns:

getEntity

public <T2> T2 getEntity(GenericType<T2> genericType,
                         Annotation[] ann)
Specified by:
getEntity in class ClientResponse<T>
Returns:

getHeaders

public MultivaluedMap<String,String> getHeaders()
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:
getHeaders in class ClientResponse<T>
Returns:

getMetadata

public MultivaluedMap<String,Object> getMetadata()
Description copied from class: Response
Get metadata associated with the response as a map. The returned map may be subsequently modified by the JAX-RS runtime. Values will be serialized using a RuntimeDelegate.HeaderDelegate if one is available via RuntimeDelegate.createHeaderDelegate(java.lang.Class) for the class of the value or using the values toString method if a header delegate is not available.

Specified by:
getMetadata in class Response
Returns:
response metadata as a map

getStatus

public int getStatus()
Description copied from class: Response
Get the status code associated with the response.

Specified by:
getStatus in class Response
Returns:
the response status code or -1 if the status was not set.

checkFailureStatus

public void checkFailureStatus()

createResponseFailure

public ClientResponseFailure createResponseFailure(String message)

createResponseFailure

public ClientResponseFailure createResponseFailure(String message,
                                                   Exception e)

getResponseStatus

public Response.Status getResponseStatus()
Specified by:
getResponseStatus in class ClientResponse<T>

wasReleased

public boolean wasReleased()

releaseConnection

public final void releaseConnection()
Specified by:
releaseConnection in class ClientResponse<T>

finalize

protected final void finalize()
                       throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 2013. All Rights Reserved.