Class AtmosphereResponseImpl

java.lang.Object
jakarta.servlet.ServletResponseWrapper
jakarta.servlet.http.HttpServletResponseWrapper
org.atmosphere.cpr.AtmosphereResponseImpl
All Implemented Interfaces:
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse, AtmosphereResponse, CompletionAware

public class AtmosphereResponseImpl extends jakarta.servlet.http.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 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.
  • Constructor Details

    • AtmosphereResponseImpl

      public AtmosphereResponseImpl(AsyncIOWriter asyncIOWriter, AtmosphereRequest atmosphereRequest, boolean destroyable)
    • AtmosphereResponseImpl

      public AtmosphereResponseImpl(jakarta.servlet.http.HttpServletResponse r, AsyncIOWriter asyncIOWriter, AtmosphereRequest atmosphereRequest, boolean destroyable)
  • Method Details

    • destroy

      public void destroy()
      Specified by:
      destroy in interface AtmosphereResponse
    • destroy

      public void destroy(boolean force)
      Specified by:
      destroy in interface AtmosphereResponse
    • destroyed

      public boolean destroyed()
      Specified by:
      destroyed in interface AtmosphereResponse
    • addCookie

      public void addCookie(jakarta.servlet.http.Cookie cookie)
      Specified by:
      addCookie in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addCookie in class jakarta.servlet.http.HttpServletResponseWrapper
    • containsHeader

      public boolean containsHeader(String name)
      Specified by:
      containsHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      containsHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • encodeURL

      public String encodeURL(String url)
      Specified by:
      encodeURL in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      encodeURL in class jakarta.servlet.http.HttpServletResponseWrapper
    • encodeRedirectURL

      public String encodeRedirectURL(String url)
      Specified by:
      encodeRedirectURL in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      encodeRedirectURL in class jakarta.servlet.http.HttpServletResponseWrapper
    • encodeUrl

      public String encodeUrl(String url)
      Specified by:
      encodeUrl in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      encodeUrl in class jakarta.servlet.http.HttpServletResponseWrapper
    • encodeRedirectUrl

      public String encodeRedirectUrl(String url)
      Specified by:
      encodeRedirectUrl in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      encodeRedirectUrl in class jakarta.servlet.http.HttpServletResponseWrapper
    • delegateToNativeResponse

      public AtmosphereResponse delegateToNativeResponse(boolean delegateToNativeResponse)
      Specified by:
      delegateToNativeResponse in interface AtmosphereResponse
    • sendError

      public void sendError(int sc, String msg) throws IOException
      Specified by:
      sendError in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      sendError in class jakarta.servlet.http.HttpServletResponseWrapper
      Throws:
      IOException
    • sendError

      public void sendError(int sc) throws IOException
      Specified by:
      sendError in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      sendError in class jakarta.servlet.http.HttpServletResponseWrapper
      Throws:
      IOException
    • sendRedirect

      public void sendRedirect(String location) throws IOException
      Specified by:
      sendRedirect in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      sendRedirect in class jakarta.servlet.http.HttpServletResponseWrapper
      Throws:
      IOException
    • setDateHeader

      public void setDateHeader(String name, long date)
      Specified by:
      setDateHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setDateHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • addDateHeader

      public void addDateHeader(String name, long date)
      Specified by:
      addDateHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addDateHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • setHeader

      public void setHeader(String name, String value)
      Specified by:
      setHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • addHeader

      public void addHeader(String name, String value)
      Specified by:
      addHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • setIntHeader

      public void setIntHeader(String name, int value)
      Specified by:
      setIntHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setIntHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • addIntHeader

      public void addIntHeader(String name, int value)
      Specified by:
      addIntHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      addIntHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • setStatus

      public void setStatus(int status)
      Specified by:
      setStatus in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      setStatus in class jakarta.servlet.http.HttpServletResponseWrapper
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      getStatus in class jakarta.servlet.http.HttpServletResponseWrapper
    • getResponse

      public jakarta.servlet.ServletResponse getResponse()
      Specified by:
      getResponse in interface AtmosphereResponse
      Overrides:
      getResponse in class jakarta.servlet.ServletResponseWrapper
    • getStatusMessage

      public String getStatusMessage()
      Specified by:
      getStatusMessage in interface AtmosphereResponse
    • headers

      public Map<String,String> headers()
      Specified by:
      headers in interface AtmosphereResponse
    • getHeader

      public String getHeader(String name)
      Specified by:
      getHeader in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      getHeader in class jakarta.servlet.http.HttpServletResponseWrapper
    • getHeaders

      public Collection<String> getHeaders(String name)
      Specified by:
      getHeaders in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      getHeaders in class jakarta.servlet.http.HttpServletResponseWrapper
    • getHeaderNames

      public Collection<String> getHeaderNames()
      Specified by:
      getHeaderNames in interface jakarta.servlet.http.HttpServletResponse
      Overrides:
      getHeaderNames in class jakarta.servlet.http.HttpServletResponseWrapper
    • setCharacterEncoding

      public void setCharacterEncoding(String charSet)
      Specified by:
      setCharacterEncoding in interface jakarta.servlet.ServletResponse
      Overrides:
      setCharacterEncoding in class jakarta.servlet.ServletResponseWrapper
    • flushBuffer

      public void flushBuffer() throws IOException
      Specified by:
      flushBuffer in interface jakarta.servlet.ServletResponse
      Overrides:
      flushBuffer in class jakarta.servlet.ServletResponseWrapper
      Throws:
      IOException
    • getBufferSize

      public int getBufferSize()
      Specified by:
      getBufferSize in interface jakarta.servlet.ServletResponse
      Overrides:
      getBufferSize in class jakarta.servlet.ServletResponseWrapper
    • getCharacterEncoding

      public String getCharacterEncoding()
      Specified by:
      getCharacterEncoding in interface jakarta.servlet.ServletResponse
      Overrides:
      getCharacterEncoding in class jakarta.servlet.ServletResponseWrapper
    • isDestroyable

      public boolean isDestroyable()
      Description copied from interface: AtmosphereResponse
      Check if this object can be destroyed. Default is true.
      Specified by:
      isDestroyable in interface AtmosphereResponse
    • destroyable

      public AtmosphereResponse destroyable(boolean destroyable)
      Specified by:
      destroyable in interface AtmosphereResponse
    • getOutputStream

      public jakarta.servlet.ServletOutputStream getOutputStream() throws IOException
      Specified by:
      getOutputStream in interface jakarta.servlet.ServletResponse
      Overrides:
      getOutputStream in class jakarta.servlet.ServletResponseWrapper
      Throws:
      IOException
    • getWriter

      public PrintWriter getWriter() throws IOException
      Specified by:
      getWriter in interface jakarta.servlet.ServletResponse
      Overrides:
      getWriter in class jakarta.servlet.ServletResponseWrapper
      Throws:
      IOException
    • setContentLength

      public void setContentLength(int len)
      Specified by:
      setContentLength in interface jakarta.servlet.ServletResponse
      Overrides:
      setContentLength in class jakarta.servlet.ServletResponseWrapper
    • setContentType

      public void setContentType(String contentType)
      Specified by:
      setContentType in interface jakarta.servlet.ServletResponse
      Overrides:
      setContentType in class jakarta.servlet.ServletResponseWrapper
    • getContentType

      public String getContentType()
      Specified by:
      getContentType in interface jakarta.servlet.ServletResponse
      Overrides:
      getContentType in class jakarta.servlet.ServletResponseWrapper
    • isCommitted

      public boolean isCommitted()
      Specified by:
      isCommitted in interface jakarta.servlet.ServletResponse
      Overrides:
      isCommitted in class jakarta.servlet.ServletResponseWrapper
    • reset

      public void reset()
      Specified by:
      reset in interface jakarta.servlet.ServletResponse
      Overrides:
      reset in class jakarta.servlet.ServletResponseWrapper
    • resetBuffer

      public void resetBuffer()
      Specified by:
      resetBuffer in interface jakarta.servlet.ServletResponse
      Overrides:
      resetBuffer in class jakarta.servlet.ServletResponseWrapper
    • setBufferSize

      public void setBufferSize(int size)
      Specified by:
      setBufferSize in interface jakarta.servlet.ServletResponse
      Overrides:
      setBufferSize in class jakarta.servlet.ServletResponseWrapper
    • setLocale

      public void setLocale(Locale locale)
      Specified by:
      setLocale in interface jakarta.servlet.ServletResponse
      Overrides:
      setLocale in class jakarta.servlet.ServletResponseWrapper
    • getLocale

      public Locale getLocale()
      Specified by:
      getLocale in interface jakarta.servlet.ServletResponse
      Overrides:
      getLocale in class jakarta.servlet.ServletResponseWrapper
    • getAsyncIOWriter

      public AsyncIOWriter getAsyncIOWriter()
      Description copied from interface: AtmosphereResponse
      Return the underlying AsyncIOWriter.
      Specified by:
      getAsyncIOWriter in interface AtmosphereResponse
    • asyncIOWriter

      public AtmosphereResponse asyncIOWriter(AsyncIOWriter asyncIOWriter)
      Description copied from interface: AtmosphereResponse
      Set an implementation of AsyncIOWriter that will be invoked every time a write operation is ready to be processed.
      Specified by:
      asyncIOWriter in interface AtmosphereResponse
      Parameters:
      asyncIOWriter - of AsyncIOWriter
      Returns:
      this
    • writeThrough

      public <E extends Exception> void writeThrough(AsyncIOWriter writer, AtmosphereResponse.WriteAction<E> action) throws E
      Description copied from interface: AtmosphereResponse
      Run action with this response writing through writer on the calling thread only, then through its own writer again; another thread writing to the response meanwhile writes through its own writer. This default installs writer for every thread while action runs.
      Specified by:
      writeThrough in interface AtmosphereResponse
      Type Parameters:
      E - what action may throw
      Parameters:
      writer - the writer to write through while action runs
      action - what writes to the response through writer
      Throws:
      E - when action throws it
    • request

      public AtmosphereRequest request()
      Description copied from interface: AtmosphereResponse
      Return the associated AtmosphereRequest.
      Specified by:
      request in interface AtmosphereResponse
      Returns:
      the associated AtmosphereRequest
    • request

      public AtmosphereResponse request(AtmosphereRequest atmosphereRequest)
      Description copied from interface: AtmosphereResponse
      Set the associated AtmosphereRequest.
      Specified by:
      request in interface AtmosphereResponse
      Parameters:
      atmosphereRequest - a AtmosphereRequest
      Returns:
      this
    • close

      public void close() throws IOException
      Description copied from interface: AtmosphereResponse
      Close the associated AsyncIOWriter.
      Specified by:
      close in interface AtmosphereResponse
      Throws:
      IOException
    • closeStreamOrWriter

      public void closeStreamOrWriter()
      Description copied from interface: AtmosphereResponse
      Close the associated
      invalid reference
      PrintWriter
      or OutputStream
      Specified by:
      closeStreamOrWriter in interface AtmosphereResponse
    • write

      public AtmosphereResponse write(String data)
      Description copied from interface: AtmosphereResponse
      Write the String by either using the
      invalid reference
      PrintWriter
      or OutputStream. The decision is based on the request attribute ApplicationConfig.PROPERTY_USE_STREAM
      Specified by:
      write in interface AtmosphereResponse
      Parameters:
      data - the String to write
    • write

      public AtmosphereResponse write(String data, boolean writeUsingOriginalResponse)
      Description copied from interface: AtmosphereResponse
      Write the String by either using the
      invalid reference
      PrintWriter
      or OutputStream. The decision is based on the request attribute ApplicationConfig.PROPERTY_USE_STREAM. If writeUsingOriginalResponse is set to true, execute the write without invoking the defined AsyncIOWriter.
      Specified by:
      write in interface AtmosphereResponse
      Parameters:
      data - the String to write
      writeUsingOriginalResponse - if true, execute the write without invoking the AsyncIOWriter
    • write

      public AtmosphereResponse write(byte[] data)
      Description copied from interface: AtmosphereResponse
      Write the bytes by either using the
      invalid reference
      PrintWriter
      or OutputStream. The decision is based on the request attribute ApplicationConfig.PROPERTY_USE_STREAM.
      Specified by:
      write in interface AtmosphereResponse
      Parameters:
      data - the bytes to write
    • write

      public AtmosphereResponse write(byte[] data, boolean writeUsingOriginalResponse)
      Description copied from interface: AtmosphereResponse
      Write the String by either using the
      invalid reference
      PrintWriter
      or OutputStream. The decision is based on the request attribute ApplicationConfig.PROPERTY_USE_STREAM. If writeUsingOriginalResponse is set to true, execute the write without invoking the defined AsyncIOWriter.
      Specified by:
      write in interface AtmosphereResponse
      Parameters:
      data - the bytes to write
      writeUsingOriginalResponse - if true, execute the write without invoking the AsyncIOWriter
    • write

      public AtmosphereResponse write(byte[] data, int offset, int length)
      Description copied from interface: AtmosphereResponse
      Write the bytes by either using the
      invalid reference
      PrintWriter
      or OutputStream. The decision is based on the request attribute ApplicationConfig.PROPERTY_USE_STREAM.
      Specified by:
      write in interface AtmosphereResponse
      Parameters:
      data - the bytes to write
      offset - the first byte position to write
      length - the data length
    • write

      public AtmosphereResponse write(byte[] data, int offset, int length, boolean writeUsingOriginalResponse)
      Description copied from interface: AtmosphereResponse
      Write the String by either using the
      invalid reference
      PrintWriter
      or OutputStream. The decision is based on the request attribute ApplicationConfig.PROPERTY_USE_STREAM. If writeUsingOriginalResponse is set to true, execute the write without invoking the defined AsyncIOWriter.
      Specified by:
      write in interface AtmosphereResponse
      Parameters:
      data - the bytes to write
      offset - the first byte position to write
      length - the data length
      writeUsingOriginalResponse - if true, execute the write without invoking the AsyncIOWriter
    • resource

      public AtmosphereResource resource()
      Description copied from interface: AtmosphereResponse
      The AtmosphereResource associated with this request. If the request hasn't been suspended, this method will return null.
      Specified by:
      resource in interface AtmosphereResponse
      Returns:
      an AtmosphereResource, or null.
    • setResponse

      public void setResponse(jakarta.servlet.ServletResponse response)
      Specified by:
      setResponse in interface AtmosphereResponse
      Overrides:
      setResponse in class jakarta.servlet.ServletResponseWrapper
    • newInstance

      public static AtmosphereResponse newInstance()
      Create an instance not associated with any response parent.
    • newInstance

      public static AtmosphereResponse newInstance(AtmosphereRequest request)
      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

      public static AtmosphereResponse wrap(jakarta.servlet.http.HttpServletResponse response)
      Wrap an HttpServletResponse
      Parameters:
      response - HttpServletResponse
      Returns:
      an AtmosphereResponse
    • uuid

      public String uuid()
      Description copied from interface: AtmosphereResponse
      Return the AtmosphereResource.uuid() used by this object.
      Specified by:
      uuid in interface AtmosphereResponse
      Returns:
      the AtmosphereResource.uuid() used by this object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • onComplete

      public void onComplete()
      Specified by:
      onComplete in interface CompletionAware
    • completed

      public boolean completed()
      Specified by:
      completed in interface CompletionAware