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
  • Method Details

    • 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:
    • forwardTo

      public Response forwardTo(String path, HttpServletResponse response)
      Use a dispatcher to forward the request to the given path of a local resource. If the path is relative, it must be relative to the current servlet.
      Parameters:
      path - a String specifying the pathname to the resource
      response - the HTTP response used for the forward
      Returns:
      an empty JAX-RS response with a HTTP 200 status
      Throws:
      OslcWebApplicationException - if no request dispatcher can be provided by the servlet container or an error occurs during the forward
      Since:
      4.0.0
    • 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.