I was able to do it using "uriInfo.getPathSegments().get(0).getPath();"
Regards,
.
Rahul
On Thu, Dec 9, 2010 at 4:53 PM, Rahul Babbar <rahul.babbar1_at_gmail.com>wrote:
> Hi,
>
> I was able to get around this problem by defining a BaseRESTServlet and all
> my servlets extend from it and defining the method in the BaseRESTServlet
> with the @Path("/{id}/descriptor").
> That solves this problem for me.
> However i was wondering how do i get the value of the path before the
> "{id}/descriptor".
>
> Here's the details.
> FooRESTServlet has @Path("/foo")
> BarRESTServlet has @Path("/bar")
>
> Both extend BaseRESTServlet which has a method defined as
>
> @GET
> @Path("/{id}/descriptor")
> public String getDescriptor(@PathParam("id") long id) {
> logger.info("descriptor(): " + id);
> return StringUtils.EMPTY;
> }
>
> Now, both uri pattern /foo/1/descriptor and /bar/1/descriptor will come to
> this method. and i will get the value of 1 as Id in both cases.
>
> But i also want to get of "foo" or "bar", (because this method is defined
> in the base class).
>
> I could parse the URL and find out, but i am hoping there is a better way.
>
> Regards,
>
> Rahul
>
> Rahul
>
>
> On Thu, Dec 9, 2010 at 4:22 PM, Rahul Babbar <rahul.babbar1_at_gmail.com>wrote:
>
>> Hi All,
>>
>> I have this following requirement.
>>
>> rest/foo;A=B should go to a fooServlet.
>> rest/<Anything>/<Anything>/descriptor should go to DescriptorServlet(which
>> may be a normal Servlet handled without Jersey)
>>
>> In my web.xml, i have given,
>>
>> <servlet>
>> <servlet-name>Jersey</servlet-name>
>>
>> <servlet-class>org.*.*.*.configuration.JerseyServletContainer</servlet-class>
>> ........init-params...............
>> </servlet>
>> <servlet>
>> <servlet-name>DescriptorServlet</servlet-name>
>> <servlet-class>org.*.*.*.DescriptorRESTService</servlet-class>
>> </servlet>
>>
>> <servlet-mapping>
>> <servlet-name>Jersey</servlet-name>
>> <url-pattern>/rest/*</url-pattern>
>> </servlet-mapping>
>> <servlet-mapping>
>> <servlet-name>DescriptorServlet</servlet-name>
>> <url-pattern>/rest/*/*/descriptor</url-pattern>
>> </servlet-mapping>
>>
>> However, a URL like /rest/foo/1/descriptor still goes into the fooServlet
>> and not the DescriptorServlet giving a 404 error.
>>
>> Does the servlet named "Jersey" intercepts all the calls to "/rest/*" even
>> though a more specific servlet is defined to handle "/rest/*/*/descriptor".
>>
>> Or am i doing something wrong?
>>
>> Thank you
>>
>> Rahul
>>
>
>