Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring, Jersey and Viewable JSP Integration

I'm trying to integrate Spring 3.0.5 with Jersey 1.4. I seem to have everything working, but whenever I try and return a Viewable that points to a JSP, I get a 404 error. When I wasn't using spring I could use this filter:

<filter>
    <filter-name>Jersey Filter</filter-name>
    <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
    <init-param>
        <param-name>com.sun.jersey.config.feature.Redirect</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>cheetah.frontend.controllers</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</filter>

And I could return a Viewable to any JSP's, image, css that were stored in the appropriate folder. However, now that I have to use the SpringServlet to get spring integration, I'm at a loss for how to access resources, since I can't use the filter above. I've tried using this servlet mapping with no luck:

<servlet>  
    <servlet-name>jerseyspring</servlet-name> 
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</servlet>  
<servlet-mapping>  
    <servlet-name>jerseyspring</servlet-name>  
    <url-pattern>/*</url-pattern>  
</servlet-mapping>

Does anyone know the proper configurations to achieve this?

Thanks for any help.

like image 722
Brian DiCasa Avatar asked Dec 30 '10 03:12

Brian DiCasa


2 Answers

I discovered that you can use the SpringServlet as a filter:

<filter>
    <filter-name>Jersey Filter</filter-name>
    <filter-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</filter-class>
    <init-param>
        <param-name>com.sun.jersey.config.feature.Redirect</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>Jersey Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Which really should have been obvious to me since I used a Servlet in my original filter!

like image 167
Brian DiCasa Avatar answered Sep 24 '22 06:09

Brian DiCasa


This seems similar to the default Servlet handler recently added to Spring.

I suspect your Viewable resource is being processed by the jerseyspring Servlet rather than a static content handling Servlet (the "default" Servlet discussed in the above link).

What happens if you change your configuration to use <url-pattern>/</url-pattern>?

like image 35
earldouglas Avatar answered Sep 25 '22 06:09

earldouglas