Class HttpServletSupport
- java.lang.Object
-
- net.shibboleth.utilities.java.support.net.HttpServletSupport
-
-
Constructor Summary
Constructors Modifier Constructor Description privateHttpServletSupport()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddNoCacheHeaders(javax.servlet.http.HttpServletResponse response)Adds Cache-Control and Pragma headers meant to disable caching.static URIgetFullRequestURI(javax.servlet.http.HttpServletRequest request)Gets the URL that was requested to generate this request.static List<Locale.LanguageRange>getLanguageRange(javax.servlet.http.HttpServletRequest request)Return theLocale.LanguageRangeassociated with this request.static StringgetRequestPathWithoutContext(javax.servlet.http.HttpServletRequest request)Gets the request URI as returned byHttpServletRequest.getRequestURI()but without the servlet context path.static voidsetContentType(javax.servlet.http.HttpServletResponse response, String contentType)Sets the MIME content type of the response.static voidsetUTF8Encoding(javax.servlet.http.HttpServletResponse response)Sets the character encoding of the transport to UTF-8.static booleanvalidateContentType(javax.servlet.http.HttpServletRequest request, Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy)Validate the Content-Type of the specified request.
-
-
-
Method Detail
-
addNoCacheHeaders
public static void addNoCacheHeaders(javax.servlet.http.HttpServletResponse response)
Adds Cache-Control and Pragma headers meant to disable caching.- Parameters:
response- transport to add headers to
-
setUTF8Encoding
public static void setUTF8Encoding(javax.servlet.http.HttpServletResponse response)
Sets the character encoding of the transport to UTF-8.- Parameters:
response- transport to set character encoding type
-
setContentType
public static void setContentType(javax.servlet.http.HttpServletResponse response, String contentType)Sets the MIME content type of the response.- Parameters:
response- the transport to set content type oncontentType- the content type to set
-
getRequestPathWithoutContext
public static String getRequestPathWithoutContext(javax.servlet.http.HttpServletRequest request)
Gets the request URI as returned byHttpServletRequest.getRequestURI()but without the servlet context path.- Parameters:
request- request to get the URI from- Returns:
- constructed URI
-
getFullRequestURI
public static URI getFullRequestURI(javax.servlet.http.HttpServletRequest request)
Gets the URL that was requested to generate this request. This includes the scheme, host, port, path, and query string.- Parameters:
request- current request- Returns:
- URL that was requested to generate this request
-
validateContentType
public static boolean validateContentType(javax.servlet.http.HttpServletRequest request, Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy)Validate the Content-Type of the specified request.Two strategies are supported for evaluating the request's parsed content type:
-
If isOneOfStrategy is true, then the
MediaTypeparsed from the request is compared to each of the specified valid types viaMediaType.is(MediaType). If any pass, the type is considered valid. This allows use of MediaType's support for wildcard and parameter evaluation. -
If isOneOfStrategy is false, then the
MediaTypeparsed from the request is stripped of its parameters, as is each of the valid types. Then a simple evaluation is done that the request type is equal to one of the passed types. In this case, only literal types and subtypes should be passed as valid types; wildcards should not be used.
- Parameters:
request- the request to be validatedvalidTypes- the set of valid media typesnoContentTypeIsValid- flag whether the case of a missing/empty Content-Type header is considered validisOneOfStrategy- flag for the strategy used in the validation (see above for details)- Returns:
- true if the content type is valid, false if not
-
If isOneOfStrategy is true, then the
-
getLanguageRange
@Nonnull @NonnullElements @Unmodifiable public static List<Locale.LanguageRange> getLanguageRange(javax.servlet.http.HttpServletRequest request)
Return theLocale.LanguageRangeassociated with this request. This is more up to date thanServletRequest.getLocales().- Parameters:
request- the request to process- Returns:
- The range.
-
-