joost1024
joost1024

Reputation: 105

Google App Engine + Jersey + JSP results in NOT_FOUND

Currently I'm working on my first Google App Engine application. I use a combination of Jersey (JAX-RS) and JSP 2.0 with custom tags to separate the lay-out from the application logic.

The application that I created runs perfectly fine in the local sandbox (started using Maven appengine:devserver), but when I run the exact same code at Google I get an "Error: NOT_FOUND" error for the same call. The log at GAE says:

2013-04-12 12:37:38.520 /rest/home 404 ...
2013-04-12 12:37:34.034
  com.sun.jersey.api.core.PackagesResourceConfig init: Scanning for root resource and provider classes in the packages:
    xxx.rest
2013-04-12 12:37:34.308
  com.sun.jersey.api.core.ScanningResourceConfig logClasses: Root resource classes found:
    class xxx.rest.HomeResource
2013-04-12 12:37:34.308
  com.sun.jersey.api.core.ScanningResourceConfig init: No provider classes found.
2013-04-12 12:37:34.619
  com.sun.jersey.server.impl.application.WebApplicationImpl _initiate: Initiating Jersey application, version 'Jersey: 1.17.1 02/28/2013 12:47 PM'
2013-04-12 12:37:38.422
  xxx.rest.HomeResource <init>: HomeResource constructor
2013-04-12 12:37:38.427
  xxx.rest.HomeResource displayHomepage: Display home

The last two lines show that the HomeResource is there and that it is called. It looks like this:

@Path("/home")
public class HomeResource {

    private Log log = LogFactory.getLog(HomeResource.class);

    public HomeResource() {
        log.info("HomeResource constructor");
    }

    @GET
    @Produces(MediaType.TEXT_HTML)
    public Response displayHomepage() {
        log.info("Display home");
        return Response.ok(new Viewable("/home")).build();
        //return new Viewable("/home");
    }

}

The JSP files are located in WEB-INF/views and the custom tags in WEB-INF/tags as specified in the web.xml:

<servlet>
    <servlet-name>Test</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>xxx.rest</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
        <param-value>/WEB-INF/views/</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(img|js|css|(WEB-INF/tags)|(WEB-INF/views))/.*</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Test</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

The location of the tags is specified in the JSP as:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

This should be correct since the JSP gets compiled without a problem.

Can you please point me in any direction that helps me solve this problem? Thanks a lot in advance!

EDIT: It appears to have something to do with the location of the JSP template. When I replace the Viewable with a static String all works as expected. How are the JSPs in WEB-INF/views referenced?

Upvotes: 0

Views: 819

Answers (1)

joost1024
joost1024

Reputation: 105

I finally cracked it... It had indeed to do with the path in the Viewable. I changed it to:

@Path("/hello")
public class HelloResource {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public Response displayHello() {
        return Response.ok(new Viewable("/views/hello")).build();
    }

}

Furthermore I moved the views folder containing the JSPs to the parent of WEB-INF and removed some lines from the web.xml:

<servlet>
    <servlet-name>Test</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>xxx.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Test</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

And now it works like a charm!

Upvotes: 2

Related Questions