users@jersey.java.net

[Jersey] Re: Handling a special URI.

From: Kevin Duffey <andjarnic_at_yahoo.com>
Date: Thu, 2 Dec 2010 14:47:38 -0800 (PST)

There are two ways I would consider given your scenario,

Like Jan said, some sort of rewriter in front of the servlets, like an apache mod or something that you configure to rewrite any URI that matches your custom URI to the new resource URI, so that it redirects to it before the servlet is even reached.

The other way would be in web.xml configure a path for the custom url to a specific servlet and handle it that way, but I am not sure if there is restrictions with that. Because your custom URI is "after" the path(s) you would configure for jersey, I dont know that you could get something like /foo to go to the /foo resource but /foo/custom to ignore the /foo path you've set up and go to another path instead.

Also as I think Jan was saying, you could have your /foo resource have a sub-resource that then forwards or calls to another resource, although I am not completely sure how that is configured in JAX-RS. It's easy enough in a servlet handler to forward to another jsp or servlet, but not sure how you can forward to another resource inside of a resource using code.


--- On Thu, 12/2/10, Rahul Babbar <rahul.babbar1_at_gmail.com> wrote:

From: Rahul Babbar <rahul.babbar1_at_gmail.com>
Subject: [Jersey] Re: Handling a special URI.
To: algermissen1971_at_mac.com, users_at_jersey.java.net
Date: Thursday, December 2, 2010, 1:03 PM

Hi Jan, 
I am trying to avoid writing the piece of code in the resource handling /foo, because it needs to happen for all the resources.
By reverse proxy, do you mean a Filter, which will see the request URL, and if it has the keyword CUSTOM, it will direct it some other servlet.


Thanks, yes, that could be done....
I am trying to look for options to accomplish this and was wondering if Jersey provided any such feature(although i think its too weird a feature to ask for).


Thank you
Rahul 


On Thu, Dec 2, 2010 at 12:39 PM, Jan Algermissen <algermissen1971_at_mac.com> wrote:


Rahul,



On Dec 2, 2010, at 9:30 PM, Rahul Babbar wrote:



> Hello All,

>

> I have a few Jersey resources which handle different URIs.

>

> Lets say i have two resources, handling /foo and /bar.

>

> I have a requirement in which any URI of the form /<anything>/{Id}/{SOME KEYWORD}/{name} should not go to the resource handling foo or bar even though anything is foo or bar.

>

> Eg, lets say, the URI is of the form /foo or /foo/1 or /bar or /bar/1 , it will go to the corresponding resource handling the URI.

>

> However if the URI is of form  /foo/CUSTOM/1 or /bar/CUSTOM/1, i need it to go to a different resource directly.



I think this is problematic with JAX-RS. You could do it by handling /foo/ with one resource and then dispatch to other based on parameters, but that IMHO works against the simplicity of JAX-RS.



Have you considered using a rewriting reverse proxy in front of Jersey?



Jan





>

> Sorry but i know this requirement is a bit weird, but is there a way to accomplish it?

>

> Thank you

>

> Rahul