users@jersey.java.net

[Jersey] Re: Can we get rid of duplicate _at_Path?

From: Markus Karg <karg_at_quipsy.de>
Date: Tue, 1 Feb 2011 14:00:53 +0100

Paul,

>> We currently have the following code, which is prototypical for a
>> POST / GET combination. POST is implemented by the root resource,
>> and must return a location header pointing to the created sub
>> resource. Then, a client can use that URI to GET a sub resource,
>> implemented by a second class:
>> @Path("myroot") public class RootResource {
>> @POST public post() {
>> ...create in database and request id from it...
>> URI location =
UriBuilder.fromResource(SubResource.class).build(...
>> id from database...);
> UriInfo ui = ...
> Method m = ...
> ui.getRequestUriBuilder().path(m).build(...id from database...);
> it ain't ideal because it is a PITA to reference methods in Java.
> Otherwise declare the "{id}" as a string constant and refer to that in

> the builder and the @Path annotation on getSubResource method:
> UriBuilder.fromPath(ID_PATH).build(...id from database...);

thanks for sharing your ideas.

We had used both solutions before, but just thought there might be
something we missed in the spec. It seems, we didn't.

Sad but true that there is no UriBuilder.fromMethod(Class cls, String
method), because that would remove the need to fiddle with additional
UriInfo and Method, which both spoils the code a bit. It could be
implemented just like UriBuilder.fromPath("").path(Method) (which is
what we will use finally) -- I should file an RFE for JAX-RS 2.0. ;-)

Regards
Markus