users@jersey.java.net

[Jersey] Jersey Guice JSP how to? (take II)

From: eishay <eishay_at_gmail.com>
Date: Tue, 23 Aug 2011 12:18:04 -0700 (PDT)

I've read the previous thread from Jul 25, 2010 at
http://jersey.576304.n2.nabble.com/Jersey-Guice-JSP-how-to-td5349718.html
but it didn't help much.

I'm using tomcat 6, jersey 1.8 with jersey guice and guice 3.
I'm having problem using JSP with my setup.
I have a "Status" servlet served as a simple servlet configured by web.xml,
a jersey servlet configured by GuiceFilter which returns a jsp view response
(jsp is /diff/index.jsp) to render the result as in:
    ....
    Viewable view = new Viewable("/diff/index.jsp", null);
    Response response = Response.ok().entity(view).build();
    return response;
 
It all works perfectly with simple Jersey, once I'm trying to have it with
Guice integration the JSP fails and I'm getting a 404 response with "The
requested resource (/diff/index.jsp) is not available."

Using the debugger I can see that the JSPTemplateProcessor as called and got
a RequestDispatcher with a StandardWrapper that has "isJspServlet = true"
and "jspFile = null".

The web.xml looks like this:
=====================
    <servlet>
        <display-name>Status Page</display-name>
        <servlet-name>Status</servlet-name>
        <servlet-class>my.BaseStatusPage</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Status</servlet-name>
        <url-pattern>/Status/*</url-pattern>
    </servlet-mapping>

   <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/REST/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>my.GuiceServletConfig</listener-class>
    </listener>
=====================
GuiceServletConfig:

public class GuiceServletConfig extends GuiceServletContextListener {

  @Override
  protected Injector getInjector() {
    return Guice.createInjector(new JerseyServletModule() {

      @Override
      protected void configureServlets() {
        bind(DiffPage.class);// the jersey servlet

        Map&lt;String, String&gt; params = new HashMap&lt;String,
String&gt;();
        params.put(PROPERTY_PACKAGES, "my");
        params.put(PROPERTY_WEB_PAGE_CONTENT_REGEX, ".*\\.jsp");
        params.put(FEATURE_REDIRECT, "true");
        params.put(FEATURE_IMPLICIT_VIEWABLES, "true");
        params.put(RESOURCE_CONFIG_CLASS,
"com.sun.jersey.api.core.PackagesResourceConfig");
        
        serve("/REST/*").with(GuiceContainer.class, params);
      }
    });
  }
=====================
Having GuiceContainer as a filter made the servlets served from the web.xml
fail. Adding a jsp servlet in web.xml didn't do much good.

Help appreciated
Thanks, Eishay




--
View this message in context: http://jersey.576304.n2.nabble.com/Jersey-Guice-JSP-how-to-take-II-tp6717412p6717412.html
Sent from the Jersey mailing list archive at Nabble.com.