users@glassfish.java.net

Forwarding to JSF from JAX-RS

From: <forums_at_java.net>
Date: Sun, 10 Apr 2011 16:25:32 -0500 (CDT)

Trying to get JSF and JAX-RS to play nicely together, but running into a
snag.  I'm trying to combine the URI control of JAX-RS with the templating
capabilities and CDI integration of JSF.  On Glassfish, the following works:


@GET @Produces("text/html") public Response showTemplate (@Context
ServletContext context, @Context ThreadLocal<HttpServletRequest> request,
@Context ThreadLocal<HttpServletResponse> response) { try {
context.getRequestDispatcher("index.jsf").forward(request.get(),
response.get()); } catch (ServletException ex) { ex.printStackTrace(); return
Response.status(NOT_FOUND).build(); } catch (IOException ex) {
ex.printStackTrace(); return Response.status(NOT_FOUND).build(); } return
null; }
 

On JBoss, it doesn't work if the method signature returns a JAX-RS Response
object -- or any object type for that matter.  In addition, whereas
Glassfish requires a ThreadLocal instance of HttpServletRequest, JBoss
requires a bare HttpServletRequest reference for injection.


@GET @Produces("text/html") public void showTemplate (@Context ServletContext
context, @Context HttpServletRequest request, @Context HttpServletResponse
response) { try { context.getRequestDispatcher("index.jsf").forward(request,
response); } catch (ServletException se) { ex.printStackTrace(); } catch
(IOException ioe) { ex.printStackTrace(); } }
 

My main target is Glassfish, but I was aiming for a solution whose only
dependencies include a JEE6 server, not specifically Jersey or Glassfish or
RESTEasy or JBoss or Weld.

 

My question is this: is the Glassfish behavior the designated standard
behavior with JBoss having an implementation bug, is Glassfish needing work
with JBoss acting correctly, or is the behavior undefined in this case with
no standard way of doing what I propose?

 


--
[Message sent by forum member 'mileselam']
View Post: http://forums.java.net/node/790563