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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    An alternate format pattern for a date and time property using a space delimiter between the date and time.
    static final String
    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.
    static final String
    An alternate format pattern for a millisecond-precise date and time property using a space delimiter between the date and time.
    static final String
    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.
    static final String
    A value to use for anonymous users in log messages.
    static final String
    The default format pattern for a date property.
    static final String
    The default format pattern for a date and time property.
    static final String
    The default format pattern for adate and time property with an explicit Z time zone.
    static final String
    The default format pattern for a millisecond-precise date and time property.
    static final String
    The default format pattern for a millisecond-precise date and time property with an explicit Z time zone.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addVaryResponseHeader(jakarta.servlet.http.HttpServletResponse response)
    Add a Vary HTTP response header.
    org.springframework.context.MessageSource
    Get the message source.
    net.solarnetwork.web.jakarta.domain.Response<?>
    handleBeanInstantiationException(org.springframework.beans.BeanInstantiationException e, org.springframework.web.context.request.WebRequest request)
    Handle an BeanInstantiationException.
    net.solarnetwork.domain.Result<?>
    handleBindException(org.springframework.validation.BindException e, org.springframework.web.context.request.WebRequest request, Locale locale)
    Handle an BindException.
    net.solarnetwork.domain.Result<Void>
    handleConstraintViolationException(jakarta.validation.ConstraintViolationException e, org.springframework.web.context.request.WebRequest request, Locale locale)
    Handle an ConstraintViolationException.
    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 a DataIntegrityViolationException.
    net.solarnetwork.web.jakarta.domain.Response<?>
    handleDataRetrievalFailureException(org.springframework.dao.DataRetrievalFailureException e, org.springframework.web.context.request.WebRequest request, Locale locale)
    Handle a DataRetrievalFailureException.
    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 a DateTimeParseException, 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 a HttpMessageNotReadableException, 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 a InvalidDataAccessResourceUsageException .
    net.solarnetwork.domain.Result<?>
    handleInvalidPropertyException(org.springframework.beans.InvalidPropertyException e, org.springframework.web.context.request.WebRequest request, Locale locale)
    Handle an InvalidPropertyException.
    net.solarnetwork.web.jakarta.domain.Response<?>
    handleJsonParseException(com.fasterxml.jackson.core.JsonProcessingException e, org.springframework.web.context.request.WebRequest request)
    Handle a JsonProcessingException, 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 a MultipartException.
    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 an TypeMismatchException.
    net.solarnetwork.web.jakarta.domain.Response<?>
    handleUnsupportedOperationException(UnsupportedOperationException e, org.springframework.web.context.request.WebRequest request)
    Handle an UnsupportedOperationException as a 404 error status.
    net.solarnetwork.web.jakarta.domain.Response<?>
    handleValidationException(ValidationException e, org.springframework.web.context.request.WebRequest request, Locale locale)
    static String
    requestDescription(org.springframework.web.context.request.WebRequest request)
    Get a standardized string description of a request.
    void
    setMessageSource(org.springframework.context.MessageSource messageSource)
    Set a message source to use for resolving exception messages.
    static String
    userPrincipalName(org.springframework.web.context.request.WebRequest request)
    Get the user principal name of a given request.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_DATE_FORMAT

      public static final String DEFAULT_DATE_FORMAT
      The default format pattern for a date property.
      See Also:
    • DEFAULT_DATE_TIME_FORMAT

      public static final String DEFAULT_DATE_TIME_FORMAT
      The default format pattern for a date and time property.
      See Also:
    • DEFAULT_DATE_TIME_FORMAT_Z

      public static final String 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

      public static final String 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

      public static final String 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

      public static final String DEFAULT_TIMESTAMP_FORMAT
      The default format pattern for a millisecond-precise date and time property.
      Since:
      1.12
      See Also:
    • DEFAULT_TIMESTAMP_FORMAT_Z

      public static final String 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

      public static final String 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

      public static final String 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

      public static final String 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

      public static String requestDescription(org.springframework.web.context.request.WebRequest request)
      Get a standardized string description of a request.
      Parameters:
      request - the request
      Returns:
      the description
    • userPrincipalName

      public static String userPrincipalName(org.springframework.web.context.request.WebRequest request)
      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 an BeanInstantiationException.
      Parameters:
      e - the exception
      request - 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 an TypeMismatchException.
      Parameters:
      e - the exception
      request - the request
      response - 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 an UnsupportedOperationException as a 404 error status.
      Parameters:
      e - the exception
      request - 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 a JsonProcessingException, presuming from malformed JSON input.
      Parameters:
      e - the exception
      request - 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 a DateTimeParseException, from malformed date input.
      Parameters:
      e - the exception
      request - 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 exception
      request - 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 a HttpMessageNotReadableException, from malformed JSON input.
      Parameters:
      e - the exception
      request - 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 a DataIntegrityViolationException.
      Parameters:
      e - the exception
      request - the request
      locale - 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 a DataRetrievalFailureException.
      Parameters:
      e - the exception
      request - the request
      locale - 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 a InvalidDataAccessResourceUsageException .
      Parameters:
      e - the exception
      request - the request
      locale - 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 an ConstraintViolationException.
      Parameters:
      e - the exception
      request - 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 an BindException.
      Parameters:
      e - the exception
      request - the request
      locale - 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 an InvalidPropertyException.
      Parameters:
      e - the exception
      request - the request
      locale - 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)
      Parameters:
      e - the exception
      request - the request
      locale - 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 a MultipartException.
      Parameters:
      e - the exception
      request - 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