users@jersey.java.net

Re: [Jersey] web.xml url-pattern and _at_PathParam

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Sat, 16 May 2009 09:51:17 +0200

On May 15, 2009, at 10:31 PM, Ronak Patel wrote:

> Paul,
>
> Thanks for your continued help!
>
> Yes, I have a filter and a servlet defined in the same web.xml both
> for Spring.
>
> I've attached my web.xml as requested.
>

OK. That is your problem. You should only declare the use of Jersey
just once either as a filter or a servlet, but not both.

Thus you should remove the servlet declaration and mapping. Jersey
declared as a filter will consume the request if the regex does not
match.

Paul.


> Ronak
>
> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
> To: users_at_jersey.dev.java.net
> Sent: Friday, May 15, 2009 12:28:39 PM
> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>
> Hi,
>
> I think i may know what the problem is, i am wondering if it is
> because there are filters and servlets defined in the same web.xml.
> Are you declaring a filter and a servlet using the Jersey Spring
> servlet container?
>
> But i need to look at your web.xml again, and the previous one you
> included was not formatted and appeared to be truncated, can you
> send it again, perhaps as an attachment?
>
> Paul.
>
>
> On May 15, 2009, at 6:27 PM, Ronak Patel wrote:
>
>> I noticed yahoo didn't encode my email properly so I am resending.
>>
>> Paul,
>>
>> I checked it out while remotely debugging my Tomcat 6.0-18 servlet
>> container hosting my JAX-RS RI 1.0.3 application
>>
>> Inside of the ServletContainer.java file around line 715 the
>> doFilter method has the following code:
>>
>> String servletPath = request.getServletPath();
>> // if we match the static content regular expression lets delegate
>> to the filter chain// to use the default container servlets &
>> handlers
>> Pattern p = getStaticContentPattern();
>> chain.doFilter(request, response);
>> }
>>
>> When I look at Eclipse's variables section, the servletPath
>> variable is set to "" (Empty String) and when I look at p it has
>> /(images|css|jsp)/.*
>>
>> The URL I am hitting to hit the jsp is:
>>
>> http://localhost:8080/resort.info-1.0/jsp/login-redirect.jsp
>>
>> where resort.info-1.0 is the application/context name inside of
>> Tomcat 6.0.
>>
>> Ronak
>>
>>
>>
>>
>>
>> ----- Original Message ----
>> From: Ronak Patel <ronak2121_at_yahoo.com>
>> To: users_at_jersey.dev.java.net
>> Sent: Friday, May 15, 2009 9:17:45 AM
>> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>>
>> Paul,
>>
>> I checked it out while remotely debugging my Tomcat 6.0-18 servlet
>> container hosting my JAX-RS RI 1.0.3 application
>>
>> Inside of the ServletContainer.java file around line 715 the
>> doFilter method has the following code:
>> String servletPath = request.getServletPath();
>> // if we match the static content regular expression lets delegate
>> to the filter chain// to use the default container servlets &
>> handlersPattern p = getStaticContentPattern();
>> chain.doFilter(request, response);
>> }
>> When I look at Eclipse's variables section, the servletPath
>> variable is set to "" (Empty String) and when I look at p it has
>>
>> The URL I am hitting to hit the jsp is:
>>
>> http://localhost:8080/resort.info-1.0/jsp/login-redirect.jsp
>>
>> where resort.info-1.0 is the application/context name inside of
>> Tomcat 6.0.
>>
>> Ronak
>>
>>
>>
>> ----- Original Message ----
>> From: Ronak Patel <ronak2121_at_yahoo.com>
>> To: users_at_jersey.dev.java.net
>> Sent: Friday, May 15, 2009 8:36:18 AM
>> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>>
>>
>> I'm trying to remotely debug my tomcat to find out what the filter
>> is doing.
>>
>> When I comment out the <servlet> section, I see that the default
>> servlet takes over in serving the jsp file. This tells me that
>> either the filter isn't loading, or it doesn't like my regular
>> expression, or something else...will let you know what I find.
>>
>>
>>
>> ----- Original Message ----
>> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>> To: users_at_jersey.dev.java.net
>> Sent: Friday, May 15, 2009 7:48:27 AM
>> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>>
>>
>> On May 15, 2009, at 3:36 PM, Ronak Patel wrote:
>>
>> >
>> > Paul,
>> >
>> > What does your directory structure look like?
>>
>>
>> Like that of the bookstore sample i previously sent a link to.
>>
>>
>> > That change on my side still doesn't make any difference.
>> > I commented out all of the J2EE security components from my
>> web.xml as well to see if that helps solve the problem.
>> >
>> > I'm wondering if the filter is matching a directory structure
>> that i don't have.
>> >
>>
>> It could be, the URL path at the end should be "jsp/file.jsp"
>>
>>
>> > I have a jsp and WEB-INF folder at the same level in the
>> directory structure.
>> >
>>
>> The directory structure looks fine for explicitly accessing the
>> "file.jsp".
>>
>> To further help you i would need a maven or NB project so i can
>> reproduce your problem.
>>
>> Paul.
>>
>> > My jsp page resides directly under the jsp folder.
>> >
>> > webapps
>> > |
>> > jsp
>> > |
>> > file.jsp
>> > WEB-INF
>> > |
>> > web.xml
>> >
>> >
>> >
>> > ----- Original Message ----
>> > From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>> > To: users_at_jersey.dev.java.net
>> > Sent: Friday, May 15, 2009 2:38:09 AM
>> > Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>> >
>> > Hi,
>> >
>> > The init parameter needs to be as follows:
>> >
>> > <init-param>
>> > <param-
>> name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
>> > <param-value>/(jsp)/.*</param-value>
>> > </init-param>
>> >
>> > You have:
>> >
>> > <init-param>
>> > <param-name>com</param-name>
>> > <param-value>/(jsp)/.*</param-value>
>> > </init-param>
>> >
>> > i.e. the param name is incorrect.
>> >
>> > Note that i double checked it works correctly by modifying the
>> Spring annotations sample to use a filter.
>> >
>> > Paul.
>> >
>> > On May 15, 2009, at 7:58 AM, Ronak Patel wrote:
>> >
>> >>
>> >> I tested this and the filter works fine if I don't have the
>> Spring Servlet defined in my web.xml. I am using JAX-RS version
>> 1.0.3 now.
>> >>
>> >> My web.xml is as follows:
>> >>
>> >> <?
>> >> <xmlversion="1.0"encoding="UTF-8"?>web-appversion="2.5"xmlns="http://java.sun.com/xml/ns/javaee
>> "xmlns:xml="http://www.w3.org/XML/1998/namespace"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
>> "xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
>> "><!-- Activate Spring on Context Load --><listener><listener-
>> class>org</listener-class></listener><context-param><param-
>> name>contextConfigLocation</param-name><param-value>classpath:META-
>> INF/sno-servlet.xml</param-value></context-param><!--
>> >> JAX-RS Filter to transfer all static content to the default
>> servlet
>> >> --><filter><filter-name>ContentFilter</filter-name><filter-
>> class>com</filter-class><init-param><param-name>com</param-
>> name><param-value>true</param-value></init-param><init-param><param-
>> name>com</param-name><param-value>true</param-value></init-
>> param><init-param><param-name>com</param-name><param-value>/
>> (jsp)/.*</param-value></init-param></filter><filter-mapping><filter-
>> name>ContentFilter</filter-name><url-pattern>/*</url-pattern></
>> filter-mapping><!-- Delegate to the JAX-RS Spring Servlet --
>> ><servlet><display-name>sno</display-name><servlet-name>sno</
>> servlet-name><servlet-
>> class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
>> servlet-class><load-on-startup>1</load-on-startup></
>> servlet><servlet-mapping><servlet-name>sno</servlet-name><url-
>> pattern>/*</url-pattern></</servlet-mapping>web-app>
>> >>
>> >> ----- Original Message ----
>> >> From: Ronak Patel <ronak2121_at_yahoo.com>
>> >> To: users_at_jersey.dev.java.net
>> >> Sent: Thursday, May 14, 2009 6:57:59 AM
>> >> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>> >>
>> >> Paul,
>> >>
>> >> I am duplicating what I see in the bookstore sample.
>> >>
>> >> I have this filter set up:
>> >> <filter><filter-name>ContentFilter</filter-name><filter-
>> class>com</filter-class><init-param><param-name>com</param-
>> name><param-value>true</param-value></init-param><init-param><param-
>> name>com</param-name><param-value>true</param-value></init-
>> param><init-param><param-name>com</param-name><param-value>/
>> (jsp)/.*</param-value></init-param></filter><filter-mapping><filter-
>> name>ContentFilter</filter-name><url-pattern>/*</url-pattern>My
>> folder structure is
>> >>
>> >> src
>> >> |
>> >> main
>> >> |
>> >> webapp
>> >> |
>> >> jsp
>> >> login.jsp
>> >> WEB-INF
>> >> |
>> >> web.xml
>> >>
>> >> However, this still doesn't work. I'm assuming I'm missing
>> something....
>> >>
>> >>
>> >>
>> >> ----- Original Message ----
>> >> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>> >> To: users_at_jersey.dev.java.net
>> >> Sent: Thursday, May 14, 2009 1:08:34 AM
>> >> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>> >>
>> >> On 05/13/09 11:19 PM, Ronak Patel wrote:
>> >>> Paul,
>> >>>
>> >>> This web form allows me to integrate my JAX-RS Jersey
>> application with our internal SSO solution.
>> >>>
>> >>> I am also using Spring so I have the JAX-RS Spring servlet
>> declared in my servlet mappings with /* as the url-pattern as you
>> said.
>> >>>
>> >>> This kind of url pattern prevents the login jsp from being
>> mapped properly. Has anyone ever done this before? This is a common
>> occurance in any enterprise.
>> >>>
>> >>
>> >> Use the Jersey servlet (Spring-based one) as a filter and set
>> the regex
>> >> to match the pattern for what the login path would be, as
>> described
>> >> previously.
>> >>
>> >> If you still have problems could you zip up a simple project and
>> i can
>> >> modify it to make it work.
>> >>
>> >> Paul.
>> >>
>> >>> Ronak
>> >>>
>> >>>
>> >>> ----- Original Message ----
>> >>> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>> >>> To: users_at_jersey.dev.java.net
>> >>> Sent: Wednesday, May 13, 2009 1:20:27 PM
>> >>> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>> >>>
>> >>>
>> >>> On May 13, 2009, at 7:47 PM, Ronak Patel wrote:
>> >>>
>> >>>> Paul,
>> >>>>
>> >>>> Thanks for your reply.
>> >>>>
>> >>>> My JSP page is a login page for J2EE security using the <login-
>> config> element rather than a jsp that is part of the business
>> logic of the application.
>> >>>>
>> >>>> How would you handle that? Would it be the same way as this
>> below?
>> >>>>
>> >>>
>> >>> Yes, ensure that the regex matches the path for logging in.
>> >>>
>> >>> Alternatively you can ensure that all your root resource
>> classes have a unique path via the URL pattern declaration.
>> >>>
>> >>> So a single declared pattern of:
>> >>>
>> >>> <url-pattern>/surface/*</url-pattern>
>> >>>
>> >>> would mean that a root resource class say:
>> >>>
>> >>> @Path("abc")
>> >>>
>> >>> would be served by the path:
>> >>>
>> >>> <web-context-path>/surface/abc
>> >>>
>> >>> I am not sure how the login-config works, if it is filter based
>> you might be able to declare it before the Jersey stuff, but i am
>> not sure.
>> >>>
>> >>> Paul.
>> >>>
>> >>>
>> >>>> Ronak
>> >>>>
>> >>>> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
>> >>>> To: users_at_jersey.dev.java.net
>> >>>> Sent: Wednesday, May 13, 2009 8:34:56 AM
>> >>>> Subject: Re: [Jersey] web.xml url-pattern and @PathParam
>> >>>>
>> >>>> Hi Ronak,
>> >>>>
>> >>>> Part of the problem might be the multiple declarations of URL
>> pattern. Why do you have multiple declarations?
>> >>>>
>> >>>> Also, when you list the URLs are they relative URLs to the
>> base say of "/surface/" or "/weather/" ?
>> >>>>
>> >>>> If you want to support JSPs and resource classes from the same
>> base URI then i recommend using the ServletContainer as a filter
>> and declare a regex pattern so that matching paths are not served
>> by Jersey.
>> >>>>
>> >>>> See the bookstore sample [1], specifically the web.xml
>> >>>>
>> >>>> http://fisheye4.atlassian.com/browse/~raw,r=2009/jersey/trunk/
>> jersey/samples/bookstore/src/main/webapp/WEB-INF/web.xml
>> >>>>
>> >>>> notice the init param:
>> >>>>
>> >>>> <init-param>
>> >>>> <param-
>> name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
>> >>>> <param-value>/(images|css|jsp)/.*</param-value>
>> >>>> </init-param>
>> >>>>
>> >>>> that declares a regex to match against the request URL path.
>> If the regex matches then Jersey will pass the request on to the
>> next filter in the chain:
>> >>>>
>> >>>> https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/spi/container/servlet/ServletContainer.html
>> #PROPERTY_WEB_PAGE_CONTENT_REGEX
>> >>>>
>> >>>> In the bookstore sample the regex matches directions that
>> contain images, CSS files, and JSP files.
>> >>>>
>> >>>> Paul.
>> >>>>
>> >>>> On May 13, 2009, at 12:03 PM, Ronak Patel wrote:
>> >>>>
>> >>>>> Hi All,
>> >>>>>
>> >>>>> I'm using Jersey 1.0.3 and came across a weird problem.
>> >>>>>
>> >>>>> My web application is a mixture of a JSP page and the main
>> REST web application.
>> >>>>>
>> >>>>> To accomodate both in the same web.xml, my web.xml structure
>> for my REST web application is as follows:
>> >>>>>
>> >>>>> <servlet><display-name>sno</display-name><servlet-name>sno</
>> servlet-name><servlet-class>com</servlet-class><load-on-startup>1</
>> load-on-startup></servlet><servlet-mapping><servlet-name>sno</
>> servlet-name><url-pattern>/forecast/*</url-pattern>
>> >>>>> <url-pattern>/surface/*</url-pattern>
>> >>>>> <url-pattern>/weather/*</url-pattern>
>> >>>>>
>> >>>>> Code as follows always results in an HTTP 404:
>> >>>>> @Controller_at_Path("/nation/
>> {nationId}/")publicclassNationController
>> {_at_GET@Produces("application/xml")publicResponse
>> getNationByNationId( {_at_PathParam("nationId") finalLong nationId)}
>> >>>>> }
>> >>>>>
>> >>>>> All of the following URLs fail:
>> >>>>>
>> >>>>> /nation
>> >>>>> /nation/
>> >>>>> /nation/1
>> >>>>> /nation/1/
>> >>>>>
>> >>>>> I would assume all 4 of these URIs would work. Why doesn't
>> Jersey match these uri properly?
>> >>>>>
>> >>>>> Ronak <url-pattern>/region/*</url-pattern></servlet-
>> mapping>.sun.jersey.spi.spring.container.servlet.SpringServlet
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>>
>> ---------------------------------------------------------------------
>> >>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> >>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >>>>>
>> >>>>
>> >>>>
>> >>>
>> >>>
>> >>>
>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> >>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> >>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >>>
>> >>
>> >>
>> >>
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> >> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >>
>> >> </filter-
>> mapping
>> >
>> .sun
>> .jersey
>> .config
>> .property
>> .WebPageContentRegex
>> .sun
>> .jersey
>> .config
>> .feature
>> .ImplicitViewables
>> .sun
>> .jersey
>> .config
>> .feature
>> .Redirect.sun.jersey.spi.spring.container.servlet.SpringServlet
>> >>
>> >>
>> >>
>> >
>> >
>> .sun
>> .jersey
>> .config
>> .property
>> .WebPageContentRegex
>> .sun
>> .jersey
>> .config
>> .feature
>> .ImplicitViewables
>> .sun
>> .jersey
>> .config
>> .feature
>> .Redirect
>> .sun
>> .jersey.spi.spring.container.servlet.SpringServlet.springframework.web.context.ContextLoaderListener
>> <!-- Delegate to the JAX-RS Spring Servlet -->
>> >>
>> >>
>> >>
>> >>
>> >>
>> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> >> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >>
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >
>> >
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>> /(images|css|jsp)/.*if(p != null&&
>> p.matcher(servletPath).matches()) {return;
>>
>>
>>
>>
>>
>
>
> <
> web
> .xml
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net