Skip to content
Sergii Kabashniuk edited this page Mar 13, 2015 · 1 revision

Process of matching request to resource

Request matching

Matching of request to resource methods proceeds in next stages:

  1. Found root resource which has URI template matched to request URI and has a most character in URI template. In this case counted ONLY characters which are not a part or template variables. If no one root resource found then HTTP response with status 404, Not Found send back to client.
  2. If root resource found then get the 'tail' of request URI. If tail is '/' or null then look up resource method which annotated with request method designation matched to current HTTP method. If no one resource method found then send back to client response with status 405, Method not allowed. If methods were found then check is content-type of request is acceptable for any method (@Consumes annotation and Content-type header are used). If no such method found then 415, Unsupported Media Type send to client. Finally check is method able to produce content-type acceptable by client (@Produces annotation and Accept header are used). If method not able produce acceptable content then send 406, Not Acceptable response to client. Otherwise invoke method and send result to client.
  3. If 'tail' is nor null nor '/' then look up sub-resource method(s) or locator(s) which have URI template matched to 'tail'. If more then one sub-resource methods or locators found then method(s) with most character in URI template will be selected. If sub-resource methods and sub-resource locator have the same number of characters then sub-resource method has priority. If sub-resource locator selected then go again to 1 otherwise check is any of sub-resource methods has request method designation matched to current HTTP method. If no one methods were found then send back to client response with status 405 Method not allowed. After that to the same as for resource method, see above.

See for details section 3.7 Matching Requests to Resource Methods of JAX-RS specification.