jax-rs Link builder is ignoring base uri, want to create absolute link

403 views Asked by At

I am trying to add links to my jax-rs response headers:

Link.fromMethod(UserResource.class, "delete")
        .baseUri(getUriInfo().getBaseUri()).rel("delete").build(id);

While i see in per debugger and log that getUriInfo().getBaseUri() returns the correct uri, the resulting link is only /1 (for id=1).

Using UriBuilder it is working!

URI build = getUriInfo().getBaseUriBuilder().path(UserResource.class, "delete").build(id);
Link.fromUri(build).rel("delete").build();

getUriInfo just returns uriInfo from base class injected with @Context.

So how to get it working with Link (it should work, shouldn't it)?

1

There are 1 answers

0
Ante On

This worked for me:

UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
UriBuilder clone = uriBuilder.clone();
clone.path("xxx");
Link link = Link.fromUriBuilder(clone).rel("self").type("GET").build();

cloning because I re use the builder