users@jersey.java.net

[Jersey] Re: Decoding URI into path parameters

From: Gili <cowwoc_at_bbs.darktech.org>
Date: Wed, 16 Mar 2011 15:01:58 -0700 (PDT)

     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
>
> 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>.
>



--
View this message in context: http://jersey.576304.n2.nabble.com/Decoding-URI-into-path-parameters-tp6167750p6179046.html
Sent from the Jersey mailing list archive at Nabble.com.