users@jersey.java.net

Re: [Jersey] Getting context root from rest service

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 08 Jun 2010 13:31:37 +0200

Hi,

You can get the base URI for the Jersey servlet:

   http://localhost:8080/aif-filebrowser-service/rest/

from UriInfo:

   https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/UriInfo.html
#getBaseUri%28%29

I am presuming that you have "rest/*" as the servlet URL pattern?

But unfortunately you cannot get the web application base URI. You
will need to construct this yourself:

   HttpServletRequest hsr = ...
   UriInfo ui = ...
   URI appBaseUri =
ui.getBaseBuilder().replacePath(hsr.getContextPath())

Paul.

On Jun 8, 2010, at 12:54 PM, vineetkr211 wrote:

>
> Hi,
>
> How can I retrieve context root of my application? For e.g., If the
> url for
> my service is
> "http://localhost:8080/aif-filebrowser-service/rest/
> GetFilesFromHome". I
> would like to get "http://localhost:8080/aif-filebrowser-service/",
> which
> points to my application root. How can i get this in my Rest service
> class?
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Getting-context-root-from-rest-service-tp5153138p5153138.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>