Package com.sodius.oslc.server.util
Class LocalResourceDispatcher
java.lang.Object
com.sodius.oslc.server.util.LocalResourceDispatcher
Handy class to identify requests to local resources and to dispatch them properly.
- Since:
- 3.3.0
-
Method Summary
Modifier and TypeMethodDescriptionDispatches a request to a local resource.booleanisLocalRequest(URI uri) Determines whether a URI corresponds to a local resource.static LocalResourceDispatcherof(HttpServletRequest request, HttpServletResponse response) Creates an instance for a given HTTP request and response.
-
Method Details
-
of
Creates an instance for a given HTTP request and response.- Parameters:
request- the HTTP request.response- the HTTP response.- Returns:
- the corresponding instance.
-
isLocalRequest
Determines whether a URI corresponds to a local resource.- Parameters:
uri- the resource URI.- Returns:
trueifuricorresponds to a local resource;falseotherwise.
-
dispatch
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 forwardhas been observed not to work as expected in some JAX-RS contexts. Current recommendations are:- When possible, clients should detect local resources on their own and make direct calls to them
rather than go through the
ProxyService - Applications not compatible with
RequestDispatchershould useOptions.enableProxyRedirect(boolean)
- Parameters:
uri- the local resource URI.- Returns:
- a temporary redirect response if the
Options.OPTION_ENABLE_PROXY_REDIRECToption 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
- When possible, clients should detect local resources on their own and make direct calls to them
rather than go through the
-