title: What is the Jersey 2 replacement for ResourceContext.matchResource(URI)?
body: <p>How do I find out what Resource an arbitrary URI maps to under Jersey 2.0? Under Jersey 1.x I'd use <a href="https://jersey.java.net/apidocs/1.5/jersey/com/sun/jersey/api/core/ResourceContext.html#matchResource(java.net.URI)" rel="nofollow noreferrer">ResourceContext.matchResource(URI)</a>.</p>
  
  <p><strong>What I'm trying to do</strong>: I'm trying to process an incoming request that references another resource by URI. For example, here is an operation that links a user to a department.</p>
  
  <pre><code>POST /departments/5
  {
    "user": "http://example.com/users/10"
  }
  </code></pre>
  
  <p>POST /departments/5 resolves to:</p>
  
  <pre><code>class DepartmentResource
  {
    @POST
    void linkUser() { ... }
  }
  </code></pre>
  
  <p>In order to honor this request, I need to resolve the URI back to a UserResource and from there to its database id. Adding <code>@Context UriInfo</code> to <code>linkUser()</code> won't help because this <code>UriInfo</code> corresponds to the URI of the department instead of the user.</p>
  
  <p><strong>UPDATE</strong>: I filed a bug report at <a href="https://github.com/eclipse-ee4j/jersey/issues/2444" rel="nofollow noreferrer">https://github.com/eclipse-ee4j/jersey/issues/2444</a></p>
  
  <p><strong>UPDATE2</strong>: Posted a follow-up question: <a href="https://stackoverflow.com/q/23145871/14731">Jersey2: Navigating from a Resource to an instance</a></p>