com.sun.jersey.spi.container
Class ContainerResponse

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

public class ContainerResponse
extends java.lang.Object
implements HttpResponseContext

An out-bound HTTP response to be processed by the web application.

Containers instantiate, or inherit, and provide an instance to the WebApplication.

Author:
Paul.Sandoz@Sun.Com

Constructor Summary
ContainerResponse(WebApplication wa, ContainerRequest request, ContainerResponseWriter responseWriter)
          Instantate a new ContainerResponse.
 
Method Summary
 java.lang.annotation.Annotation[] getAnnotations()
          Get the annotations associated with the response entity (if any).
 ContainerResponseWriter getContainerResponseWriter()
          Get the container response writer.
 java.lang.Object getEntity()
           
 java.lang.reflect.Type getEntityType()
           
static java.lang.String getHeaderValue(java.lang.Object headerValue)
          Convert a header value, represented as a general object, to the string value.
 javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> getHttpHeaders()
          Get the HTTP response headers.
 java.io.OutputStream getOutputStream()
          Get an OutputStream to which an entity may be written.
 javax.ws.rs.core.Response getResponse()
          Get the response that was set.
 int getStatus()
           
 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.
 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 setContainerResponseWriter(ContainerResponseWriter responseWriter)
          Set the container response writer.
 void setEntity(java.lang.Object entity)
          Set the entity of the response.
 void setResponse(javax.ws.rs.core.Response response)
          Set the response state from a Response instance.
 void setResponse(javax.ws.rs.core.Response r, javax.ws.rs.core.MediaType contentType)
          Set the response state from a Response instance.
 void setStatus(int status)
          Set the status of the response.
 void write()
          Write the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContainerResponse

public ContainerResponse(WebApplication wa,
                         ContainerRequest request,
                         ContainerResponseWriter responseWriter)
Instantate a new ContainerResponse.

Parameters:
wa - the web application.
request - the container request associated with this response.
responseWriter - the response writer
Method Detail

getHeaderValue

public static java.lang.String getHeaderValue(java.lang.Object headerValue)
Convert a header value, represented as a general object, to the string value.

This method defers to RuntimeDelegate.createHeaderDelegate(java.lang.Class) to obtain a RuntimeDelegate.HeaderDelegate to convert the value to a string.

Containers may use this method to convert the header values obtained from the getHttpHeaders()

Parameters:
headerValue - the header value as an object
Returns:
the string value

write

public void write()
           throws java.io.IOException
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.

Throws:
javax.ws.rs.WebApplicationException - if MessageBodyWriter cannot be found for the entity with a 406 (Not Acceptable) response.
java.io.IOException - if there is an error writing the entity

reset

public void reset()
Reset the response to 204 (No content) with no headers.


getContainerResponseWriter

public ContainerResponseWriter getContainerResponseWriter()
Get the container response writer.

Returns:
the container response writer

setContainerResponseWriter

public void setContainerResponseWriter(ContainerResponseWriter responseWriter)
Set the container response writer.

Parameters:
responseWriter - the container response writer

getResponse

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

Specified by:
getResponse in interface HttpResponseContext
Returns:
the response.

setResponse

public void setResponse(javax.ws.rs.core.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
Parameters:
response - the response.

setResponse

public void setResponse(javax.ws.rs.core.Response r,
                        javax.ws.rs.core.MediaType contentType)
Description copied from interface: HttpResponseContext
Set the response state from a Response instance. This replaces any pre-existing response state.

Specified by:
setResponse in interface HttpResponseContext
Parameters:
r - the response.
contentType - the MIME media type to use for the Content-Type response header if the header is not set by 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
Returns:
true if the response has been set.

getStatus

public int getStatus()
Specified by:
getStatus in interface HttpResponseContext
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
Parameters:
status - the status.

getEntity

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

getEntityType

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

setEntity

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

Specified by:
setEntity in interface HttpResponseContext
Parameters:
entity - the entity. If the entity is an instance of GenericEntity then the entity and entity type are set from the entity and type of that GenericEntity.

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
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
Parameters:
annotations - the annotations.

getHttpHeaders

public javax.ws.rs.core.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
Returns:
a mutable map of headerd.

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
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
Returns:
true if the response has been committed.


Copyright © 2008 Sun Microsystems, Inc. All Rights Reserved.