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.WebApplicationExceptionbadRequest(@Nullable String message) Gives aWebApplicationExceptionwith HTTP status 400 and the given message as plain text in the body.static jakarta.ws.rs.core.CacheControlcacheControl(int maxAgeInSeconds) Gives aCacheControlobject with themax-agedirective set to the given value.static jakarta.ws.rs.core.CacheControlnoCache()Gives aCacheControlobject with directives set to prevent caching.static jakarta.ws.rs.WebApplicationExceptionGives aWebApplicationExceptionwith HTTP status 404 and the given message as plain text in the body.static jakarta.ws.rs.WebApplicationExceptionserverError(@Nullable String message) Gives aWebApplicationExceptionwith HTTP status 500 and the given message as plain text in the body.static jakarta.ws.rs.WebApplicationExceptionwebApplicationException(@Nullable String message, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationExceptionwith the given HTTP status and the given message as plain text in the response body.static jakarta.ws.rs.WebApplicationExceptionwebApplicationException(@Nullable Throwable cause, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationExceptionwith the given HTTP status and the givenThrowableas 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 aWebApplicationExceptionwith the given HTTP status and the given message as plain text in the response body. Ifmessageisnull, the entity in the response body will also benull.- Parameters:
message- the message to send back to the client, ornullstatus- the HTTP status to send back to the client- Returns:
- a
WebApplicationException - Throws:
IllegalArgumentException- ifstatusisnull
-
webApplicationException
public static jakarta.ws.rs.WebApplicationException webApplicationException(@Nullable Throwable cause, jakarta.ws.rs.core.Response.Status status) Gives aWebApplicationExceptionwith the given HTTP status and the givenThrowableas plain text in the response body. Ifcauseisnull, the entity in the response body will also benull.- Parameters:
cause- the cause of the error, ornullstatus- the HTTP status to send back to the client- Returns:
- a
WebApplicationException - Throws:
IllegalArgumentException- ifstatusisnull
-
badRequest
Gives aWebApplicationExceptionwith 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 aWebApplicationExceptionwith 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 aWebApplicationExceptionwith 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 aCacheControlobject with themax-agedirective 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-agedirective- Returns:
- a
CacheControlobject with themax-agedirective set
-
noCache
public static jakarta.ws.rs.core.CacheControl noCache()Gives aCacheControlobject with directives set to prevent caching. The directives a set as follows:no-cache=trueno-store=truemust-revalidate=true
- Returns:
- a
CacheControlobject with directives set to prevent caching
-