Hi On Wed, Feb 23, 2011 at 9:00 PM, KARR, DAVID (ATTSI) <[email protected]> wrote: >> -----Original Message----- >> From: Sergey Beryozkin [mailto:[email protected]] >> Sent: Wednesday, February 23, 2011 12:07 PM >> To: [email protected] >> Subject: Re: Convenience features for generating HATEOAS urls? >> >> The builder methods such as queryParam(), etc, which do affect the >> internal state are obviously not thread-safe. >> >> Actually, I've reread your message - you were saying you assembled a >> cache... >> >> So those UriBuilder instances, in the cache, represent the relative >> URIs, so you can just keep the cache of relative URIs converted to >> strings only and then add them as links provided you have an xml:base, >> or if not then add them as path values to the the uri builder >> representing the current baseUri builder. Finally when building the >> uri using uriBuilder.build(), you may need to pass the values of the >> path parameters, if a given method has say @Path("{id}") > > I could use more elaboration. > > What is "xml:base"? > If a given xml or even json sequence contains relative links then an xml:base attribute can be used to resolve them against a base absolute uri :
http://www.w3.org/TR/xmlbase/ See also http://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java You could do WebClient client = WebClient.create(address); XMLSource source = client.get(XMLSource.class); URI xmlBase = source.getBaseURI(); then you can use xmlSource.getLink methods in combination with XPath expressions and combine the results with the baseURI if needed > How do I convert the relative Builder to a string (the obvious > builder.toString() doesn't do anything useful) so I can cache it? > uriBuilder.build().toString() > And a perhaps unrelated question: What is a "matrix param"? The javadoc for > the related methods don't appear to tell me what it really is. > they belong to individual path segments, ex /foo;id=1;id=2/bar;c=3; id and c are matrix parameters Cheers, Sergey >> You may also try uriInfo.getAbsoluteUriBuilder (sorry - do not have >> eclipse opened now so the actual name of the method may differ >> slightly) - this will give you the complete URI which the current >> method is processing...There's also the UriInfo method which will give >> you the builder containing the query parameters too >> >> >> thanks, Sergey >> >> On Wed, Feb 23, 2011 at 7:51 PM, KARR, DAVID (ATTSI) <[email protected]> >> wrote: >> >> -----Original Message----- >> >> From: Sergey Beryozkin [mailto:[email protected]] >> >> Sent: Wednesday, February 23, 2011 2:21 AM >> >> To: [email protected] >> >> Subject: Re: Convenience features for generating HATEOAS urls? >> >> >> >> Hi >> >> > >> >> > Are UriBuilder instances thread-safe? If I assembled a cache of >> >> UriBuilder instances mapped to the public methods of my class (which >> >> have the @GET or @POST annotation), can I then use that and call >> >> "build()" and other methods on that instance? For instance, does >> >> "build()" on a UriBuilder return the same instance, or a new one? >> >> > >> >> >> >> uriBuilder.build() returns a new URI instance every time. >> >> I think, in CXF at least, calling build() on the same cached >> >> UriBuilder instance, should be safe too because it does not modify >> any >> >> state internally while building a URI. uriBuilder.clone won't be, >> but >> >> uriBuilder.build() should be ok... >> > >> > What about the "queryParam()" method? That returns a UriBuilder, not >> a URI. >> > >
