com.sun.jersey.api.core
Interface HttpResponseContext

All Known Implementing Classes:
AdaptingContainerResponse, ContainerResponse

public interface HttpResponseContext

An abstraction of a HTTP response.

The default state is a HTTP response with a status code of 204 (No Content) with no headers and entity.


Method Summary
 java.lang.annotation.Annotation[] getAnnotations()
          Get the annotations associated with the response entity (if any).
 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.
 java.lang.Object getOriginalEntity()
          Get the original entity instance that was set by 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.
 void setAnnotations(java.lang.annotation.Annotation[] annotations)
          Set the annotations associated with the response entity (if any).
 void setEntity(java.lang.Object entity)
          Set the entity of the response.
 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.
 

Method Detail

getResponse

Response getResponse()
Get the response that was set.

Returns:
the response.

setResponse

void setResponse(Response response)
Set the response state from a Response instance. This replaces a pre-existing response state.

Parameters:
response - the response.

isResponseSet

boolean isResponseSet()
Check if the response has been set using the setReponse methods.

Returns:
true if the response has been set.

getMappedThrowable

java.lang.Throwable getMappedThrowable()
Get the throwable (if any) that was mapped to a response.

Returns:
the throwable that was mapped to a response, otherwise null if no throwable was mapped to a response.

getStatusType

Response.StatusType getStatusType()
Returns:
the status type of the response

setStatusType

void setStatusType(Response.StatusType statusType)
Set the status type of the response.

Parameters:
statusType - the status type.

getStatus

int getStatus()
Returns:
the status of the response

setStatus

void setStatus(int status)
Set the status of the response.

Parameters:
status - the status.

getEntity

java.lang.Object getEntity()
Returns:
the entity of the response.

getEntityType

java.lang.reflect.Type getEntityType()
Returns:
the type of the entity.

getOriginalEntity

java.lang.Object getOriginalEntity()
Get the original entity instance that was set by setEntity(java.lang.Object).


setEntity

void setEntity(java.lang.Object entity)
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 getOriginalEntity(), for example:

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

Parameters:
entity - the entity.

getAnnotations

java.lang.annotation.Annotation[] getAnnotations()
Get the annotations associated with the response entity (if any).

Returns:
the annotations.

setAnnotations

void setAnnotations(java.lang.annotation.Annotation[] annotations)
Set the annotations associated with the response entity (if any).

Parameters:
annotations - the annotations.

getHttpHeaders

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

Returns:
a mutable map of headerd.

getMediaType

MediaType getMediaType()
Get the media type of the response entity.

Returns:
the media type or null if there is no response entity.

getOutputStream

java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
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.

Returns:
the output stream
Throws:
java.io.IOException - if an IO error occurs

isCommitted

boolean isCommitted()
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.

Returns:
true if the response has been committed.


Copyright © 2011 Oracle Corporation. All Rights Reserved.