How do I get the JAX-RS @Path of a different resource during a POST?

前端 未结 4 1817
走了就别回头了
走了就别回头了 2021-02-02 15:09

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

4条回答
  •  礼貌的吻别
    2021-02-02 15:55

    I found a couple of javax.ws.rs.core.UriBuilder methods that did the trick, which I wanted to share in case others had this question. They are: UriBuilder.fromResource(OneUserResource.class) and javax.ws.rs.core.UriBuilder.path(Class). I used the latter in a one-shot call:

    URI newUserUri = uriInfo.getBaseUriBuilder().path(OneUserResource.class).path("/" + user.getId()).build();
    return Response.created(newUserUri).build();
    

提交回复
热议问题