Class DefaultWebApplicationResponse

java.lang.Object
java.io.OutputStream
javax.servlet.ServletOutputStream
cloud.piranha.webapp.impl.DefaultWebApplicationResponse
All Implemented Interfaces:
WebApplicationResponse, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, HttpServletResponse, ServletResponse
Direct Known Subclasses:
DefaultWebApplicationServerResponse, EmbeddedResponse, NanoResponse

public class DefaultWebApplicationResponse
extends ServletOutputStream
implements WebApplicationResponse
The default WebApplicationResponse.
Author:
Manfred Riem ([email protected])
  • Field Details

    • bodyOnly

      protected boolean bodyOnly
      Stores the body only flag.
    • buffer

      protected byte[] buffer
      Stores the buffer.
    • characterEncoding

      protected java.lang.String characterEncoding
      Stores the character encoding.
    • characterEncodingSet

      protected boolean characterEncodingSet
      Stores if the character encoding has been set manually.
    • committed

      protected boolean committed
      Stores the committed flag.
    • contentLength

      protected long contentLength
      Stores the content length.
    • contentType

      protected java.lang.String contentType
      Stores the content type.
    • contentTypeSet

      protected boolean contentTypeSet
      Stores if the content type has been set manually.
    • cookies

      protected java.util.List<Cookie> cookies
      Stores the cookies.
    • gotOutput

      protected boolean gotOutput
      Stores if we acquired the output stream.
    • gotWriter

      protected boolean gotWriter
      Stores if we acquired the writer.
    • headerManager

      protected DefaultHttpHeaderManager headerManager
      Stores the header manager.
    • index

      protected int index
      Stores the index.
    • locale

      protected java.util.Locale locale
      Stores the locale.
    • writer

      protected java.io.PrintWriter writer
      Stores the writer.
    • outputStream

      protected java.io.OutputStream outputStream
      Stores the output stream.
    • status

      protected int status
      Stores the status code.
    • statusMessage

      protected java.lang.String statusMessage
      Stores the status message.
    • webApplication

      protected WebApplication webApplication
      Stores the web application.
  • Constructor Details

  • Method Details

    • addCookie

      public void addCookie​(Cookie cookie)
      Add the cookie.
      Specified by:
      addCookie in interface HttpServletResponse
      Parameters:
      cookie - the cookie.
    • addDateHeader

      public void addDateHeader​(java.lang.String name, long date)
      Add the date header.
      Specified by:
      addDateHeader in interface HttpServletResponse
      Parameters:
      name - the header name.
      date - the header date value.
    • addHeader

      public void addHeader​(java.lang.String name, java.lang.String value)
      Add the header.
      Specified by:
      addHeader in interface HttpServletResponse
      Parameters:
      name - the name.
      value - the value.
    • addIntHeader

      public void addIntHeader​(java.lang.String name, int value)
      Add the integer header.
      Specified by:
      addIntHeader in interface HttpServletResponse
      Parameters:
      name - the name of the header.
      value - the value of the header.
    • containsHeader

      public boolean containsHeader​(java.lang.String name)
      Contains the given header.
      Specified by:
      containsHeader in interface HttpServletResponse
      Parameters:
      name - the header name.
      Returns:
      true if there, false otherwise.
    • encodeRedirectURL

      public java.lang.String encodeRedirectURL​(java.lang.String url)
      Encode the redirect URL.
      Specified by:
      encodeRedirectURL in interface HttpServletResponse
      Parameters:
      url - the url.
      Returns:
      the encoded redirect url.
    • encodeRedirectUrl

      @Deprecated public java.lang.String encodeRedirectUrl​(java.lang.String url)
      Deprecated.
      Encode the redirect url.
      Specified by:
      encodeRedirectUrl in interface HttpServletResponse
      Parameters:
      url - the url.
      Returns:
      the encoded redirect url.
    • encodeURL

      public java.lang.String encodeURL​(java.lang.String url)
      Encode the URL.
      Specified by:
      encodeURL in interface HttpServletResponse
      Parameters:
      url - the URL.
      Returns:
      the encoded url.
    • encodeUrl

      @Deprecated public java.lang.String encodeUrl​(java.lang.String url)
      Deprecated.
      Encode the url.
      Specified by:
      encodeUrl in interface HttpServletResponse
      Parameters:
      url - the url.
      Returns:
      the encoded url.
    • flushBuffer

      public void flushBuffer() throws java.io.IOException
      Flush the buffer.
      Specified by:
      flushBuffer in interface ServletResponse
      Throws:
      java.io.IOException - when an I/O error occurs.
    • getCharacterEncoding

      public java.lang.String getCharacterEncoding()
      Get the character encoding.
      Specified by:
      getCharacterEncoding in interface ServletResponse
      Returns:
      the character encoding.
    • getBufferSize

      public int getBufferSize()
      Get the buffer size.
      Specified by:
      getBufferSize in interface ServletResponse
      Returns:
      the buffer size.
    • getContentLength

      public long getContentLength()
      Get the content length.
      Returns:
      the content length.
    • getContentType

      public java.lang.String getContentType()
      Get the content type.
      Specified by:
      getContentType in interface ServletResponse
      Returns:
      the content type.
    • getHeader

      public java.lang.String getHeader​(java.lang.String name)
      Get the header.
      Specified by:
      getHeader in interface HttpServletResponse
      Parameters:
      name - the header name.
      Returns:
      the value.
    • getHeaderNames

      public java.util.Collection<java.lang.String> getHeaderNames()
      Get the header names.
      Specified by:
      getHeaderNames in interface HttpServletResponse
      Returns:
      the collection.
    • getHeaders

      public java.util.Collection<java.lang.String> getHeaders​(java.lang.String name)
      Get the headers.
      Specified by:
      getHeaders in interface HttpServletResponse
      Parameters:
      name - the name of the header.
      Returns:
      the collection.
    • getLocale

      public java.util.Locale getLocale()
      Get the locale.
      Specified by:
      getLocale in interface ServletResponse
      Returns:
      the locale.
    • getOutputStream

      public ServletOutputStream getOutputStream() throws java.io.IOException
      Get the output stream.
      Specified by:
      getOutputStream in interface ServletResponse
      Returns:
      the output stream.
      Throws:
      java.io.IOException - when an I/O error occurs.
    • getStatus

      public int getStatus()
      Get the status.
      Specified by:
      getStatus in interface HttpServletResponse
      Returns:
      the status.
    • getStatusMessage

      public java.lang.String getStatusMessage()
      Get the status message.
      Returns:
      the status message.
    • getWebApplication

      public WebApplication getWebApplication()
      Get the web application.
      Returns:
      the web application.
    • getWriter

      public java.io.PrintWriter getWriter() throws java.io.IOException
      Get the writer.
      Specified by:
      getWriter in interface ServletResponse
      Returns:
      the writer.
      Throws:
      java.io.IOException - when an I/O error occurs.
    • isBodyOnly

      public boolean isBodyOnly()
      Is body only.
      Returns:
      true if we are only sending the body, false otherwise.
    • isCommitted

      public boolean isCommitted()
      Is committed.
      Specified by:
      isCommitted in interface ServletResponse
      Returns:
      the committed flag.
    • reset

      public void reset()
      Reset the response.
      Specified by:
      reset in interface ServletResponse
    • resetBuffer

      public void resetBuffer()
      Reset the buffer.
      Specified by:
      resetBuffer in interface ServletResponse
    • sendError

      public void sendError​(int status) throws java.io.IOException
      Send an error.
      Specified by:
      sendError in interface HttpServletResponse
      Parameters:
      status - the error code.
      Throws:
      java.io.IOException - when an I/O error occurs.
    • sendError

      public void sendError​(int status, java.lang.String statusMessage) throws java.io.IOException
      Send the error.
      Specified by:
      sendError in interface HttpServletResponse
      Parameters:
      status - the status code.
      statusMessage - the message.
      Throws:
      java.io.IOException - when an I/O error occurs.
    • sendRedirect

      public void sendRedirect​(java.lang.String location) throws java.io.IOException
      Send the redirect.
      Specified by:
      sendRedirect in interface HttpServletResponse
      Parameters:
      location - the location.
      Throws:
      java.io.IOException - when an I/O error occurs.
    • setBodyOnly

      public void setBodyOnly​(boolean bodyOnly)
      Set the body only flag.
      Parameters:
      bodyOnly - flag.
    • setBufferSize

      public void setBufferSize​(int bufferSize)
      Set the buffer size.
      Specified by:
      setBufferSize in interface ServletResponse
      Parameters:
      bufferSize - the buffer size.
    • setCharacterEncoding

      public void setCharacterEncoding​(java.lang.String characterEncoding)
      Set the character encoding.
      Specified by:
      setCharacterEncoding in interface ServletResponse
      Parameters:
      characterEncoding - the character encoding.
    • setCommitted

      public void setCommitted​(boolean committed)
      Set the committed.
      Parameters:
      committed - the committed flag.
    • setContentLength

      public void setContentLength​(int contentLength)
      Set the content length.
      Specified by:
      setContentLength in interface ServletResponse
      Parameters:
      contentLength - the content length.
    • setContentLengthLong

      public void setContentLengthLong​(long contentLength)
      Set the content length.
      Specified by:
      setContentLengthLong in interface ServletResponse
      Parameters:
      contentLength - the content length.
    • setContentType

      public void setContentType​(java.lang.String type)
      Set the content type.
      Specified by:
      setContentType in interface ServletResponse
      Parameters:
      type - the content type.
    • setDateHeader

      public void setDateHeader​(java.lang.String name, long date)
      Set the date header.
      Specified by:
      setDateHeader in interface HttpServletResponse
      Parameters:
      name - the header name.
      date - the date.
    • setHeader

      public void setHeader​(java.lang.String name, java.lang.String value)
      Set the header.
      Specified by:
      setHeader in interface HttpServletResponse
      Parameters:
      name - the name.
      value - the value.
    • setIntHeader

      public void setIntHeader​(java.lang.String name, int value)
      Set the int header.
      Specified by:
      setIntHeader in interface HttpServletResponse
      Parameters:
      name - the header name.
      value - the header value.
    • setLocale

      public void setLocale​(java.util.Locale locale)
      Set the locale.
      Specified by:
      setLocale in interface ServletResponse
      Parameters:
      locale - the locale.
    • setOutputStream

      public void setOutputStream​(ServletOutputStream outputStream)
      Set the output stream.
      Parameters:
      outputStream - the output stream.
    • setStatus

      public void setStatus​(int status)
      Set the status.
      Specified by:
      setStatus in interface HttpServletResponse
      Parameters:
      status - the status code.
    • setStatus

      @Deprecated public void setStatus​(int status, java.lang.String statusMessage)
      Deprecated.
      Set the status.
      Specified by:
      setStatus in interface HttpServletResponse
      Parameters:
      status - the status.
      statusMessage - the message
    • setWebApplication

      public void setWebApplication​(WebApplication webApplication)
      Set the web application.
      Parameters:
      webApplication - the web application.
    • verifyNotCommitted

      protected void verifyNotCommitted​(java.lang.String methodName)
      Verify we are not committed.
      Parameters:
      methodName - the method we are checking for.
    • getCookies

      public java.util.Collection<Cookie> getCookies()
      Get the cookies.
      Specified by:
      getCookies in interface WebApplicationResponse
      Returns:
      the cookies.
    • getUnderlyingOutputStream

      public java.io.OutputStream getUnderlyingOutputStream()
      Get the underlying output stream.
      Specified by:
      getUnderlyingOutputStream in interface WebApplicationResponse
      Returns:
      the underlying output stream.
    • setUnderlyingOutputStream

      public void setUnderlyingOutputStream​(java.io.OutputStream outputStream)
      Set the underlying output stream.
      Specified by:
      setUnderlyingOutputStream in interface WebApplicationResponse
      Parameters:
      outputStream - the underlying output stream.
    • closeAsyncResponse

      public void closeAsyncResponse()
      Specified by:
      closeAsyncResponse in interface WebApplicationResponse
    • close

      public void close() throws java.io.IOException
      Close the output stream.
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Overrides:
      close in class java.io.OutputStream
      Throws:
      java.io.IOException - when an I/O error occurs.
    • flush

      public void flush() throws java.io.IOException
      Flush the output stream.
      Specified by:
      flush in interface java.io.Flushable
      Overrides:
      flush in class java.io.OutputStream
      Throws:
      java.io.IOException - when an I/O error occurs.
    • isReady

      public boolean isReady()
      Is the output stream ready?
      Specified by:
      isReady in class ServletOutputStream
      Returns:
      true if it is, false otherwise.
    • setWriteListener

      public void setWriteListener​(WriteListener listener)
      Set the write listener.
      Specified by:
      setWriteListener in class ServletOutputStream
      Parameters:
      listener - the write listener.
    • write

      public void write​(int integer) throws java.io.IOException
      Write the integer.
      Specified by:
      write in class java.io.OutputStream
      Parameters:
      integer - the integer.
      Throws:
      java.io.IOException - when an I/O error occurs.