|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.ws.rest.spi.container.AbstractContainerResponse
public abstract class AbstractContainerResponse
An abstract implementation of ContainerResponse
.
Specific containers may extend this class and instances may be passed to
the runtime using the method WebApplication.handleRequest(com.sun.ws.rest.spi.container.ContainerRequest, com.sun.ws.rest.spi.container.ContainerResponse)
.
When the call to the method WebApplication.handleRequest(com.sun.ws.rest.spi.container.ContainerRequest, com.sun.ws.rest.spi.container.ContainerResponse)
returns
a container must commit the response, if the response has not already been
committed, by committing the status and headers, and writing the entity
to the underlying output stream, for example:
if (!isCommitted()) { commitStatusAndHeaders(); writeEntity(getUnderlyingOutputStream()); }
The runtime may call the method getUnderlyingOutputStream()
and
before any bytes are written to this stream call the method
commitStatusAndHeaders(long)
. When one or more bytes are written to the
stream the response is marked as committed. Such behaviour arises when a
resource chooses to write an entity directly to an output stream obtained
from the method getOutputStream()
.
Constructor Summary | |
---|---|
protected |
AbstractContainerResponse(MessageBodyContext bodyContext,
ContainerRequest request)
|
Method Summary | |
---|---|
protected abstract void |
commitStatusAndHeaders(long contentLength)
Commit the status code and headers (if any) to the underlying container response. |
java.lang.Object |
getEntity()
Get the entity of the response |
java.lang.String |
getHeaderValue(java.lang.Object headerValue)
|
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. |
int |
getStatus()
Get the status of the response. |
protected abstract java.io.OutputStream |
getUnderlyingOutputStream()
Get the OutputStream provided by the underlying container response. |
boolean |
isCommitted()
Ascertain if a response has been committed to an underlying container. |
boolean |
isResponseSet()
Check if the response has been set using the setReponse methods. |
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 response,
javax.ws.rs.core.MediaType contentType)
Set the response state from a Response instance. |
void |
setStatus(int status)
Set the status of the response. |
protected void |
writeEntity()
Write the entity (if any) to the underlying output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractContainerResponse(MessageBodyContext bodyContext, ContainerRequest request)
bodyContext
- the message body context.request
- the container request associated with this response.Method Detail |
---|
protected abstract java.io.OutputStream getUnderlyingOutputStream() throws java.io.IOException
java.io.IOException
- if there is an error obtaining the
underlying OutputStream.protected abstract void commitStatusAndHeaders(long contentLength) throws java.io.IOException
contentLength
- the length, bytes, of the entity to be written,
otherwise -1 if the length is unknown.
java.io.IOException
- if an error commiting status and headers
occurs.public final void setResponse(javax.ws.rs.core.Response response)
HttpResponseContext
If an entity is set but there is no MIME media type declared for the Content-Type response header then the MIME media type will be set to "application/octet-stream".
setResponse
in interface HttpResponseContext
response
- the response.public final void setResponse(javax.ws.rs.core.Response response, javax.ws.rs.core.MediaType contentType)
HttpResponseContext
setResponse
in interface HttpResponseContext
response
- the response.contentType
- the MIME media type to use fot the Content-Type response
header if the header is not set by the response. If null then
"application/octet-stream" will be used.public final boolean isResponseSet()
HttpResponseContext
isResponseSet
in interface HttpResponseContext
public final int getStatus()
HttpResponseContext
getStatus
in interface HttpResponseContext
public final void setStatus(int status)
HttpResponseContext
setStatus
in interface HttpResponseContext
public final java.lang.Object getEntity()
HttpResponseContext
getEntity
in interface HttpResponseContext
public final void setEntity(java.lang.Object entity)
HttpResponseContext
setEntity
in interface HttpResponseContext
public final javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> getHttpHeaders()
HttpResponseContext
setHttpResponse
can change the HTTP response
headers and may overwrite headers set previously.
getHttpHeaders
in interface HttpResponseContext
public final java.io.OutputStream getOutputStream() throws java.io.IOException
HttpResponseContext
The first byte written will cause the status code and headers (if any) to be committed to the underlying container.
getOutputStream
in interface HttpResponseContext
java.io.IOException
- if an IO error occurspublic final boolean isCommitted()
HttpResponseContext
A response is committed if the status code, headers (if any) have been committed to the underlying container.
isCommitted
in interface HttpResponseContext
protected final void writeEntity() throws java.io.IOException
The status and headers will be committed by calling the method
commitStatusAndHeaders(long)
. The output stream will be obtained
by calling the method getUnderlyingOutputStream()
If a MessageBodyReader
cannot be found for the entity
then a 406 (Not Acceptable) response is returned.
java.io.IOException
- if there is an error writing the entitypublic java.lang.String getHeaderValue(java.lang.Object headerValue)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |