Class ResourceUtil
java.lang.Object
com.reallifedeveloper.common.resource.ResourceUtil
Utility class with helper methods for JAX-RS resources.
- Author:
- RealLifeDeveloper
-
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.ws.rs.WebApplicationException
badRequest
(@Nullable String message) Gives aWebApplicationException
with HTTP status 400 and the given message as plain text in the body.static jakarta.ws.rs.core.CacheControl
cacheControl
(int maxAgeInSeconds) Gives aCacheControl
object with themax-age
directive set to the given value.static jakarta.ws.rs.core.CacheControl
noCache()
Gives aCacheControl
object with directives set to prevent caching.static jakarta.ws.rs.WebApplicationException
Gives aWebApplicationException
with HTTP status 404 and the given message as plain text in the body.static jakarta.ws.rs.WebApplicationException
serverError
(@Nullable String message) Gives aWebApplicationException
with HTTP status 500 and the given message as plain text in the body.static jakarta.ws.rs.WebApplicationException
webApplicationException
(@Nullable String message, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationException
with the given HTTP status and the given message as plain text in the response body.static jakarta.ws.rs.WebApplicationException
webApplicationException
(@Nullable Throwable cause, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationException
with the given HTTP status and the givenThrowable
as plain text in the response body.
-
Method Details
-
webApplicationException
public static jakarta.ws.rs.WebApplicationException webApplicationException(@Nullable String message, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationException
with the given HTTP status and the given message as plain text in the response body. Ifmessage
isnull
, the entity in the response body will also benull
.- Parameters:
message
- the message to send back to the client, ornull
status
- the HTTP status to send back to the client- Returns:
- a
WebApplicationException
- Throws:
IllegalArgumentException
- ifstatus
isnull
-
webApplicationException
public static jakarta.ws.rs.WebApplicationException webApplicationException(@Nullable Throwable cause, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationException
with the given HTTP status and the givenThrowable
as plain text in the response body. Ifcause
isnull
, the entity in the response body will also benull
.- Parameters:
cause
- the cause of the error, ornull
status
- the HTTP status to send back to the client- Returns:
- a
WebApplicationException
- Throws:
IllegalArgumentException
- ifstatus
isnull
-
badRequest
Gives aWebApplicationException
with HTTP status 400 and the given message as plain text in the body.- Parameters:
message
- the message to send back to the client- Returns:
- a
WebApplicationException
-
notFound
Gives aWebApplicationException
with HTTP status 404 and the given message as plain text in the body.- Parameters:
message
- the message to send back to the client- Returns:
- a
WebApplicationException
-
serverError
Gives aWebApplicationException
with HTTP status 500 and the given message as plain text in the body.- Parameters:
message
- the message to send back to the client- Returns:
- a
WebApplicationException
-
cacheControl
public static jakarta.ws.rs.core.CacheControl cacheControl(int maxAgeInSeconds) Gives aCacheControl
object with themax-age
directive set to the given value.You would normally use this method like this:
Response response = Response.ok(representation).cacheControl(cacheControl(10)).build();
- Parameters:
maxAgeInSeconds
- the value of themax-age
directive- Returns:
- a
CacheControl
object with themax-age
directive set
-
noCache
public static jakarta.ws.rs.core.CacheControl noCache()Gives aCacheControl
object with directives set to prevent caching. The directives a set as follows:no-cache=true
no-store=true
must-revalidate=true
- Returns:
- a
CacheControl
object with directives set to prevent caching
-