Hi Simon On Tue, Apr 12, 2011 at 9:01 PM, Simon Chen <[email protected]> wrote:
> Hi Sergey, > > I tried adding "@context UriInfo uriInfo;" into my class definition, > however, when I try to get uri information from the uriInfo object, I > always get a NullPointerException. Do I need to initialize the uriInfo > in any way? > > Is it the root resource that you add the Context fields to ? Do you mean the context field is simply not initialized and this causes NPE ? How do you register this resource. do you have Spring AOP involved ? Cheers. Sergey > I don't think this example here did anything special: > http://download.oracle.com/docs/cd/E19776-01/820-4867/6nga7f5og/index.html > > Just to give some context, I am trying to embed some URI information > into the XML serialization. I am doing @XmlIDREF and @XmlElement > markup for any non-containment references. I thought that in addition > to print out a name (marked by @XmlID), it might be useful to give the > associated URI as well. > > Thanks. > -Simon > > On Mon, Apr 11, 2011 at 5:08 PM, Sergey Beryozkin <[email protected]> > wrote: > > Hi > > > > On Mon, Apr 11, 2011 at 9:27 PM, Simon Chen <[email protected]> > wrote: > >> > >> Hi all, > >> > >> I'm wondering if there is a way for an object in the web service to > >> somehow self-report where it is, in term of uri path? > >> > >> For example, we have: > >> > >> @path("/webstore/") > >> class WebStore { > >> @path("/customers/") > >> List<Customer> customers; > >> } > >> > >> Given a link "cl" to a Customer object, can we somehow figure out that > >> it is under "/webstore/customers"? I understand that we can probably > >> easily hard-code this, but I want to do it more automatically... > >> > > Have JAX-RS UriInfo injected: > > > > @path("/webstore/") > > class WebStore { > > @Context > > private UriInfo uriInfo; > > } > > > > then you can do: > > > > uriInfo.getBaseUri() > > > > or > > > > UriBuilder builder = uriInfo.getBaseUriBuilder(); > > > > Cheers, Sergey > > > >> Thanks. > >> -SImon > > > > > > > > -- > > Sergey Beryozkin > > > > Application Integration Division of Talend > > http://sberyozkin.blogspot.com > > > -- Sergey Beryozkin Application Integration Division of Talend <http://www.talend.com> http://sberyozkin.blogspot.com
