users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 15 May 2009 11:38:09 +0200

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
>