Class ResponseBuilder
- java.lang.Object
-
- com.djrapitops.plan.delivery.web.resolver.ResponseBuilder
-
public class ResponseBuilder extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResponseBuilder.InvalidResponseException
Thrown whenResponseBuilder
is missing some parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Response
build()
Finish building.ResponseBuilder
redirectTo(java.lang.String url)
Utility method for building redirects.ResponseBuilder
setContent(byte[] bytes)
ResponseBuilder
setContent(WebResource resource)
ResponseBuilder
setContent(java.lang.String utf8String)
ResponseBuilder
setContent(java.lang.String content, java.nio.charset.Charset charset)
ResponseBuilder
setHeader(java.lang.String header, java.lang.Object value)
Set HTTP Response header.ResponseBuilder
setJSONContent(java.lang.Object objectToSerialize)
Set content as serialized JSON object.ResponseBuilder
setJSONContent(java.lang.String json)
ResponseBuilder
setMimeType(java.lang.String mimeType)
Set MIME Type of the Response.ResponseBuilder
setStatus(int code)
Set HTTP Status code.
-
-
-
Method Detail
-
setMimeType
public ResponseBuilder setMimeType(java.lang.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(java.lang.String header, java.lang.Object value)
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
public ResponseBuilder redirectTo(java.lang.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(java.lang.String utf8String)
-
setContent
public ResponseBuilder setContent(java.lang.String content, java.nio.charset.Charset charset)
-
setJSONContent
public ResponseBuilder setJSONContent(java.lang.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(java.lang.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.
-
-