Class WebServiceControllerSupport
java.lang.Object
net.solarnetwork.central.web.support.WebServiceControllerSupport
@RestControllerAdvice(annotations=GlobalExceptionRestController.class)
@Order(100)
public final class WebServiceControllerSupport
extends Object
A base class to support web service style controllers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAn alternate format pattern for a date and time property using a space delimiter between the date and time.static final StringAn alternate format pattern for a date and time property with an explicit Z time zone using a space delimiter between the date and time.static final StringAn alternate format pattern for a millisecond-precise date and time property using a space delimiter between the date and time.static final StringAn alternate format pattern for a millisecond-precise date and time property with an explicit Z time zone using a space delimiter between the date and time.static final StringA value to use for anonymous users in log messages.static final StringThe default format pattern for a date property.static final StringThe default format pattern for a date and time property.static final StringThe default format pattern for adate and time property with an explicit Z time zone.static final StringThe default format pattern for a millisecond-precise date and time property.static final StringThe default format pattern for a millisecond-precise date and time property with an explicit Z time zone. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVaryResponseHeader(jakarta.servlet.http.HttpServletResponse response) Add a Vary HTTP response header.org.springframework.context.MessageSourceGet the message source.net.solarnetwork.web.jakarta.domain.Response<?> handleBeanInstantiationException(org.springframework.beans.BeanInstantiationException e, org.springframework.web.context.request.WebRequest request) Handle anBeanInstantiationException.net.solarnetwork.domain.Result<?> handleBindException(org.springframework.validation.BindException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anBindException.net.solarnetwork.domain.Result<Void> handleConstraintViolationException(jakarta.validation.ConstraintViolationException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anConstraintViolationException.net.solarnetwork.web.jakarta.domain.Response<?> handleDataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException e, org.springframework.web.context.request.WebRequest request, Locale locale, jakarta.servlet.http.HttpServletRequest servletRequest) Handle aDataIntegrityViolationException.net.solarnetwork.web.jakarta.domain.Response<?> handleDataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle aDataRetrievalFailureException.net.solarnetwork.web.jakarta.domain.Response<?> handleDateTimeException(DateTimeException e, org.springframework.web.context.request.WebRequest request) Handle a general .net.solarnetwork.web.jakarta.domain.Response<?> handleDateTimeParseException(DateTimeParseException e, org.springframework.web.context.request.WebRequest request) Handle aDateTimeParseException, from malformed date input.net.solarnetwork.web.jakarta.domain.Response<?> handleHttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException e, org.springframework.web.context.request.WebRequest request) Handle aHttpMessageNotReadableException, from malformed JSON input.net.solarnetwork.web.jakarta.domain.Response<?> handleInvalidDataAccessResourceUsageException(org.springframework.dao.InvalidDataAccessResourceUsageException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle aInvalidDataAccessResourceUsageException.net.solarnetwork.domain.Result<?> handleInvalidPropertyException(org.springframework.beans.InvalidPropertyException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anInvalidPropertyException.net.solarnetwork.web.jakarta.domain.Response<?> handleJsonParseException(com.fasterxml.jackson.core.JsonProcessingException e, org.springframework.web.context.request.WebRequest request) Handle aJsonProcessingException, presuming from malformed JSON input.net.solarnetwork.web.jakarta.domain.Response<?> handleMultipartException(org.springframework.web.multipart.MultipartException e, org.springframework.web.context.request.WebRequest request) Handle aMultipartException.net.solarnetwork.web.jakarta.domain.Response<?> handleTypeMismatchException(org.springframework.beans.TypeMismatchException e, org.springframework.web.context.request.WebRequest request, jakarta.servlet.http.HttpServletResponse response) Handle anTypeMismatchException.net.solarnetwork.web.jakarta.domain.Response<?> handleUnsupportedOperationException(UnsupportedOperationException e, org.springframework.web.context.request.WebRequest request) Handle anUnsupportedOperationExceptionas a 404 error status.net.solarnetwork.web.jakarta.domain.Response<?> handleValidationException(ValidationException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anValidationException.static StringrequestDescription(org.springframework.web.context.request.WebRequest request) Get a standardized string description of a request.voidsetMessageSource(org.springframework.context.MessageSource messageSource) Set a message source to use for resolving exception messages.static StringuserPrincipalName(org.springframework.web.context.request.WebRequest request) Get the user principal name of a given request.
-
Field Details
-
DEFAULT_DATE_FORMAT
The default format pattern for a date property.- See Also:
-
DEFAULT_DATE_TIME_FORMAT
The default format pattern for a date and time property.- See Also:
-
DEFAULT_DATE_TIME_FORMAT_Z
The default format pattern for adate and time property with an explicit Z time zone.- Since:
- 1.12
- See Also:
-
ALT_DATE_TIME_FORMAT
An alternate format pattern for a date and time property using a space delimiter between the date and time.- Since:
- 1.12
- See Also:
-
ALT_DATE_TIME_FORMAT_Z
An alternate format pattern for a date and time property with an explicit Z time zone using a space delimiter between the date and time.- Since:
- 1.12
- See Also:
-
DEFAULT_TIMESTAMP_FORMAT
The default format pattern for a millisecond-precise date and time property.- Since:
- 1.12
- See Also:
-
DEFAULT_TIMESTAMP_FORMAT_Z
The default format pattern for a millisecond-precise date and time property with an explicit Z time zone.- Since:
- 1.12
- See Also:
-
ALT_TIMESTAMP_FORMAT
An alternate format pattern for a millisecond-precise date and time property using a space delimiter between the date and time.- Since:
- 1.12
- See Also:
-
ALT_TIMESTAMP_FORMAT_Z
An alternate format pattern for a millisecond-precise date and time property with an explicit Z time zone using a space delimiter between the date and time.- Since:
- 1.12
- See Also:
-
ANONYMOUS_USER_PRINCIPAL
A value to use for anonymous users in log messages.- Since:
- 2.1
- See Also:
-
-
Constructor Details
-
WebServiceControllerSupport
public WebServiceControllerSupport()
-
-
Method Details
-
requestDescription
Get a standardized string description of a request.- Parameters:
request- the request- Returns:
- the description
-
userPrincipalName
Get the user principal name of a given request.- Parameters:
request- the request- Returns:
- the name, or
ANONYMOUS_USER_PRINCIPAL
-
handleBeanInstantiationException
@ExceptionHandler(org.springframework.beans.BeanInstantiationException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleBeanInstantiationException(org.springframework.beans.BeanInstantiationException e, org.springframework.web.context.request.WebRequest request) Handle anBeanInstantiationException.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
- Since:
- 1.15
-
handleTypeMismatchException
@ExceptionHandler(org.springframework.beans.TypeMismatchException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleTypeMismatchException(org.springframework.beans.TypeMismatchException e, org.springframework.web.context.request.WebRequest request, jakarta.servlet.http.HttpServletResponse response) Handle anTypeMismatchException.- Parameters:
e- the exceptionrequest- the requestresponse- the response- Returns:
- an error response object
- Since:
- 1.4
-
handleUnsupportedOperationException
@ExceptionHandler(java.lang.UnsupportedOperationException.class) @ResponseBody @ResponseStatus(code=NOT_FOUND) public net.solarnetwork.web.jakarta.domain.Response<?> handleUnsupportedOperationException(UnsupportedOperationException e, org.springframework.web.context.request.WebRequest request) Handle anUnsupportedOperationExceptionas a 404 error status.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
- Since:
- 1.15
-
handleJsonParseException
@ExceptionHandler(com.fasterxml.jackson.core.JsonParseException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleJsonParseException(com.fasterxml.jackson.core.JsonProcessingException e, org.springframework.web.context.request.WebRequest request) Handle aJsonProcessingException, presuming from malformed JSON input.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
- Since:
- 1.6
-
handleDateTimeParseException
@ExceptionHandler(java.time.format.DateTimeParseException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleDateTimeParseException(DateTimeParseException e, org.springframework.web.context.request.WebRequest request) Handle aDateTimeParseException, from malformed date input.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
- Since:
- 1.15
-
handleDateTimeException
@ExceptionHandler(java.time.DateTimeException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleDateTimeException(DateTimeException e, org.springframework.web.context.request.WebRequest request) Handle a general .- Parameters:
e- the exceptionrequest- the request- Returns:
- the error response object
- Since:
- 2.0
-
handleHttpMessageNotReadableException
@ExceptionHandler(org.springframework.http.converter.HttpMessageNotReadableException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleHttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException e, org.springframework.web.context.request.WebRequest request) Handle aHttpMessageNotReadableException, from malformed JSON input.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
- Since:
- 1.6
-
handleDataIntegrityViolationException
@ExceptionHandler(org.springframework.dao.DataIntegrityViolationException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleDataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException e, org.springframework.web.context.request.WebRequest request, Locale locale, jakarta.servlet.http.HttpServletRequest servletRequest) Handle aDataIntegrityViolationException.- Parameters:
e- the exceptionrequest- the requestlocale- the locale- Returns:
- an error response object
- Since:
- 1.8
-
handleDataRetrievalFailureException
@ExceptionHandler(org.springframework.dao.DataRetrievalFailureException.class) @ResponseBody @ResponseStatus(code=NOT_FOUND) public net.solarnetwork.web.jakarta.domain.Response<?> handleDataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle aDataRetrievalFailureException.- Parameters:
e- the exceptionrequest- the requestlocale- the locale- Returns:
- an error response object
- Since:
- 1.15
-
handleInvalidDataAccessResourceUsageException
@ExceptionHandler(org.springframework.dao.InvalidDataAccessResourceUsageException.class) @ResponseBody @ResponseStatus public net.solarnetwork.web.jakarta.domain.Response<?> handleInvalidDataAccessResourceUsageException(org.springframework.dao.InvalidDataAccessResourceUsageException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle aInvalidDataAccessResourceUsageException.- Parameters:
e- the exceptionrequest- the requestlocale- the desired locale- Returns:
- an error response object
- Since:
- 1.18
-
handleConstraintViolationException
@ExceptionHandler(jakarta.validation.ConstraintViolationException.class) @ResponseBody @ResponseStatus(UNPROCESSABLE_ENTITY) public net.solarnetwork.domain.Result<Void> handleConstraintViolationException(jakarta.validation.ConstraintViolationException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anConstraintViolationException.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
-
handleBindException
@ExceptionHandler(org.springframework.validation.BindException.class) @ResponseBody @ResponseStatus(UNPROCESSABLE_ENTITY) public net.solarnetwork.domain.Result<?> handleBindException(org.springframework.validation.BindException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anBindException.- Parameters:
e- the exceptionrequest- the requestlocale- the locale- Returns:
- an error response object
-
handleInvalidPropertyException
@ExceptionHandler(org.springframework.beans.InvalidPropertyException.class) @ResponseBody @ResponseStatus(UNPROCESSABLE_ENTITY) public net.solarnetwork.domain.Result<?> handleInvalidPropertyException(org.springframework.beans.InvalidPropertyException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anInvalidPropertyException.- Parameters:
e- the exceptionrequest- the requestlocale- the locale- Returns:
- an error response object
-
handleValidationException
@ExceptionHandler(ValidationException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleValidationException(ValidationException e, org.springframework.web.context.request.WebRequest request, Locale locale) Handle anValidationException.- Parameters:
e- the exceptionrequest- the requestlocale- the locale- Returns:
- an error response object
-
handleMultipartException
@ExceptionHandler(org.springframework.web.multipart.MultipartException.class) @ResponseBody @ResponseStatus(code=UNPROCESSABLE_ENTITY) public net.solarnetwork.web.jakarta.domain.Response<?> handleMultipartException(org.springframework.web.multipart.MultipartException e, org.springframework.web.context.request.WebRequest request) Handle aMultipartException.- Parameters:
e- the exceptionrequest- the request- Returns:
- an error response object
- Since:
- 1.20
-
addVaryResponseHeader
@ModelAttribute public void addVaryResponseHeader(jakarta.servlet.http.HttpServletResponse response) Add a Vary HTTP response header.This is so the responses work well with caching proxies.
- Parameters:
response- the response to add the header to- Since:
- 1.11
-
getMessageSource
public org.springframework.context.MessageSource getMessageSource()Get the message source.- Returns:
- the message source
-
setMessageSource
@Autowired public void setMessageSource(org.springframework.context.MessageSource messageSource) Set a message source to use for resolving exception messages.- Parameters:
messageSource- the message source
-