users@jersey.java.net

[Jersey] Re: Decoding URI into path parameters

From: Markus Karg <karg_at_quipsy.de>
Date: Thu, 17 Mar 2011 15:12:24 +0100

Martin,

 

I'll try to find the time to post a complete working sample code tomorrow (have to strip closed source parts first).

 

Regards

Markus

 

From: Martin Matula [mailto:martin.matula_at_oracle.com]
Sent: Donnerstag, 17. März 2011 15:03
To: users_at_jersey.java.net
Subject: [Jersey] Re: Decoding URI into path parameters

 

Hi Markus - good point! I guess we should add a paragraph on this to our user guide as well as a sample. Please do share the snipped or even better feel free to contribute the sample.
Thanks!
Martin

On 17.3.2011 10:52, Markus Karg wrote:

Side Note: Using XmlAdapter you can performan translation of URI<--->Entity on the fly (when sending entity trees it replaces entity references by URIs, and when receiving entity URIs it replaces them by an instance using a subsequent HTTP GET). We're using this heavily in our application and it works pretty well. Maybe this makes your code easier for you. If you like I can post a snippet.

 

From: Gili [mailto:cowwoc_at_bbs.darktech.org]
Sent: Mittwoch, 16. März 2011 23:02
To: users_at_jersey.java.net
Subject: [Jersey] Re: Decoding URI into path parameters

 

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