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 String
The optional HTTP header that holds the API key of the calling system.static final String
The optional query parameter that holds the API key of the calling system.protected static final int
A handy value to provide to theResourceUtil.cacheControl(int)
method to cache a result for one hour.static final String
The standard format for dates, without time. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a newBaseResource
, intended to be used by sub-classes. -
Method Summary
Modifier and TypeMethodDescriptionGiven a comma-separated list, this methods returns a list containing the constituent strings, with leading and trailing whitespace removed.protected jakarta.ws.rs.WebApplicationException
handleError
(String methodName, Exception originalException) Use this method to translate an exception to the appropriateWebApplicationException
.protected org.slf4j.Logger
logger()
Gives theorg.slf4j.Logger
to use for logging.protected LocalDate
Parses a string as ajava.time.LocalDate
, using the date format "yyyy-MM-dd".protected URL
Parses 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_HEADER
must 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_PARAMETER
must 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.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 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.LocalDate
representation ofdate
- Throws:
IllegalArgumentException
- ifdate
isnull
or 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.URL
representation ofurl
- Throws:
IllegalArgumentException
- ifurl
could 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"].- Parameters:
s
- a comma-separated list- Returns:
- a list with the constituent strings, with whitespace removed
-