Class ResourceUtil

java.lang.Object
com.reallifedeveloper.common.resource.ResourceUtil

public final class ResourceUtil extends Object
Utility class with helper methods for JAX-RS resources.
Author:
RealLifeDeveloper
  • Method Summary

    Modifier and Type
    Method
    Description
    static jakarta.ws.rs.WebApplicationException
    badRequest(@Nullable String message)
    Gives a WebApplicationException with HTTP status 400 and the given message as plain text in the body.
    static jakarta.ws.rs.core.CacheControl
    cacheControl(int maxAgeInSeconds)
    Gives a CacheControl object with the max-age directive set to the given value.
    static jakarta.ws.rs.core.CacheControl
    Gives a CacheControl object with directives set to prevent caching.
    static jakarta.ws.rs.WebApplicationException
    notFound(@Nullable String message)
    Gives a WebApplicationException with HTTP status 404 and the given message as plain text in the body.
    static jakarta.ws.rs.WebApplicationException
    serverError(@Nullable String message)
    Gives a WebApplicationException 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 a WebApplicationException 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 a WebApplicationException with the given HTTP status and the given Throwable as plain text in the response body.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • webApplicationException

      public static jakarta.ws.rs.WebApplicationException webApplicationException(@Nullable String message, jakarta.ws.rs.core.Response.Status status)
      Gives a WebApplicationException with the given HTTP status and the given message as plain text in the response body. If message is null, the entity in the response body will also be null.
      Parameters:
      message - the message to send back to the client, or null
      status - the HTTP status to send back to the client
      Returns:
      a WebApplicationException
      Throws:
      IllegalArgumentException - if status is null
    • webApplicationException

      public static jakarta.ws.rs.WebApplicationException webApplicationException(@Nullable Throwable cause, jakarta.ws.rs.core.Response.Status status)
      Gives a WebApplicationException with the given HTTP status and the given Throwable as plain text in the response body. If cause is null, the entity in the response body will also be null.
      Parameters:
      cause - the cause of the error, or null
      status - the HTTP status to send back to the client
      Returns:
      a WebApplicationException
      Throws:
      IllegalArgumentException - if status is null
    • badRequest

      public static jakarta.ws.rs.WebApplicationException badRequest(@Nullable String message)
      Gives a WebApplicationException 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

      public static jakarta.ws.rs.WebApplicationException notFound(@Nullable String message)
      Gives a WebApplicationException 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

      public static jakarta.ws.rs.WebApplicationException serverError(@Nullable String message)
      Gives a WebApplicationException 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 a CacheControl object with the max-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 the max-age directive
      Returns:
      a CacheControl object with the max-age directive set
    • noCache

      public static jakarta.ws.rs.core.CacheControl noCache()
      Gives a CacheControl 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