Package net.solarnetwork.central.web
Class WebUtils
java.lang.Object
net.solarnetwork.central.web.WebUtils
Helper utilities for web APIs.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.springframework.http.MediaTypeThe text/csv media type.static final StringThe text/csv media type value.static final org.springframework.http.MediaTypeThe text/csv media type with a UTF-8 character set.static final StringThe text/csv media type with a UTF-8 character set value.static final org.springframework.http.MediaTypeThe media type for Microsoft XLSX.static final StringThe media type value for Microsoft XLSX. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TdoWithTransientDataAccessExceptionRetry(Supplier<T> action, jakarta.servlet.http.HttpServletRequest req, int tries, long retryDelay, org.slf4j.Logger log) Perform an action withDataAccessExceptionretry.static <T> FilteredResultsProcessor<T> filteredResultsProcessorForType(List<org.springframework.http.MediaType> acceptTypes, jakarta.servlet.http.HttpServletResponse response, OutputSerializationSupportContext<T> context) Setup a filtered results processor.static voidhandleTransientDataAccessExceptionRetry(jakarta.servlet.http.HttpServletRequest req, org.springframework.dao.DataAccessException e, int retries, long retryDelay, org.slf4j.Logger log) Handle aDataAccessExceptionby either logging a WARN log message ifretriesis greater than 0, or re-throwing the exception otherwise.static StringrequestUriWithQueryParameters(jakarta.servlet.http.HttpServletRequest request) Get the request URI including query parameters as a string.static URIuriWithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Object... uriVariableValues) Build aURIwithout any scheme, host, or port.static URIuriWithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Map<String, ?> uriVariables) Build aURIwithout any scheme, host, or port.static org.springframework.web.util.UriComponentswithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Object... uriVariableValues) Build aUriComponentswithout any scheme, host, or port.static org.springframework.web.util.UriComponentswithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Map<String, ?> uriVariables) Build aUriComponentswithout any scheme, host, or port.
-
Field Details
-
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_TYPEThe text/csv media type. -
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_TYPEThe text/csv media type with a UTF-8 character set. -
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_TYPEThe 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 aUriComponentswithout any scheme, host, or port.- Parameters:
builder- the builderuriVariableValues- 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 aUriComponentswithout any scheme, host, or port.- Parameters:
builder- the builderuriVariables- the optional URI variables- Returns:
- the URI components
-
uriWithoutHost
public static URI uriWithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Object... uriVariableValues) Build aURIwithout any scheme, host, or port.- Parameters:
builder- the builderuriVariableValues- the optional URI variable values- Returns:
- the URI
-
uriWithoutHost
public static URI uriWithoutHost(org.springframework.web.util.UriComponentsBuilder builder, Map<String, ?> uriVariables) Build aURIwithout any scheme, host, or port.- Parameters:
builder- the builderuriVariables- 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 typesresponse- the HTTP responsecontext- the output context- Returns:
- the processor
- Throws:
IOException- if an IO error occurs- Since:
- 1.1
-
requestUriWithQueryParameters
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 aDataAccessExceptionby either logging a WARN log message ifretriesis greater than 0, or re-throwing the exception otherwise.- Parameters:
req- the HTTP requeste- the exceptionretries- the number of retry attempts remainingretryDelay- a delay in milliseconds to sleep for, ifretriesis greater than 0log- 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 withDataAccessExceptionretry.- Type Parameters:
T- the action argument typeR- the action return type- Parameters:
action- the action to performreq- the HTTP requesttries- the number of attempts to tryretryDelay- a delay in milliseconds to sleep for, ifretriesis greater than 0log- the logger to log a WARN message toarg- the argument to pass to the action- Returns:
-