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}")
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.
>