0

I have a JAX-RS based web application that I have working correctly. The development environment is Jetty 9, Maven 3.0.4, and JBoss RESTeasy.

I have a method in a public class resource /login (reachable at http://somedomain/login, tested, working correctly) that looks like this (see this SO post):

@Path("/login")
public class LoginResource {

@GET
@Path ("/silly")
@Produces ("text/html")
public void sillier (@Context HttpServletRequest request, @Context HttpServletResponse response) throws ServletException, IOException
{
request.getRequestDispatcher ("/Project/hello.jsp").forward (request, response);
}
}

The file /Project/hello.jsp is loadable on a browser (at http://somedomain/Project/hello.jsp) when not called by the method sillier above, and the contents of hello.jsp are as follows.

<HTML><BODY> Hello! The time is now <%= new java.util.Date() %> </BODY></HTML>

This code does what you would expect--print out the current time in the browser.

When I call http://somedomain/login/silly, though, I see the following issue:

Unable to find contextual data of type: javax.servlet.http.HttpServletRequest

What am I missing? Is this some configuration in pom.xml and/or web.xml I am missing?

My web.xml is below:

Archetype Created Web Application

<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.sonny.project.web.App</param-value>
    </init-param>
</servlet>

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

Community
  • 1
  • 1
Sonny
  • 2,103
  • 1
  • 26
  • 34
  • For one, you can't forward across contexts. If you had URLs `http://somedomain/Project/hello.jsp` and `http://somedomain/Project/login/silly` with the forward using `request.getRequestDispatcher ("hello.jsp").forward (request, response);` it might work. Or you might need `"../../hello.jsp"` That might be the whole issue. – developerwjk Apr 09 '14 at 23:50
  • Or this might help: https://issues.jboss.org/browse/RESTEASY-903 – developerwjk Apr 09 '14 at 23:55
  • The URLs are `http://somedomain/Project/hello.jsp` and `http://somedomain/login/silly`. I put the web appilcation in the root directory as `root.war` so I can access the resources in the root context `http://somedomain/`. However, the static pages for the project are in `http://somedomain/Project` and other static pages are accessible from the `http://somedomain` context so I do not believe that is the issue, unless I am missing something again. Thanks for your energy and time with this. – Sonny Apr 09 '14 at 23:56
  • I saw that bug page earlier. Why isn't anyone else landing on this bug? Is there a better production quality framework to accomplish what I am trying to do? – Sonny Apr 09 '14 at 23:57

0 Answers0