Class BaseResource

java.lang.Object
com.reallifedeveloper.common.resource.BaseResource
Direct Known Subclasses:
DocumentationResource, NotificationResource

public class BaseResource extends Object
A base class for JAX-RS resources.
Author:
RealLifeDeveloper
  • Field Details

    • API_KEY_QUERY_PARAMETER

      public static final String API_KEY_QUERY_PARAMETER
      The optional query parameter that holds the API key of the calling system. If authentication is required, either this query parameter or the HTTP header API_KEY_HTTP_HEADER must be included in the request.
      See Also:
    • API_KEY_HTTP_HEADER

      public static final String API_KEY_HTTP_HEADER
      The optional HTTP header that holds the API key of the calling system. If authentication is required, either this HTTP header or the query parameter API_KEY_QUERY_PARAMETER must be included in the request.
      See Also:
    • DATE_FORMAT

      public static final String DATE_FORMAT
      The standard format for dates, without time.
      See Also:
    • CACHE_1_HOUR

      protected static final int CACHE_1_HOUR
      A handy value to provide to the ResourceUtil.cacheControl(int) method to cache a result for one hour.
      See Also:
  • Constructor Details

    • BaseResource

      protected BaseResource()
      Creates a new BaseResource, intended to be used by sub-classes.
  • Method Details

    • logger

      protected org.slf4j.Logger logger()
      Gives the org.slf4j.Logger to use for logging.
      Returns:
      the org.slf4j.Logger
    • handleError

      protected jakarta.ws.rs.WebApplicationException handleError(String methodName, Exception originalException)
      Use this method to translate an exception to the appropriate WebApplicationException. The problem is also logged.
      Parameters:
      methodName - the name of the method where the problem occurred
      originalException - the exception that should be translated
      Returns:
      an appropriate WebApplicationException, depending on originalException
      Throws:
      IllegalArgumentException - if any argument is null
    • parseDate

      protected LocalDate parseDate(String date)
      Parses a string as a java.time.LocalDate, using the date format "yyyy-MM-dd".
      Parameters:
      date - the string to parse
      Returns:
      the java.time.LocalDate representation of date
      Throws:
      IllegalArgumentException - if date is null or could not be parsed as a date
    • parseUrl

      protected URL parseUrl(String url)
      Parses a string as a java.net.URL.
      Parameters:
      url - the string to parse
      Returns:
      the java.net.URL representation of url
      Throws:
      IllegalArgumentException - if url could not be parsed as a URL
    • commaSeparatedStringToList

      protected List<String> commaSeparatedStringToList(String s)
      Given a comma-separated list, this methods returns a list containing the constituent strings, with leading and trailing whitespace removed. Example: Given the string " foo ,bar , baz " the result is the list ["foo","bar","baz"].
      Parameters:
      s - a comma-separated list
      Returns:
      a list with the constituent strings, with whitespace removed