users@jax-rs-spec.java.net

[jax-rs-spec users] UriInfo CDI enabled

From: Sebastian Daschner <java_at_sebastian-daschner.de>
Date: Mon, 1 Feb 2016 21:56:38 +0100

Hi experts,

Thanks for the work done so far.

We had the case in projects that we wanted to construct URIs based on
UriInfo without wanting to pass the current UriInfo into other
(dedicated helper) classes.

Do you think it's feasible to enable the request scoped UriInfo (plus
maybe others) for CDI injection, in order to decouple potential URI
construction classes from the JAX-RS resources?

So something like follows would be possible (to call the method from any
component):

public class BookstoreUriBuilder {

    @Inject
    UriInfo uriInfo;

    public URI forBook(Book book) {
        return uriInfo.getBaseUriBuilder()
            .path(BooksResource.class)
            .path(BooksResource.class, "getBook")
            .build(book.getId());
    }

}

WDYT?

Cheers,
Sebastian