jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Are Links build with fromReosurce or fromResourceMethod are useful at all?

From: Jan Algermissen <jan.algermissen_at_nordsc.com>
Date: Wed, 14 Nov 2012 11:29:57 +0100

Links that are constructed by using Link.fromResource or Link.fromResourceMethod come with a relative URI.

This URI is always relative to the JAX-RS application context.

If I am not completely out of my mind, these links are never useful as-is, because they are always relative in a way that doesn't fit any current resolution context.

At leat not without applying rewrite rules in front of the container.

E.g. suppose my app is living at

http://example.org/myWarName/

and my resources at

http://example.org/myWarName/resources

Now if I have

@Path("orders/service")
class OrderResource { ... }

@Path("customers/accounts/{id}")
class CustomerResource { ... }


and I do a GET on 'my' account:

GET http://example.org/myWarName/resources/customers/accounts/42

What might come back is a response with a Link to the order service:

200 Ok
Link: <orders/service>;rel=...

....


This link would never resolve to:


http://example.org/myWarName/resources/orders/service

but, (hope I get this right) to

orders/service

http://example.org/myWarName/resources/customers/accounts/orders/service


Bottom line seems to be: the runtime should prepend the base URI and produce absolute links.

However(!) given that it is very unusual to have the actual base-URI as the publicly visible base URI (there is usually quite a bunch of mangling going on) producing an absolute URI does cut it either - in fact it would be worse.

Maybe we need to rethink the UriBuilder.fromXXX behavior to that regard, too.


Any ideas?


Jan