users@jersey.java.net

[Jersey] Re: UriInfo injection at resource initialization time

From: Martin Matula <martin.matula_at_oracle.com>
Date: Wed, 09 Mar 2011 17:01:19 +0100

I still don't see how that gets you any more further than
UriBuilder.fromResource(class).build().
The root resource needs to figure out the server name, port, context
path and server mapping. How did you get that without the request context?
If you figured out how to get the "base URI" it for your servlet outside
of the request context, you can do the same thing for your JAX-RS
resources and then just do
UriBuilder.fromUri(baseUri).path(Resource.class).build().
Martin

On 9.3.2011 16:49, Martynas Jusevicius wrote:
> I had a recursive Resource.getAbsolutePath() which went up the parent
> tree concatenating getPath().
>
> For singletons I could get the URI like this:
> SearchResource.getInstance().getAbsolutePath().
>
> For other Resources the mapping happened within the request.
>
> On Wed, Mar 9, 2011 at 4:31 PM, Martin Matula<martin.matula_at_oracle.com> wrote:
>> Hi Martynas,
>>
>> On 9.3.2011 15:59, Martynas Jusevicius wrote:
>>>>> I had achieved the same using abstract Resource superclass (like in my
>>>>> last example) with
>>>>> - getPath() and getAbsolutePath() equivalents
>>>>> - constructor Resource(Resource parent) - effectively building a
>>>>> parent/child tree of Resource instances
>>>>> - Servlet-like doGet(), doPost() etc methods
>>>>> and the real HttpServlet mapping request URIs to Resource instances
>>>>> and executing the appropriate do..() methods.
>> I mean, how did you get the absolute URI outside of the request context? I
>> am guessing all the above initialization happened upon the first request
>> within it's context, no?
>> Martin
>>
>>