users@jersey.java.net

Doh! Re: [Jersey] Trying to include a resource class from jsp

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 15 Dec 2009 14:08:30 +0100

On Dec 15, 2009, at 12:31 PM, Paul Sandoz wrote:

> On Dec 15, 2009, at 12:06 PM, Paul Sandoz wrote:
>>>
>>> OK. I have just played around with your sample and if i do not
>>> register your ExtendedJSPTemplateProcessor and modify Jersey's
>>> RequestDispatcherWrapper such that the include methods is
>>> implemented as follows:
>>>
>>> public void include(ServletRequest req, ServletResponse rsp)
>>> throws ServletException, IOException {
>>> ResolvedViewable rv =
>>> (ResolvedViewable
>>> )hc
>>> .getProperties
>>> ().get("com.sun.jersey.spi.template.ResolvedViewable");
>>>
>>> req.setAttribute("httpContext", hc);
>>> req.setAttribute("resolvingClass", rv.getResolvingClass());
>>> req.setAttribute("it", it);
>>> req.setAttribute("_basePath", basePath);
>>> req.setAttribute("_request", req);
>>> req.setAttribute("_response", rsp);
>>> d.include(req,rsp);
>>> }
>>>
>>
>> Clarification: the above does not actually require any modification
>> because Jersey's JSPTemplateProcessor always calls the forward on
>> the dispatcher. Thus some tweaks to the ServletContainer.filter
>> method may be all that is required.
>>
>
> After debugging, i observed that the
> ExtendedServletContainer.doFilter is never called for includes from
> views. Thus there is something more fundamental going on. Since the
> JSPTemplateProcessor calls forward then perhaps after that it is not
> possible to include using the JSP include tag?
>

Doh! i forgot to include the following statement in the JSP file:

   <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Now everything works as i would expect.

Attached is a modification of your example that uses Jersey's
unmodified JSPTemplateProcessor and RequestDispatcherWrapper.

Paul.




> In any case from what i can tell one does not have to modify
> Viewable to get equivalent behavior for view inclusion as in the
> example you provide. But, to get re-entrant inclusion will require a
> little more head scratching to work out and still may require a
> custom tag.
>
> Paul.
>