title: How do I get the JAX-RS @Path of a different resource during a POST?
body: <p>I have two REST classes for a simple web service (Jersey and GlassFish) that involves user resources - one to operate on all users (e.g., a factory for @POSTing) and another on individual users (e.g., @GET, @PUT, @DELETE). They are at:</p>
  
  <pre><code>@Stateless @Path("users") public class AllUsersResource {...}
  @Stateless @Path("user") public class OneUserResource {...}
  </code></pre>
  
  <p>respectively. When POSTing to AllUsersResource I want to return the Location (via <code>Response.created(uri).build()</code>) of the new User, e.g.,</p>
  
  <pre><code>http://localhost:8080/.../user/152
  </code></pre>
  
  <p>My question is how to do this. AllUsersResource injects @Context UriInfo uriInfo, but that does not get me @Path info for OneUserResource, only that of the current call ("users"). The way I finally got it working was simply to use reflection, but I'm worried it is brittle and unclean:</p>
  
  <pre><code>OneUserResource.class.getAnnotation(Path.class).value();
  </code></pre>
  
  <p>Searching StackOverflow the only other things I found to try were the following, without success:</p>
  
  <ul>
  <li>com.sun.jersey.api.core.ResourceContext</li>
  <li>javax.ws.rs.core.UriInfo.getMatchedResources()</li>
  <li>@javax.inject.Inject OneUserResource oneUserRes;</li>
  </ul>
  
  <p>Any help would be terrific!</p>