Quantcast

need some guidance on @ApplicationPath and url-pattern in web.xml

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

need some guidance on @ApplicationPath and url-pattern in web.xml

Jim the Standing Bear
Hello,

I need some help on sorting out @ApplicationPath and <url-pattern> in web.xml

I have been working on a jersey application.  Initially, I set
@ApplicationPath("/")  and I override the getClasses() method in the
application to tell it what resources are available.   I also have a
web.xml, and in it, I define

<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
...
<servlet-mapping>
   <servlet-name>jersey-servlet</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>
...

the package is named mywar.war, and I was able to access it using the
following URL without any problems

http://localhost:8080/mywar/resource1


But now, we are adding a servlet filter to this RESTful application,
and another RESTful application to the same tomcat container, so I am
trying to distinguish the two application by not using just "/" and
"/*", and instead, trying to give them more specific path segments
such as @ApplicationPath("/mine")  and
<url-pattern>/mine</url-pattern>.  But as soon as I did that, I am not
able to figure out the correct URL to access my RESTful application
any more.

I thought it would be http://localhost:8080/mine/mywar/resource1  but
it gave me 404.

I even tried to omit @ApplicationPath, but to no avail.

So what would be the correct configuration for my application in terms
of ApplicationPath and <url-pattern> (leave one out? keep both the
same?  I tried all but none seemed to work), and what would the
correct URL be?  Please help!  Thanks.

- S.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: need some guidance on @ApplicationPath and url-pattern in web.xml

Marek Potociar
Since you deploy using the web.xml, the @ApplicationPath annotation gets ignored. You need to fix your servlet mapping to include "/*" in the end, e.g. "<url-pattern>/mine/*</url-pattern>".

Marek

On Apr 3, 2012, at 11:09 PM, Jim the Standing Bear wrote:

> Hello,
>
> I need some help on sorting out @ApplicationPath and <url-pattern> in web.xml
>
> I have been working on a jersey application.  Initially, I set
> @ApplicationPath("/")  and I override the getClasses() method in the
> application to tell it what resources are available.   I also have a
> web.xml, and in it, I define
>
> <servlet-name>jersey-servlet</servlet-name>
> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
> ...
> <servlet-mapping>
>   <servlet-name>jersey-servlet</servlet-name>
>  <url-pattern>/*</url-pattern>
> </servlet-mapping>
> ...
>
> the package is named mywar.war, and I was able to access it using the
> following URL without any problems
>
> http://localhost:8080/mywar/resource1
>
>
> But now, we are adding a servlet filter to this RESTful application,
> and another RESTful application to the same tomcat container, so I am
> trying to distinguish the two application by not using just "/" and
> "/*", and instead, trying to give them more specific path segments
> such as @ApplicationPath("/mine")  and
> <url-pattern>/mine</url-pattern>.  But as soon as I did that, I am not
> able to figure out the correct URL to access my RESTful application
> any more.
>
> I thought it would be http://localhost:8080/mine/mywar/resource1  but
> it gave me 404.
>
> I even tried to omit @ApplicationPath, but to no avail.
>
> So what would be the correct configuration for my application in terms
> of ApplicationPath and <url-pattern> (leave one out? keep both the
> same?  I tried all but none seemed to work), and what would the
> correct URL be?  Please help!  Thanks.
>
> - S.

Loading...