Class BaseResource
java.lang.Object
com.reallifedeveloper.common.resource.BaseResource
- Direct Known Subclasses:
DocumentationResource,NotificationResource
A base class for JAX-RS resources.
- Author:
- RealLifeDeveloper
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe optional HTTP header that holds the API key of the calling system.static final StringThe optional query parameter that holds the API key of the calling system.protected static final intA handy value to provide to theResourceUtil.cacheControl(int)method to cache a result for one hour.static final StringThe standard format for dates, without time. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a newBaseResource, intended to be used by sub-classes. -
Method Summary
Modifier and TypeMethodDescriptioncommaSeparatedStringToList(@Nullable String s) Given a comma-separated list, this methods returns a list containing the constituent strings, with leading and trailing whitespace removed.protected jakarta.ws.rs.WebApplicationExceptionhandleError(String methodName, Exception originalException) Use this method to translate an exception to the appropriateWebApplicationException.protected org.slf4j.Loggerlogger()Gives theorg.slf4j.Loggerto use for logging.protected LocalDateParses a string as ajava.time.LocalDate, using the date format "yyyy-MM-dd".protected URLParses a string as ajava.net.URL.
-
Field Details
-
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 headerAPI_KEY_HTTP_HEADERmust be included in the request.- See Also:
-
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 parameterAPI_KEY_QUERY_PARAMETERmust be included in the request.- See Also:
-
DATE_FORMAT
The standard format for dates, without time.- See Also:
-
CACHE_1_HOUR
protected static final int CACHE_1_HOURA handy value to provide to theResourceUtil.cacheControl(int)method to cache a result for one hour.- See Also:
-
-
Constructor Details
-
BaseResource
protected BaseResource()Creates a newBaseResource, intended to be used by sub-classes.
-
-
Method Details
-
logger
protected org.slf4j.Logger logger()Gives theorg.slf4j.Loggerto 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 appropriateWebApplicationException. The problem is also logged.- Parameters:
methodName- the name of the method where the problem occurredoriginalException- the exception that should be translated- Returns:
- an appropriate
WebApplicationException, depending onoriginalException - Throws:
IllegalArgumentException- if any argument isnull
-
parseDate
Parses a string as ajava.time.LocalDate, using the date format "yyyy-MM-dd".- Parameters:
date- the string to parse- Returns:
- the
java.time.LocalDaterepresentation ofdate - Throws:
IllegalArgumentException- ifdateisnullor could not be parsed as a date
-
parseUrl
Parses a string as ajava.net.URL.- Parameters:
url- the string to parse- Returns:
- the
java.net.URLrepresentation ofurl - Throws:
IllegalArgumentException- ifurlcould not be parsed as a URL
-
commaSeparatedStringToList
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"].
A
nullstring gives an empty list, the method does not throw an exception.- Parameters:
s- a comma-separated list, ornull- Returns:
- a list with the constituent strings, with whitespace removed
-