users@jersey.java.net

Viewable is not able to resolve jsp path when integrated with Guice

From: Dinesh Narayanan <ndchandar_at_gmail.com>
Date: Mon, 12 Oct 2009 02:15:56 -0700

Hello,

When I integrate Guice with JAX-RS, Viewable is not able to resolve my jsp
path. I get a 404 error (Problem accessing
/MiniMyBrocadeWeb/myAccount/helloWorld.jsp.)


I did my integration based on the following email thread (
http://n2.nabble.com/WebPageContentRegex-and-Guice-integration-td3615214.html
)


Example:

-------------

*A) My HelloWorldResource:*


@Path("/helloworld")

@RequestScoped

public class HelloWorldResource {

    private static final Logger logger =
Logger.getLogger(HelloWorldResource.class);


    @Context

    private UriInfo uriInfo;


    private String name;

    private int no;


    public String getName() {

        return name;

    }


    public void setName(String name) {

        this.name = name;

    }


    public int getNo() {

        return no;

    }


    public void setNo(int no) {

        this.no = no;

    }


@GET

    @Produces("text/html")

    public Viewable get() {

        logger.info("inside HelloWorldResource get()");

        logger.info("uri info "+uriInfo);

        logger.info("abs path "+uriInfo.getAbsolutePath());

        logger.info("baseUri "+uriInfo.getBaseUri());

        logger.info("getPath "+uriInfo.getPath());


        this.name = "Dinesh";

        this.no = 007;


        return new Viewable("/myAccount/helloWorld.jsp", this);


    }

}


*B) MyGuiceServletConfig:*

*
*

public class MyGuiceServletConfig extends GuiceServletContextListener {


    private static final Logger logger =
Logger.getLogger(MyGuiceServletConfig.class);


    @Override

    protected Injector getInjector() {


        final ServletModule servletModule = new ServletModule() {

            @Override

            protected void configureServlets() {

                logger.info("inside configureServlets method");


                //bind resources

                bind(HelloWorldResource.class);


                // this serves the static content

//
serveRegex("/(dojo|dijit|dojox|util|js)/.*").with(DefaultWrapperServlet.class);


                Map<String, String> params = new HashMap<String, String>();

                params.put("com.sun.jersey.config.feature.Redirect",
"true");


params.put("com.sun.jersey.config.feature.ImplicitViewables", "true");

                params.put("com.sun.jersey.config.property.packages",


"com.brocade.webportal.common;com.brocade.webportal.myAccount.resource;com.brocade.webportal.myHome.resource");


//
params.put("com.sun.jersey.config.property.WebPageContentRegex",
"/(dojo|dijit|dojox|util|js)/.*");


                serve("/*").with(GuiceContainer.class, params);

            }

        };


        return Guice.createInjector(servletModule);

    }


}


*C) web.xml*

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

         id="WebApp_ID" version="2.5">


    <display-name>MyBrocade</display-name>


    <listener>


<listener-class>com.brocade.webportal.config.MyGuiceServletConfig</listener-class>

    </listener>


    <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>/*</url-pattern>

    </filter-mapping>



</web-app>


The logs indicate the following error

*ERROR: PWC6117: File
"/Users/ndchandar/IdeaProjects/GuicyMyBrocade/MiniMyBrocadeWeb/src/main/webapp/helloworld"
not found*

*
*

What was I missing here?


Thanks

Dinesh