[jboss-jira] [JBoss JIRA] (WFLY-3212) Access Base URI without CDI

Marek Kopecký (Jira) issues at jboss.org
Mon Feb 4 02:24:00 EST 2019


    [ https://issues.jboss.org/browse/WFLY-3212?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13690493#comment-13690493 ] 

Marek Kopecký commented on WFLY-3212:
-------------------------------------

bq. my problem is I need the baseUri in a piece of code I can't Inject into, (a sub object of an entity).
[~xenoterracide]: Can you please share an example? I tried this and it works as expected:
{code:java}
public class CustomObject {
    public String get() {
        UriInfo uriInfo = ResteasyProviderFactory.getContextData(UriInfo.class);
        return uriInfo.getAbsolutePath().toString();
    }
}

@Path("/")
public class Resource {
    @GET
    @Path("a")
    public String getDemoValue() {
        CustomObject customObject = new CustomObject();
        return customObject.get();
    }
}
{code}

> Access Base URI without CDI
> ---------------------------
>
>                 Key: WFLY-3212
>                 URL: https://issues.jboss.org/browse/WFLY-3212
>             Project: WildFly
>          Issue Type: Feature Request
>          Components: REST
>            Reporter: Caleb Cushing
>            Priority: Minor
>
> I need to get at the baseUri, I'm familliar with this
>     @Context
>     UriInfo uriInfo;
> my problem is I need the baseUri in a piece of code I can't Inject into, (a sub object of an entity). I could pass `uriInfo` or the builder down but that doesn't seem ideal, as most of the objects have no business knowing about it. The end goal is HATEOAS URI's in my JSON responses, but I don't need it to be a JAX-RS specific solution, I figure if I can just get at the Base URI either in my jackson converters, or entities, I can create the `URIBuilder` from there. It seems to me that once the app is deployed the base uri could be a global singleton.
> This is requesting a feature that allows me to access the base uri in the application or a URIBuilder similar to UriInfo.getBaseUriBuilder() except without requiring that the object be injected, this object would obviously not have request specific information



--
This message was sent by Atlassian Jira
(v7.12.1#712002)



More information about the jboss-jira mailing list