Class ResponseBuilder
java.lang.Object
com.djrapitops.plan.delivery.web.resolver.ResponseBuilder
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Thrown whenResponseBuilder
is missing some parameters. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Finish building.redirectTo(String url)
Utility method for building redirects.setContent(byte[] bytes)
setContent(WebResource resource)
setContent(String utf8String)
setContent(String content, Charset charset)
Set HTTP Response header.setJSONContent(Object objectToSerialize)
Set content as serialized JSON object.setJSONContent(String json)
setMimeType(String mimeType)
Set MIME Type of the Response.setStatus(int code)
Set HTTP Status code.
-
Method Details
-
setMimeType
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
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
Set HTTP Response header.- Parameters:
header
- Key of the header. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headersvalue
- Value for the header.- Returns:
- this builder.
-
redirectTo
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
-
setContent
-
setContent
-
setContent
-
setJSONContent
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
-
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.
-