com.sun.jersey.spi.container
Class AdaptingContainerResponse

java.lang.Object
  extended by com.sun.jersey.spi.container.ContainerResponse
      extended by com.sun.jersey.spi.container.AdaptingContainerResponse
All Implemented Interfaces:
HttpResponseContext

public class AdaptingContainerResponse
extends ContainerResponse

An adapting in-bound HTTP response that may override the behaviour of ContainerResponse.

Author:
[email protected]

Field Summary
protected  ContainerResponse acr
          The adapted container response.
 
Constructor Summary
protected AdaptingContainerResponse(ContainerResponse acr)
          Create the adapting container response.
 
Method Summary
 java.lang.annotation.Annotation[] getAnnotations()
          Get the annotations associated with the response entity (if any).
 ContainerRequest getContainerRequest()
          Get the container request.
 ContainerResponseWriter getContainerResponseWriter()
          Get the container response writer.
 java.lang.Object getEntity()
           
 java.lang.reflect.Type getEntityType()
           
 MultivaluedMap<java.lang.String,java.lang.Object> getHttpHeaders()
          Get the HTTP response headers.
 java.lang.Throwable getMappedThrowable()
          Get the throwable (if any) that was mapped to a response.
 MediaType getMediaType()
          Get the media type of the response entity.
 MessageBodyWorkers getMessageBodyWorkers()
          Get the message body workers.
 java.lang.Object getOriginalEntity()
          Get the original entity instance that was set by HttpResponseContext.setEntity(java.lang.Object).
 java.io.OutputStream getOutputStream()
          Get an OutputStream to which an entity may be written.
 Response getResponse()
          Get the response that was set.
 int getStatus()
           
 Response.StatusType getStatusType()
           
 boolean isCommitted()
          Ascertain if a response has been committed to the container.
 boolean isResponseSet()
          Check if the response has been set using the setReponse methods.
 boolean mapException(java.lang.Throwable e)
          Map an exception to a response.
 void mapMappableContainerException(MappableContainerException e)
          Map the cause of a mapable container exception to a response.
 void mapWebApplicationException(WebApplicationException e)
          Map a web application exception to a response.
 void reset()
          Reset the response to 204 (No content) with no headers.
 void setAnnotations(java.lang.annotation.Annotation[] annotations)
          Set the annotations associated with the response entity (if any).
 void setContainerRequest(ContainerRequest request)
          Set the container request.
 void setContainerResponseWriter(ContainerResponseWriter responseWriter)
          Set the container response writer.
 void setEntity(java.lang.Object entity)
          Set the entity of the response.
 void setEntity(java.lang.Object entity, java.lang.reflect.Type entityType)
           
 void setResponse(Response response)
          Set the response state from a Response instance.
 void setStatus(int status)
          Set the status of the response.
 void setStatusType(Response.StatusType statusType)
          Set the status type of the response.
 void write()
          Write the response.
 
Methods inherited from class com.sun.jersey.spi.container.ContainerResponse
getHeaderValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

acr

protected final ContainerResponse acr
The adapted container response.

Constructor Detail

AdaptingContainerResponse

protected AdaptingContainerResponse(ContainerResponse acr)
Create the adapting container response.

Parameters:
acr - the container response to adapt.
Method Detail

write

public void write()
           throws java.io.IOException
Description copied from class: ContainerResponse
Write the response.

The status and headers will be written by calling the method ContainerResponseWriter.writeStatusAndHeaders(long, com.sun.jersey.spi.container.ContainerResponse) on the provided ContainerResponseWriter instance. The OutputStream returned from that method call is used to write the entity (if any) to that OutputStream. An appropriate MessageBodyWriter will be found to write the entity.

Overrides:
write in class ContainerResponse
Throws:
java.io.IOException - if there is an error writing the entity

reset

public void reset()
Description copied from class: ContainerResponse
Reset the response to 204 (No content) with no headers.

Overrides:
reset in class ContainerResponse

getContainerRequest

public ContainerRequest getContainerRequest()
Description copied from class: ContainerResponse
Get the container request.

Overrides:
getContainerRequest in class ContainerResponse
Returns:
the container request.

setContainerRequest

public void setContainerRequest(ContainerRequest request)
Description copied from class: ContainerResponse
Set the container request.

Overrides:
setContainerRequest in class ContainerResponse
Parameters:
request - the container request.

getContainerResponseWriter

public ContainerResponseWriter getContainerResponseWriter()
Description copied from class: ContainerResponse
Get the container response writer.

Overrides:
getContainerResponseWriter in class ContainerResponse
Returns:
the container response writer

setContainerResponseWriter

public void setContainerResponseWriter(ContainerResponseWriter responseWriter)
Description copied from class: ContainerResponse
Set the container response writer.

Overrides:
setContainerResponseWriter in class ContainerResponse
Parameters:
responseWriter - the container response writer

getMessageBodyWorkers

public MessageBodyWorkers getMessageBodyWorkers()
Description copied from class: ContainerResponse
Get the message body workers.

Overrides:
getMessageBodyWorkers in class ContainerResponse
Returns:
the message body workers.

mapMappableContainerException

public void mapMappableContainerException(MappableContainerException e)
Description copied from class: ContainerResponse
Map the cause of a mapable container exception to a response.

If the cause cannot be mapped and then that cause is re-thrown if a runtime exception otherwise the mappable contaner exception is re-thrown.

Overrides:
mapMappableContainerException in class ContainerResponse
Parameters:
e - the mappable container exception whose cause will be mapped to a response.

mapWebApplicationException

public void mapWebApplicationException(WebApplicationException e)
Description copied from class: ContainerResponse
Map a web application exception to a response.

Overrides:
mapWebApplicationException in class ContainerResponse
Parameters:
e - the web application exception.

mapException

public boolean mapException(java.lang.Throwable e)
Description copied from class: ContainerResponse
Map an exception to a response.

Overrides:
mapException in class ContainerResponse
Parameters:
e - the exception.
Returns:
true if the exception was mapped, otherwise false.

getResponse

public Response getResponse()
Description copied from interface: HttpResponseContext
Get the response that was set.

Specified by:
getResponse in interface HttpResponseContext
Overrides:
getResponse in class ContainerResponse
Returns:
the response.

setResponse

public void setResponse(Response response)
Description copied from interface: HttpResponseContext
Set the response state from a Response instance. This replaces a pre-existing response state.

Specified by:
setResponse in interface HttpResponseContext
Overrides:
setResponse in class ContainerResponse
Parameters:
response - the response.

isResponseSet

public boolean isResponseSet()
Description copied from interface: HttpResponseContext
Check if the response has been set using the setReponse methods.

Specified by:
isResponseSet in interface HttpResponseContext
Overrides:
isResponseSet in class ContainerResponse
Returns:
true if the response has been set.

getMappedThrowable

public java.lang.Throwable getMappedThrowable()
Description copied from interface: HttpResponseContext
Get the throwable (if any) that was mapped to a response.

Specified by:
getMappedThrowable in interface HttpResponseContext
Overrides:
getMappedThrowable in class ContainerResponse
Returns:
the throwable that was mapped to a response, otherwise null if no throwable was mapped to a response.

getStatusType

public Response.StatusType getStatusType()
Specified by:
getStatusType in interface HttpResponseContext
Overrides:
getStatusType in class ContainerResponse
Returns:
the status type of the response

setStatusType

public void setStatusType(Response.StatusType statusType)
Description copied from interface: HttpResponseContext
Set the status type of the response.

Specified by:
setStatusType in interface HttpResponseContext
Overrides:
setStatusType in class ContainerResponse
Parameters:
statusType - the status type.

getStatus

public int getStatus()
Specified by:
getStatus in interface HttpResponseContext
Overrides:
getStatus in class ContainerResponse
Returns:
the status of the response

setStatus

public void setStatus(int status)
Description copied from interface: HttpResponseContext
Set the status of the response.

Specified by:
setStatus in interface HttpResponseContext
Overrides:
setStatus in class ContainerResponse
Parameters:
status - the status.

getEntity

public java.lang.Object getEntity()
Specified by:
getEntity in interface HttpResponseContext
Overrides:
getEntity in class ContainerResponse
Returns:
the entity of the response.

getEntityType

public java.lang.reflect.Type getEntityType()
Specified by:
getEntityType in interface HttpResponseContext
Overrides:
getEntityType in class ContainerResponse
Returns:
the type of the entity.

getOriginalEntity

public java.lang.Object getOriginalEntity()
Description copied from interface: HttpResponseContext
Get the original entity instance that was set by HttpResponseContext.setEntity(java.lang.Object).

Specified by:
getOriginalEntity in interface HttpResponseContext
Overrides:
getOriginalEntity in class ContainerResponse

setEntity

public void setEntity(java.lang.Object entity)
Description copied from interface: HttpResponseContext
Set the entity of the response.

If the entity is an instance of GenericEntity then the entity and entity type are set from the entity and type of that GenericEntity. Otherwise, the entity is set from the entity parameter and the type is the class of that parameter.

If it is necessary to wrap an entity that may have been set with an instance of GenericEntity then utilize the HttpResponseContext.getOriginalEntity(), for example:

     HttpResponseContext r = ...
     r.setEntity(wrap(getOriginalEntity()));
 

Specified by:
setEntity in interface HttpResponseContext
Overrides:
setEntity in class ContainerResponse
Parameters:
entity - the entity.

setEntity

public void setEntity(java.lang.Object entity,
                      java.lang.reflect.Type entityType)
Overrides:
setEntity in class ContainerResponse

getAnnotations

public java.lang.annotation.Annotation[] getAnnotations()
Description copied from interface: HttpResponseContext
Get the annotations associated with the response entity (if any).

Specified by:
getAnnotations in interface HttpResponseContext
Overrides:
getAnnotations in class ContainerResponse
Returns:
the annotations.

setAnnotations

public void setAnnotations(java.lang.annotation.Annotation[] annotations)
Description copied from interface: HttpResponseContext
Set the annotations associated with the response entity (if any).

Specified by:
setAnnotations in interface HttpResponseContext
Overrides:
setAnnotations in class ContainerResponse
Parameters:
annotations - the annotations.

getHttpHeaders

public MultivaluedMap<java.lang.String,java.lang.Object> getHttpHeaders()
Description copied from interface: HttpResponseContext
Get the HTTP response headers. The returned map is case-insensitive with respect to the keys (header values). The method HttpResponseContext.setResponse(javax.ws.rs.core.Response) will replace any headers previously set.

Specified by:
getHttpHeaders in interface HttpResponseContext
Overrides:
getHttpHeaders in class ContainerResponse
Returns:
a mutable map of headerd.

getMediaType

public MediaType getMediaType()
Description copied from interface: HttpResponseContext
Get the media type of the response entity.

Specified by:
getMediaType in interface HttpResponseContext
Overrides:
getMediaType in class ContainerResponse
Returns:
the media type or null if there is no response entity.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Description copied from interface: HttpResponseContext
Get an OutputStream to which an entity may be written.

The first byte written will result in the writing of thethe status code and headers.

Specified by:
getOutputStream in interface HttpResponseContext
Overrides:
getOutputStream in class ContainerResponse
Returns:
the output stream
Throws:
java.io.IOException - if an IO error occurs

isCommitted

public boolean isCommitted()
Description copied from interface: HttpResponseContext
Ascertain if a response has been committed to the container.

A response is committed if the status code, headers have been written to the container.

Specified by:
isCommitted in interface HttpResponseContext
Overrides:
isCommitted in class ContainerResponse
Returns:
true if the response has been committed.


Copyright © 2011 Oracle Corporation. All Rights Reserved.