Class ResponseBuilder

java.lang.Object
com.djrapitops.plan.delivery.web.resolver.ResponseBuilder

public class ResponseBuilder extends Object
  • Method Details

    • setMimeType

      public ResponseBuilder setMimeType(String mimeType)
      Set MIME Type of the Response.
      Parameters:
      mimeType - MIME type of the Response https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
      Returns:
      this builder.
      See Also:
      for common MIME types.
    • setStatus

      public ResponseBuilder setStatus(int code)
      Set HTTP Status code.

      Default status code is 200 (OK) if not set.

      Parameters:
      code - 1xx, 2xx, 3xx, 4xx, 5xx, https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
      Returns:
      this builder.
    • setHeader

      public ResponseBuilder setHeader(String header, Object value)
      Set HTTP Response header.
      Parameters:
      header - Key of the header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
      value - Value for the header.
      Returns:
      this builder.
    • redirectTo

      public ResponseBuilder redirectTo(String url)
      Utility method for building redirects.
      Parameters:
      url - URL to redirect the client to with 302 Found.
      Returns:
      https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location
    • setContent

      public ResponseBuilder setContent(WebResource resource)
    • setContent

      public ResponseBuilder setContent(byte[] bytes)
    • setContent

      public ResponseBuilder setContent(String utf8String)
    • setContent

      public ResponseBuilder setContent(String content, Charset charset)
    • setJSONContent

      public ResponseBuilder setJSONContent(Object objectToSerialize)
      Set content as serialized JSON object.
      Parameters:
      objectToSerialize - Object to serialize into JSON with Gson. If the object is a String it is assumed to be valid JSON.
      Returns:
      this builder.
    • setJSONContent

      public ResponseBuilder setJSONContent(String json)
    • build

      public Response build()
      Finish building.
      Returns:
      Response.
      Throws:
      ResponseBuilder.InvalidResponseException - if content was not defined (not even empty byte array).
      ResponseBuilder.InvalidResponseException - if content has bytes, but MIME-type is not defined.
      ResponseBuilder.InvalidResponseException - if status code is outside range 100-599.
      See Also:
      to set MIME-type.