Class Response

java.lang.Object
org.eclipse.jetty.ee8.nested.Response
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class Response extends Object implements javax.servlet.http.HttpServletResponse

Response provides the implementation for HttpServletResponse.

  • Field Details

  • Constructor Details

  • Method Details

    • getBaseResponse

      public static Response getBaseResponse(javax.servlet.ServletResponse servletResponse)
    • getHttpChannel

      public HttpChannel getHttpChannel()
    • onResponse

      protected void onResponse(HttpFields.Mutable headers)
    • recycle

      protected void recycle()
    • getHttpOutput

      public HttpOutput getHttpOutput()
    • reopen

      public void reopen()
    • errorClose

      public void errorClose()
    • isIncluding

      public boolean isIncluding()
    • include

      public void include()
    • included

      public void included()
    • addCookie

      public void addCookie(HttpCookie cookie)
    • addCookie

      public void addCookie(javax.servlet.http.Cookie cookie)
      Specified by:
      addCookie in interface javax.servlet.http.HttpServletResponse
    • replaceCookie

      public void replaceCookie(HttpCookie cookie)
      Replace (or add) a cookie. Using name, path and domain, look for a matching set-cookie header and replace it.
      Parameters:
      cookie - The cookie to add/replace
    • containsHeader

      public boolean containsHeader(String name)
      Specified by:
      containsHeader in interface javax.servlet.http.HttpServletResponse
    • encodeURL

      public String encodeURL(String url)
      Specified by:
      encodeURL in interface javax.servlet.http.HttpServletResponse
    • encodeRedirectURL

      public String encodeRedirectURL(String url)
      Specified by:
      encodeRedirectURL in interface javax.servlet.http.HttpServletResponse
    • encodeUrl

      @Deprecated(since="Servlet API 2.1") public String encodeUrl(String url)
      Deprecated.
      Specified by:
      encodeUrl in interface javax.servlet.http.HttpServletResponse
    • encodeRedirectUrl

      @Deprecated(since="Servlet API 2.1") public String encodeRedirectUrl(String url)
      Deprecated.
      Specified by:
      encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse
    • sendError

      public void sendError(int sc) throws IOException
      Specified by:
      sendError in interface javax.servlet.http.HttpServletResponse
      Throws:
      IOException
    • sendError

      public void sendError(int code, String message) throws IOException
      Send an error response.

      In addition to the servlet standard handling, this method supports some additional codes:

      102
      Send a partial PROCESSING response and allow additional responses
      103
      Send a partial EARLY_HINT response as per RFC8297
      -1
      Abort the HttpChannel and close the connection/stream
      Specified by:
      sendError in interface javax.servlet.http.HttpServletResponse
      Parameters:
      code - The error code
      message - The message
      Throws:
      IOException - If an IO problem occurred sending the error response.
    • sendProcessing

      public void sendProcessing() throws IOException
      Sends a 102 Processing interim response. This method is called by sendError(int) if it is passed status code 102.
      Throws:
      IOException - if unable to send the 102 response
      See Also:
      • HttpServletResponse.sendError(int)
    • sendEarlyHint

      public void sendEarlyHint() throws IOException
      Sends a 103 Early Hints interim response, as per RFC8297. This method is called by sendError(int) if it is passed status code 103.
      Throws:
      IOException - if unable to send the 103 response
      See Also:
      • HttpServletResponse.sendError(int)
    • sendRedirect

      public void sendRedirect(int code, String location) throws IOException
      Sends a response with one of the 300 series redirection codes.
      Parameters:
      code - the redirect status code
      location - the location to send in Location headers
      Throws:
      IOException - if unable to send the redirect
    • sendRedirect

      public void sendRedirect(String location, boolean consumeAll) throws IOException
      Sends a response with a HTTP version appropriate 30x redirection.
      Parameters:
      location - the location to send in Location headers
      consumeAll - if True, consume any HTTP/1 request input before doing the redirection. If the input cannot be consumed without blocking, then add a `Connection: close` header to the response.
      Throws:
      IOException - if unable to send the redirect
    • sendRedirect

      public void sendRedirect(int code, String location, boolean consumeAll) throws IOException
      Sends a response with a given redirection code.
      Parameters:
      code - the redirect status code
      location - the location to send in Location headers
      consumeAll - if True, consume any HTTP/1 request input before doing the redirection. If the input cannot be consumed without blocking, then add a `Connection: close` header to the response.
      Throws:
      IOException - if unable to send the redirect
    • sendRedirect

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

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

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

      public void setHeader(HttpHeader name, String value)
    • setHeader

      public void setHeader(String name, String value)
      Specified by:
      setHeader in interface javax.servlet.http.HttpServletResponse
    • getHeaderNames

      public Collection<String> getHeaderNames()
      Specified by:
      getHeaderNames in interface javax.servlet.http.HttpServletResponse
    • getHeader

      public String getHeader(String name)
      Specified by:
      getHeader in interface javax.servlet.http.HttpServletResponse
    • getHeaders

      public Collection<String> getHeaders(String name)
      Specified by:
      getHeaders in interface javax.servlet.http.HttpServletResponse
    • addHeader

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

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

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

      public void setStatus(int sc)
      Specified by:
      setStatus in interface javax.servlet.http.HttpServletResponse
    • setStatus

      @Deprecated(since="Servlet API 2.1") public void setStatus(int sc, String message)
      Deprecated.
      Specified by:
      setStatus in interface javax.servlet.http.HttpServletResponse
    • setStatusWithReason

      public void setStatusWithReason(int sc, String message)
    • getCharacterEncoding

      public String getCharacterEncoding()
      Specified by:
      getCharacterEncoding in interface javax.servlet.ServletResponse
    • getContentType

      public String getContentType()
      Specified by:
      getContentType in interface javax.servlet.ServletResponse
    • getOutputStream

      public javax.servlet.ServletOutputStream getOutputStream() throws IOException
      Specified by:
      getOutputStream in interface javax.servlet.ServletResponse
      Throws:
      IOException
    • isWriting

      public boolean isWriting()
    • isStreaming

      public boolean isStreaming()
    • isWritingOrStreaming

      public boolean isWritingOrStreaming()
    • getWriter

      public PrintWriter getWriter() throws IOException
      Specified by:
      getWriter in interface javax.servlet.ServletResponse
      Throws:
      IOException
    • setContentLength

      public void setContentLength(int len)
      Specified by:
      setContentLength in interface javax.servlet.ServletResponse
    • getContentLength

      public long getContentLength()
    • isAllContentWritten

      public boolean isAllContentWritten(long written)
    • isContentComplete

      public boolean isContentComplete(long written)
    • closeOutput

      public void closeOutput() throws IOException
      Throws:
      IOException
    • completeOutput

      @Deprecated public void completeOutput() throws IOException
      Deprecated.
      close the output
      Throws:
      IOException
    • completeOutput

      public void completeOutput(Callback callback)
    • getLongContentLength

      public long getLongContentLength()
    • setLongContentLength

      public void setLongContentLength(long len)
    • setContentLengthLong

      public void setContentLengthLong(long length)
      Specified by:
      setContentLengthLong in interface javax.servlet.ServletResponse
    • setCharacterEncoding

      public void setCharacterEncoding(String encoding)
      Specified by:
      setCharacterEncoding in interface javax.servlet.ServletResponse
    • setContentType

      public void setContentType(String contentType)
      Specified by:
      setContentType in interface javax.servlet.ServletResponse
    • setBufferSize

      public void setBufferSize(int size)
      Specified by:
      setBufferSize in interface javax.servlet.ServletResponse
    • getBufferSize

      public int getBufferSize()
      Specified by:
      getBufferSize in interface javax.servlet.ServletResponse
    • flushBuffer

      public void flushBuffer() throws IOException
      Specified by:
      flushBuffer in interface javax.servlet.ServletResponse
      Throws:
      IOException
    • reset

      public void reset()
      Specified by:
      reset in interface javax.servlet.ServletResponse
    • resetContent

      public void resetContent()
    • resetForForward

      public void resetForForward()
    • resetBuffer

      public void resetBuffer()
      Specified by:
      resetBuffer in interface javax.servlet.ServletResponse
    • getTrailers

      public Supplier<HttpFields> getTrailers()
    • setTrailers

      public void setTrailers(Supplier<HttpFields> trailers)
    • getTrailerFields

      public Supplier<Map<String,String>> getTrailerFields()
      Specified by:
      getTrailerFields in interface javax.servlet.http.HttpServletResponse
    • setTrailerFields

      public void setTrailerFields(Supplier<Map<String,String>> trailers)
      Specified by:
      setTrailerFields in interface javax.servlet.http.HttpServletResponse
    • newResponseMetaData

      protected MetaData.Response newResponseMetaData()
    • isCommitted

      public boolean isCommitted()
      Specified by:
      isCommitted in interface javax.servlet.ServletResponse
    • setLocale

      public void setLocale(Locale locale)
      Specified by:
      setLocale in interface javax.servlet.ServletResponse
    • getLocale

      public Locale getLocale()
      Specified by:
      getLocale in interface javax.servlet.ServletResponse
    • getStatus

      public int getStatus()
      Specified by:
      getStatus in interface javax.servlet.http.HttpServletResponse
    • getReason

      public String getReason()
    • getHttpFields

      public HttpFields.Mutable getHttpFields()
    • getContentCount

      public long getContentCount()
    • toString

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

      public void putHeaders(HttpContent content, long contentLength, boolean etag)
    • putHeaders

      public static void putHeaders(javax.servlet.http.HttpServletResponse response, HttpContent content, long contentLength, boolean etag)
    • unwrap

      public static javax.servlet.http.HttpServletResponse unwrap(javax.servlet.ServletResponse servletResponse)