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

前端 未结 4 1819
走了就别回头了
走了就别回头了 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 16:15

    As of JAX-RS 2.0, the most correct way (As far as I know) is to use the builder method like so:

        String uri = uriInfo.getBaseUriBuilder()
          .path(ODataV4Endpoint.class)
          .path(ODataV4Endpoint.class, "serviceEndpointJSONCatalog")
          .resolveTemplate("endpointId", endpointId).build().toString();
    

    FYI, I need to call path twice in my case, once for the path annotation on the class, and the second time for the annotation on the method. I suspected the call to the method would do both, but it does not.

    The Path annotation on the endpoint serviceEndpointJSONCatalog declared a parameter, like so: 'endpoint/{endpointId}', so the call to resolveTemplate was needed. Otherwise you would just call path(Class cl, String method).

    In my case I created a builder and a symbolic way to reference the methods so the compiler / runtime could check them.

提交回复
热议问题