Package org.atmosphere.cpr
Class AtmosphereResponseImpl
java.lang.Object
jakarta.servlet.ServletResponseWrapper
jakarta.servlet.http.HttpServletResponseWrapper
org.atmosphere.cpr.AtmosphereResponseImpl
- All Implemented Interfaces:
HttpServletResponse,ServletResponse,AtmosphereResponse,CompletionAware
public class AtmosphereResponseImpl
extends HttpServletResponseWrapper
implements AtmosphereResponse, CompletionAware
An Atmosphere's response representation. An AtmosphereResponse can be used to construct a bi-directional asynchronous
application. If the underlying transport is a WebSocket or if its associated
This object can delegate the write operation to
AtmosphereResource has been
suspended, this object can be used to write message back to the client at any moment.
This object can delegate the write operation to
AsyncIOWriter.-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface jakarta.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_FOUND, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY -
Constructor Summary
ConstructorsConstructorDescriptionAtmosphereResponseImpl(HttpServletResponse r, AsyncIOWriter asyncIOWriter, AtmosphereRequest atmosphereRequest, boolean destroyable) AtmosphereResponseImpl(AsyncIOWriter asyncIOWriter, AtmosphereRequest atmosphereRequest, boolean destroyable) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddDateHeader(String name, long date) voidvoidaddIntHeader(String name, int value) asyncIOWriter(AsyncIOWriter asyncIOWriter) Set an implementation ofAsyncIOWriterthat will be invoked every time a write operation is ready to be processed.voidclose()Close the associatedAsyncIOWriter.voidClose the associatedorinvalid reference
PrintWriterOutputStreambooleanbooleancontainsHeader(String name) delegateToNativeResponse(boolean delegateToNativeResponse) voiddestroy()voiddestroy(boolean force) destroyable(boolean destroyable) booleanencodeRedirectUrl(String url) encodeRedirectURL(String url) voidReturn the underlyingAsyncIOWriter.intgetHeaders(String name) intheaders()booleanbooleanCheck if this object can be destroyed.static AtmosphereResponseCreate an instance not associated with any response parent.static AtmosphereResponsenewInstance(AtmosphereConfig config, AtmosphereRequest request, WebSocket webSocket) Create a new instance to use with WebSocket.static AtmosphereResponsenewInstance(AtmosphereRequest request) Create a new instance to use with WebSocket.voidrequest()Return the associatedAtmosphereRequest.request(AtmosphereRequest atmosphereRequest) Set the associatedAtmosphereRequest.voidreset()voidresource()TheAtmosphereResourceassociated with this request.voidsendError(int sc) voidvoidsendRedirect(String location) voidsetBufferSize(int size) voidsetCharacterEncoding(String charSet) voidsetContentLength(int len) voidsetContentType(String contentType) voidsetDateHeader(String name, long date) voidvoidsetIntHeader(String name, int value) voidvoidsetResponse(ServletResponse response) voidsetStatus(int status) toString()uuid()Return theAtmosphereResource.uuid()used by this object.static AtmosphereResponsewrap(HttpServletResponse response) Wrap anHttpServletResponsewrite(byte[] data) Write the bytes by either using theorinvalid reference
PrintWriterOutputStream.write(byte[] data, boolean writeUsingOriginalResponse) Write the String by either using theorinvalid reference
PrintWriterOutputStream.write(byte[] data, int offset, int length) Write the bytes by either using theorinvalid reference
PrintWriterOutputStream.write(byte[] data, int offset, int length, boolean writeUsingOriginalResponse) Write the String by either using theorinvalid reference
PrintWriterOutputStream.Write the String by either using theorinvalid reference
PrintWriterOutputStream.Write the String by either using theorinvalid reference
PrintWriterOutputStream.Methods inherited from class jakarta.servlet.http.HttpServletResponseWrapper
getTrailerFields, setStatus, setTrailerFieldsMethods inherited from class jakarta.servlet.ServletResponseWrapper
isWrapperFor, isWrapperFor, setContentLengthLongMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface jakarta.servlet.http.HttpServletResponse
getTrailerFields, setStatus, setTrailerFieldsMethods inherited from interface jakarta.servlet.ServletResponse
setContentLengthLong
-
Constructor Details
-
AtmosphereResponseImpl
public AtmosphereResponseImpl(AsyncIOWriter asyncIOWriter, AtmosphereRequest atmosphereRequest, boolean destroyable) -
AtmosphereResponseImpl
public AtmosphereResponseImpl(HttpServletResponse r, AsyncIOWriter asyncIOWriter, AtmosphereRequest atmosphereRequest, boolean destroyable)
-
-
Method Details
-
destroy
public void destroy()- Specified by:
destroyin interfaceAtmosphereResponse
-
destroy
public void destroy(boolean force) - Specified by:
destroyin interfaceAtmosphereResponse
-
destroyed
public boolean destroyed()- Specified by:
destroyedin interfaceAtmosphereResponse
-
addCookie
- Specified by:
addCookiein interfaceHttpServletResponse- Overrides:
addCookiein classHttpServletResponseWrapper
-
containsHeader
- Specified by:
containsHeaderin interfaceHttpServletResponse- Overrides:
containsHeaderin classHttpServletResponseWrapper
-
encodeURL
- Specified by:
encodeURLin interfaceHttpServletResponse- Overrides:
encodeURLin classHttpServletResponseWrapper
-
encodeRedirectURL
- Specified by:
encodeRedirectURLin interfaceHttpServletResponse- Overrides:
encodeRedirectURLin classHttpServletResponseWrapper
-
encodeUrl
- Specified by:
encodeUrlin interfaceHttpServletResponse- Overrides:
encodeUrlin classHttpServletResponseWrapper
-
encodeRedirectUrl
- Specified by:
encodeRedirectUrlin interfaceHttpServletResponse- Overrides:
encodeRedirectUrlin classHttpServletResponseWrapper
-
delegateToNativeResponse
- Specified by:
delegateToNativeResponsein interfaceAtmosphereResponse
-
sendError
- Specified by:
sendErrorin interfaceHttpServletResponse- Overrides:
sendErrorin classHttpServletResponseWrapper- Throws:
IOException
-
sendError
- Specified by:
sendErrorin interfaceHttpServletResponse- Overrides:
sendErrorin classHttpServletResponseWrapper- Throws:
IOException
-
sendRedirect
- Specified by:
sendRedirectin interfaceHttpServletResponse- Overrides:
sendRedirectin classHttpServletResponseWrapper- Throws:
IOException
-
setDateHeader
- Specified by:
setDateHeaderin interfaceHttpServletResponse- Overrides:
setDateHeaderin classHttpServletResponseWrapper
-
addDateHeader
- Specified by:
addDateHeaderin interfaceHttpServletResponse- Overrides:
addDateHeaderin classHttpServletResponseWrapper
-
setHeader
- Specified by:
setHeaderin interfaceHttpServletResponse- Overrides:
setHeaderin classHttpServletResponseWrapper
-
addHeader
- Specified by:
addHeaderin interfaceHttpServletResponse- Overrides:
addHeaderin classHttpServletResponseWrapper
-
setIntHeader
- Specified by:
setIntHeaderin interfaceHttpServletResponse- Overrides:
setIntHeaderin classHttpServletResponseWrapper
-
addIntHeader
- Specified by:
addIntHeaderin interfaceHttpServletResponse- Overrides:
addIntHeaderin classHttpServletResponseWrapper
-
setStatus
public void setStatus(int status) - Specified by:
setStatusin interfaceHttpServletResponse- Overrides:
setStatusin classHttpServletResponseWrapper
-
getStatus
public int getStatus()- Specified by:
getStatusin interfaceHttpServletResponse- Overrides:
getStatusin classHttpServletResponseWrapper
-
getResponse
- Specified by:
getResponsein interfaceAtmosphereResponse- Overrides:
getResponsein classServletResponseWrapper
-
getStatusMessage
- Specified by:
getStatusMessagein interfaceAtmosphereResponse
-
headers
- Specified by:
headersin interfaceAtmosphereResponse
-
getHeader
- Specified by:
getHeaderin interfaceHttpServletResponse- Overrides:
getHeaderin classHttpServletResponseWrapper
-
getHeaders
- Specified by:
getHeadersin interfaceHttpServletResponse- Overrides:
getHeadersin classHttpServletResponseWrapper
-
getHeaderNames
- Specified by:
getHeaderNamesin interfaceHttpServletResponse- Overrides:
getHeaderNamesin classHttpServletResponseWrapper
-
setCharacterEncoding
- Specified by:
setCharacterEncodingin interfaceServletResponse- Overrides:
setCharacterEncodingin classServletResponseWrapper
-
flushBuffer
- Specified by:
flushBufferin interfaceServletResponse- Overrides:
flushBufferin classServletResponseWrapper- Throws:
IOException
-
getBufferSize
public int getBufferSize()- Specified by:
getBufferSizein interfaceServletResponse- Overrides:
getBufferSizein classServletResponseWrapper
-
getCharacterEncoding
- Specified by:
getCharacterEncodingin interfaceServletResponse- Overrides:
getCharacterEncodingin classServletResponseWrapper
-
isDestroyable
public boolean isDestroyable()Description copied from interface:AtmosphereResponseCheck if this object can be destroyed. Default is true.- Specified by:
isDestroyablein interfaceAtmosphereResponse
-
destroyable
- Specified by:
destroyablein interfaceAtmosphereResponse
-
getOutputStream
- Specified by:
getOutputStreamin interfaceServletResponse- Overrides:
getOutputStreamin classServletResponseWrapper- Throws:
IOException
-
getWriter
- Specified by:
getWriterin interfaceServletResponse- Overrides:
getWriterin classServletResponseWrapper- Throws:
IOException
-
setContentLength
public void setContentLength(int len) - Specified by:
setContentLengthin interfaceServletResponse- Overrides:
setContentLengthin classServletResponseWrapper
-
setContentType
- Specified by:
setContentTypein interfaceServletResponse- Overrides:
setContentTypein classServletResponseWrapper
-
getContentType
- Specified by:
getContentTypein interfaceServletResponse- Overrides:
getContentTypein classServletResponseWrapper
-
isCommitted
public boolean isCommitted()- Specified by:
isCommittedin interfaceServletResponse- Overrides:
isCommittedin classServletResponseWrapper
-
reset
public void reset()- Specified by:
resetin interfaceServletResponse- Overrides:
resetin classServletResponseWrapper
-
resetBuffer
public void resetBuffer()- Specified by:
resetBufferin interfaceServletResponse- Overrides:
resetBufferin classServletResponseWrapper
-
setBufferSize
public void setBufferSize(int size) - Specified by:
setBufferSizein interfaceServletResponse- Overrides:
setBufferSizein classServletResponseWrapper
-
setLocale
- Specified by:
setLocalein interfaceServletResponse- Overrides:
setLocalein classServletResponseWrapper
-
getLocale
- Specified by:
getLocalein interfaceServletResponse- Overrides:
getLocalein classServletResponseWrapper
-
getAsyncIOWriter
Description copied from interface:AtmosphereResponseReturn the underlyingAsyncIOWriter.- Specified by:
getAsyncIOWriterin interfaceAtmosphereResponse
-
asyncIOWriter
Description copied from interface:AtmosphereResponseSet an implementation ofAsyncIOWriterthat will be invoked every time a write operation is ready to be processed.- Specified by:
asyncIOWriterin interfaceAtmosphereResponse- Parameters:
asyncIOWriter- ofAsyncIOWriter- Returns:
- this
-
request
Description copied from interface:AtmosphereResponseReturn the associatedAtmosphereRequest.- Specified by:
requestin interfaceAtmosphereResponse- Returns:
- the associated
AtmosphereRequest
-
request
Description copied from interface:AtmosphereResponseSet the associatedAtmosphereRequest.- Specified by:
requestin interfaceAtmosphereResponse- Parameters:
atmosphereRequest- aAtmosphereRequest- Returns:
- this
-
close
Description copied from interface:AtmosphereResponseClose the associatedAsyncIOWriter.- Specified by:
closein interfaceAtmosphereResponse- Throws:
IOException
-
closeStreamOrWriter
public void closeStreamOrWriter()Description copied from interface:AtmosphereResponseClose the associatedorinvalid reference
PrintWriterOutputStream- Specified by:
closeStreamOrWriterin interfaceAtmosphereResponse
-
write
Description copied from interface:AtmosphereResponseWrite the String by either using theorinvalid reference
PrintWriterOutputStream. The decision is based on the request attributeApplicationConfig.PROPERTY_USE_STREAM- Specified by:
writein interfaceAtmosphereResponse- Parameters:
data- the String to write
-
write
Description copied from interface:AtmosphereResponseWrite the String by either using theorinvalid reference
PrintWriterOutputStream. The decision is based on the request attributeApplicationConfig.PROPERTY_USE_STREAM. If writeUsingOriginalResponse is set to true, execute the write without invoking the definedAsyncIOWriter.- Specified by:
writein interfaceAtmosphereResponse- Parameters:
data- the String to writewriteUsingOriginalResponse- if true, execute the write without invoking theAsyncIOWriter
-
write
Description copied from interface:AtmosphereResponseWrite the bytes by either using theorinvalid reference
PrintWriterOutputStream. The decision is based on the request attributeApplicationConfig.PROPERTY_USE_STREAM.- Specified by:
writein interfaceAtmosphereResponse- Parameters:
data- the bytes to write
-
write
Description copied from interface:AtmosphereResponseWrite the String by either using theorinvalid reference
PrintWriterOutputStream. The decision is based on the request attributeApplicationConfig.PROPERTY_USE_STREAM. If writeUsingOriginalResponse is set to true, execute the write without invoking the definedAsyncIOWriter.- Specified by:
writein interfaceAtmosphereResponse- Parameters:
data- the bytes to writewriteUsingOriginalResponse- if true, execute the write without invoking theAsyncIOWriter
-
write
Description copied from interface:AtmosphereResponseWrite the bytes by either using theorinvalid reference
PrintWriterOutputStream. The decision is based on the request attributeApplicationConfig.PROPERTY_USE_STREAM.- Specified by:
writein interfaceAtmosphereResponse- Parameters:
data- the bytes to writeoffset- the first byte position to writelength- the data length
-
write
public AtmosphereResponse write(byte[] data, int offset, int length, boolean writeUsingOriginalResponse) Description copied from interface:AtmosphereResponseWrite the String by either using theorinvalid reference
PrintWriterOutputStream. The decision is based on the request attributeApplicationConfig.PROPERTY_USE_STREAM. If writeUsingOriginalResponse is set to true, execute the write without invoking the definedAsyncIOWriter.- Specified by:
writein interfaceAtmosphereResponse- Parameters:
data- the bytes to writeoffset- the first byte position to writelength- the data lengthwriteUsingOriginalResponse- if true, execute the write without invoking theAsyncIOWriter
-
resource
Description copied from interface:AtmosphereResponseTheAtmosphereResourceassociated with this request. If the request hasn't been suspended, this method will return null.- Specified by:
resourcein interfaceAtmosphereResponse- Returns:
- an
AtmosphereResource, or null.
-
setResponse
- Specified by:
setResponsein interfaceAtmosphereResponse- Overrides:
setResponsein classServletResponseWrapper
-
newInstance
Create an instance not associated with any response parent. -
newInstance
Create a new instance to use with WebSocket. -
newInstance
public static AtmosphereResponse newInstance(AtmosphereConfig config, AtmosphereRequest request, WebSocket webSocket) Create a new instance to use with WebSocket. -
wrap
Wrap anHttpServletResponse- Parameters:
response-HttpServletResponse- Returns:
- an
AtmosphereResponse
-
uuid
Description copied from interface:AtmosphereResponseReturn theAtmosphereResource.uuid()used by this object.- Specified by:
uuidin interfaceAtmosphereResponse- Returns:
- the
AtmosphereResource.uuid()used by this object.
-
toString
-
onComplete
public void onComplete()- Specified by:
onCompletein interfaceCompletionAware
-
completed
public boolean completed()- Specified by:
completedin interfaceCompletionAware
-