Class Response

All Implemented Interfaces:
Operation, OperationBuilder

public abstract class Response extends HttpOperation
Responsible for manipulating properties such as headers, cookies, ResponseContentInterceptor and ResponseStreamWrapper instances to the current HttpServletResponse
Author:
Lincoln Baxter, III
  • Constructor Details

    • Response

      public Response()
  • Method Details

    • withOutputInterceptedBy

      public static OperationBuilder withOutputInterceptedBy(ResponseContentInterceptor... buffers) throws IllegalStateException
      Create an Operation that adds the given ResponseContentInterceptor instances to the current ServletResponse. This will activate response buffering on the current ServletRequest - meaning that generated output will not be sent to the client until the entire request has completed and all registered ResponseContentInterceptor instances have been executed on the outbound response content.

      WARNING: This will cause the ENTIRE response to be buffered in memory, which may cause performance issues on larger responses. Make sure you you really need to buffer the entire response! Favor using a ResponseStreamWrapper if desired behavior may be performed as a stream operation; this will result in far less memory overhead.

      Throws:
      IllegalStateException - When output has already been written to the client.
    • withOutputStreamWrappedBy

      public static OperationBuilder withOutputStreamWrappedBy(ResponseStreamWrapper... wrappers) throws IllegalStateException
      Create an Operation that adds the given ResponseStreamWrapper instances to the current ServletResponse. This will activate response stream wrapping on the current ServletRequest - meaning response content will be piped through all registered ResponseStreamWrapper instances as it is written to the client ServletOutputStream.
      Throws:
      IllegalStateException - When output has already been written to the client.
    • addHeader

      public static OperationBuilder addHeader(String name, String value)
      Create an Operation that adds a header to the HttpServletResponse
    • addDateHeader

      public static OperationBuilder addDateHeader(String name, long value)
      Create an Operation that adds a date header to the HttpServletResponse
    • setContentType

      public static OperationBuilder setContentType(String contentType)
      Create an Operation that sets the content type for the HttpServletResponse
    • addIntHeader

      public static OperationBuilder addIntHeader(String name, int value)
      Create an Operation that adds an int header to the HttpServletResponse
    • addCookie

      public static OperationBuilder addCookie(jakarta.servlet.http.Cookie cookie)
      Create an Operation that adds a Cookie to the HttpServletResponse
    • gzipCompression

      public static OperationBuilder gzipCompression()
      Compress the ServletOutputStream contents written to the client.

      WARNING: This causes response content to be buffered in memory in order to properly count the response 'Content-Length'.

    • gzipStreamCompression

      public static OperationBuilder gzipStreamCompression()
      Compress the ServletOutputStream contents written to the client.

      WARNING: This means that the HTTP response will not contain a 'Content-Length' header.

    • write

      public static OperationBuilder write(byte... bytes)
      Create an Operation that writes the given bytes to the current HttpServletResponse upon execution.
    • write

      public static OperationBuilder write(Object value)
      Create an Operation that writes the String value of the given Object to the current HttpServletResponse upon execution. The value to be written is obtained using Object.toString().
    • write

      public static OperationBuilder write(InputStream stream)
      Create an Operation that writes the contents of the given InputStream current HttpServletResponse upon execution.
    • setStatus

      public static OperationBuilder setStatus(int status)
      Create an Operation that sets the given status code via HttpServletResponse.setStatus(int). This does not call ServletResponse.flushBuffer()
    • complete

      public static OperationBuilder complete()
      Create an Operation that halts further Rewrite processing and completes the current HttpServletResponse.
    • isCommitted

      public static ConditionBuilder isCommitted()
      Create a Condition that evaluates the status of ServletResponse.isCommitted().