Class WebUtils

java.lang.Object
net.solarnetwork.central.web.WebUtils

public final class WebUtils extends Object
Helper utilities for web APIs.
  • Field Details

    • TEXT_CSV_MEDIA_TYPE_VALUE

      public static final String TEXT_CSV_MEDIA_TYPE_VALUE
      The text/csv media type value.
      Since:
      1.2
      See Also:
    • TEXT_CSV_MEDIA_TYPE

      public static final org.springframework.http.MediaType TEXT_CSV_MEDIA_TYPE
      The text/csv media type.
    • TEXT_CSV_UTF8_MEDIA_TYPE_VALUE

      public static final String TEXT_CSV_UTF8_MEDIA_TYPE_VALUE
      The text/csv media type with a UTF-8 character set value.
      See Also:
    • TEXT_CSV_UTF8_MEDIA_TYPE

      public static final org.springframework.http.MediaType TEXT_CSV_UTF8_MEDIA_TYPE
      The text/csv media type with a UTF-8 character set.
    • XLSX_MEDIA_TYPE_VALUE

      public static final String XLSX_MEDIA_TYPE_VALUE
      The media type value for Microsoft XLSX.
      Since:
      1.2
      See Also:
    • XLSX_MEDIA_TYPE

      public static final org.springframework.http.MediaType XLSX_MEDIA_TYPE
      The media type for Microsoft XLSX.
      Since:
      1.2
  • Method Details

    • withoutHost

      public static org.springframework.web.util.UriComponents withoutHost(org.springframework.web.util.UriComponentsBuilder builder, Object... uriVariableValues)
      Build a UriComponents without any scheme, host, or port.
      Parameters:
      builder - the builder
      uriVariableValues - the optional URI variable values
      Returns:
      the URI components
    • withoutHost

      public static org.springframework.web.util.UriComponents withoutHost(org.springframework.web.util.UriComponentsBuilder builder, Map<String,?> uriVariables)
      Build a UriComponents without any scheme, host, or port.
      Parameters:
      builder - the builder
      uriVariables - the optional URI variables
      Returns:
      the URI components
    • uriWithoutHost

      public static URI uriWithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Object... uriVariableValues)
      Build a URI without any scheme, host, or port.
      Parameters:
      builder - the builder
      uriVariableValues - the optional URI variable values
      Returns:
      the URI
    • uriWithoutHost

      public static URI uriWithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Map<String,?> uriVariables)
      Build a URI without any scheme, host, or port.
      Parameters:
      builder - the builder
      uriVariables - the optional URI variables
      Returns:
      the URI
    • filteredResultsProcessorForType

      public static <T> FilteredResultsProcessor<T> filteredResultsProcessorForType(List<org.springframework.http.MediaType> acceptTypes, jakarta.servlet.http.HttpServletResponse response, OutputSerializationSupportContext<T> context) throws IOException
      Setup a filtered results processor.

      The following types are supported:

      • application/json
      • application/cbor
      • text/csv
      Type Parameters:
      T - the result type
      Parameters:
      acceptTypes - the acceptable types
      response - the HTTP response
      context - the output context
      Returns:
      the processor
      Throws:
      IOException - if an IO error occurs
      Since:
      1.1
    • requestUriWithQueryParameters

      public static String requestUriWithQueryParameters(jakarta.servlet.http.HttpServletRequest request)
      Get the request URI including query parameters as a string.
      Parameters:
      request - the servlet request
      Returns:
      the request URI with query parameters included
      Since:
      1.3
    • handleTransientDataAccessExceptionRetry

      public static void handleTransientDataAccessExceptionRetry(jakarta.servlet.http.HttpServletRequest req, org.springframework.dao.DataAccessException e, int retries, long retryDelay, org.slf4j.Logger log)
      Handle a DataAccessException by either logging a WARN log message if retries is greater than 0, or re-throwing the exception otherwise.
      Parameters:
      req - the HTTP request
      e - the exception
      retries - the number of retry attempts remaining
      retryDelay - a delay in milliseconds to sleep for, if retries is greater than 0
      log - the logger to log a WARN message to
      Since:
      1.3
    • doWithTransientDataAccessExceptionRetry

      public static <T> T doWithTransientDataAccessExceptionRetry(Supplier<T> action, jakarta.servlet.http.HttpServletRequest req, int tries, long retryDelay, org.slf4j.Logger log)
      Perform an action with DataAccessException retry.
      Type Parameters:
      T - the action argument type
      R - the action return type
      Parameters:
      action - the action to perform
      req - the HTTP request
      tries - the number of attempts to try
      retryDelay - a delay in milliseconds to sleep for, if retries is greater than 0
      log - the logger to log a WARN message to
      arg - the argument to pass to the action
      Returns: