Class LocalResourceDispatcher

java.lang.Object
com.sodius.oslc.server.util.LocalResourceDispatcher

public class LocalResourceDispatcher extends Object
Handy class to identify requests to local resources and to dispatch them properly.
Since:
3.3.0
  • Method Details

    • of

      public static LocalResourceDispatcher of(HttpServletRequest request, HttpServletResponse response)
      Creates an instance for a given HTTP request and response.
      Parameters:
      request - the HTTP request.
      response - the HTTP response.
      Returns:
      the corresponding instance.
    • isLocalRequest

      public boolean isLocalRequest(URI uri)
      Determines whether a URI corresponds to a local resource.
      Parameters:
      uri - the resource URI.
      Returns:
      true if uri corresponds to a local resource; false otherwise.
    • dispatch

      public Response dispatch(URI uri)
      Dispatches a request to a local resource. This method removes the protocol and hostname of the given URI up the application context to ensure a local resource is fetched.

      Note: a request forward has been observed not to work as expected in some JAX-RS contexts. Current recommendations are:

      Parameters:
      uri - the local resource URI.
      Returns:
      a temporary redirect response if the Options.OPTION_ENABLE_PROXY_REDIRECT option is enabled; an empty JAX-RS response with a HTTP 200 status otherwise.
      Throws:
      OslcWebApplicationException - if no request dispatcher can be provided by the servlet container or an error occurs during the forward