users@jersey.java.net

Re: What does it take to recognize a hierarchy formatted URI?

From: Martin Grotzke <martin.grotzke_at_javakaffee.de>
Date: Thu, 27 Mar 2008 23:34:19 +0100

Hi William,

On Thu, 2008-03-27 at 05:04 -0500, William Brogden wrote:
> Using this hierarchy formatted GET
> http://localhost:8080/MetaPhone2/resources/lookup/word/varmit
>
> results in a 404 not found response.
>
> What do I have to do to get it to map a hierarchy formatted GET
> to the "lookup" path?

AFAIK you should be able to do s.th. like this within your
LookupResource mapped to the path "/lookup":

    @GET
    @Path( "word/{word}" )
    @ProduceMime({ "application/xml" })
    public Response lookupWord( @PathParam( "word" ) String word ) {
        ...
    }

Though, "lookup" sounds like a verb and not a resource, so it would be
good to know what you are trying to achieve, to get it more RESTful...

E.g. if you simply want to return the word (and status 200) if it exists
and status 404 if it does not exist, you might create a WordsResource
mapped to "/words", so that you can retrieve a word via

    GET /resources/words/varmit

and your WordsResource.lookupWord might look like this:

    @GET
    @Path( "{word}" )
    @ProduceMime({ "application/xml" })
    public Response lookupWord( @PathParam( "word" ) String word ) {
        ...
    }

Cheers,
Martin



On Thu, 2008-03-27 at 05:04 -0500, William Brogden wrote:
> Using the steps in
> https://jersey.dev.java.net/use/getting-started.html
>
> I used NetBeans 6.0 to create a simple Restful Web Service
> using the Singleton Pattern. I put some simple debugging
> String return in the getHtml() method. Deployment to
> Tomcat 6.0.14
>
> Doing a GET with this query formatted URI
> http://localhost:8080/MetaPhone2/resources/lookup?word=varmit
> works as expected.
>
> Using this hierarchy formatted GET
> http://localhost:8080/MetaPhone2/resources/lookup/word/varmit
>
> results in a 404 not found response.
>
> What do I have to do to get it to map a hierarchy formatted GET
> to the "lookup" path?
>
> Casual inspection of the Jersey 0.6ea examples show pleny of
> hierarchy formatted URIs in use.
>
> Bill
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>