Package com.sodius.oslc.server
Class OslcRequests
- java.lang.Object
-
- com.sodius.oslc.server.OslcRequests
-
public class OslcRequests extends Object
Provides access to various properties of servlet requests.- Since:
- 1.13.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OslcRequests.HttpServletRequestWrapperBuilder
A builder of request wrapper.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description URI
getFullUri()
Returns the complete URI of the request, which combines the full request path and the query string, if any.List<Locale>
getLocales()
Returns a list of enabled Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header and supported by the server.boolean
isAccepted(MediaType type)
Determines whether the given media type is compatible with the request Accept header.static OslcRequests
of(HttpServletRequest request)
Returns an instance that wraps the specified servlet request.OslcRequests.HttpServletRequestWrapperBuilder
wrapper()
Returns a builder to create a request wrapper, for overriding some properties of the underlying request.
-
-
-
Method Detail
-
of
public static OslcRequests of(HttpServletRequest request)
Returns an instance that wraps the specified servlet request.- Parameters:
request
- a servlet request.- Returns:
- a new OslcRequests instance.
-
isAccepted
public boolean isAccepted(MediaType type)
Determines whether the given media type is compatible with the request Accept header.- Parameters:
type
- a media type to test.- Returns:
true
if the request Accept header is compatible with the given type or if the Accept value is empty,false
otherwise.
-
getFullUri
public URI getFullUri()
Returns the complete URI of the request, which combines the full request path and the query string, if any.- Returns:
- the complete URI of the request.
-
getLocales
public List<Locale> getLocales()
Returns a list of enabled Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header and supported by the server.The returned list contains the locales requested by client and supported by the server, as defined by the
Options.ENABLED_LOCALES
property. If the server doesn't support any locale requested by client, this method returns an empty list.- Returns:
- a list of preferred Locale objects for the client and enabled on server.
- See Also:
Options.ENABLED_LOCALES
-
wrapper
public OslcRequests.HttpServletRequestWrapperBuilder wrapper()
Returns a builder to create a request wrapper, for overriding some properties of the underlying request. Wrapping a request may be useful for example in a filter, for removing or overriding the value of a header, so that successive filters are not aware of the original header the filter has already processed.Here's an example of builder usage:
HttpServletRequest wrapped = OslcRequests.of(request).wrapper().removeHeader(HttpHeaders.AUTHORIZATION).build();
- Returns:
- a builder to create a request wrapper
- Since:
- 1.14.0.
-
-