users@jersey.java.net

[Jersey] Re: Decoding URI into path parameters

From: Martin Matula <martin.matula_at_oracle.com>
Date: Thu, 17 Mar 2011 10:53:07 +0100

You can use path parameter instead of a particular hostname, like this:
UriTemplate ut = new
UriTemplate("http://{host}/context/jersey/books/{id}/page/{pageNum}");

You can even replace the whole context and care only about the
"jersey-specific" part of the URI like this:
UriTemplate ut = new UriTemplate("{context: *.}/books/{id}/page/{pageNum}");
Martin

On 16.3.2011 23:01, Gili wrote:
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> That's exactly what I was looking for. Thank you!
>
> PS: Is it possible to use regex in the template? For example, I'd want
> to match any host name to support clustering.
>
> Thanks,
> Gili
>
> On 16/03/2011 5:52 PM, Martin Matula-3 [via Jersey] wrote:
>> Hi Gili,
>>
>> On Mar 16, 2011, at 4:47 PM, Gili wrote:
>>
>> > If a user invokes HTTP PUT with a body that contains URIs, how
>> should I
>> > translate those URIs back to resource identifiers? Am I expected to
>> hit the
>> > URI, examine the body in order to figure out the resource identity
>> or should
>> > I parse the URI to an ID somehow? What's the best practice?
>>
>> You can use UriTemplate (see
>> http://jersey.java.net/nonav/apidocs/1.5/jersey/com/sun/jersey/api/uri/UriTemplate.html).
>>
>>
>> For example, like this:
>>
>> // create URI template object for a given template
>> UriTemplate ut = new
>> UriTemplate("http://localhost:8080/context/jersey/books/{id}/page/{pageNum}");
>>
>> // this hashmap will be populated with param name->value
>> mapping after the URI is matched
>> HashMap<String, String> m = new HashMap<String, String>();
>> // match the URI passed in the first parameter, populate the
>> map in the second parameter with params and values
>>
>> ut.match("http://localhost:8080/context/jersey/books/20/page/10"
>> <http://localhost:8080/context/jersey/books/20/page/10%22>, m);
>> // extract book ID from the URI
>> int bookId = m.get("id");
>>
>> Is that good enough for what you need?
>> Martin
>>
>> ------------------------------------------------------------------------
>> If you reply to this email, your message will be added to the
>> discussion below:
>> http://jersey.576304.n2.nabble.com/Decoding-URI-into-path-parameters-tp6167750p6179023.html
>> <http://jersey.576304.n2.nabble.com/Decoding-URI-into-path-parameters-tp6167750p6179023.html?by-user=t>
>>
>> To unsubscribe from Decoding URI into path parameters, click here
>> <http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6167750&code=Y293d29jQGJicy5kYXJrdGVjaC5vcmd8NjE2Nzc1MHwxNTc0MzIxMjQ3&by-user=t>.
>>
>
>
> ------------------------------------------------------------------------
> View this message in context: Re: Decoding URI into path parameters
> <http://jersey.576304.n2.nabble.com/Decoding-URI-into-path-parameters-tp6167750p6179046.html>
> Sent from the Jersey mailing list archive
> <http://jersey.576304.n2.nabble.com/> at Nabble.com.