users@jersey.java.net

Re: [Jersey] JSPTemplateProvider and request object

From: Daniel Larsson <daniel.j.larsson_at_gmail.com>
Date: Tue, 4 Aug 2009 18:06:18 +0200

Hi Paul,
I changed my code to match your updated JSP code (i.e. I'm now also using
ThreadLocal<HttpServletRequest>), and now things are working much better,
thanks!

On Mon, Aug 3, 2009 at 8:32 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> Hi Daniel,
>
> I am not sure if this is release but recently (i cannot remember exactly
> how recently) i modified the Jersey JSPTemplateProvider to have injected
> explicit ThreadLocal wrappers for HttpServletRequest/Response:
>
> public class JSPTemplateProcessor implements TemplateProcessor {
> private @Context HttpContext hc;
>
> private @Context ServletContext servletContext;
>
> private @Context ThreadLocal<HttpServletRequest> requestInvoker;
>
> private @Context ThreadLocal<HttpServletResponse> responseInvoker;
>
> private final String basePath;
>
>
> and the write method is as follows:
>
> public void writeTo(String resolvedPath, Object model, OutputStream out)
> throws IOException {
> // Commit the status and headers to the HttpServletResponse
> out.flush();
>
> RequestDispatcher d =
> servletContext.getRequestDispatcher(resolvedPath);
> if (d == null) {
> throw new ContainerException("No request dispatcher for: " +
> resolvedPath);
> }
>
> d = new RequestDispatcherWrapper(d, basePath, hc, model);
>
> try {
> d.forward(requestInvoker.get(), responseInvoker.get());
> } catch (Exception e) {
> throw new ContainerException(e);
> }
> }
>
>
> When i was developing the JSP integration to took a couple of
> head-scratching moments to realize that the forward method does like to be
> passed thread local proxies of HttpServletRequest/Response.
>
>
> Other than that, i would need to look at your example to help you out more,
> Paul.
>
> On Aug 1, 2009, at 10:03 PM, Daniel Larsson wrote:
>
> Hi,
>>
>> I'm trying to write a custom JSP template provider, and I noticed the
>> standard JSP template provider gets the request in the constructor, and
>> using the injected HttpServletRequest doesn't work very well (in the writeTo
>> method, when dispatching the request to the JSP processor). Using the
>> injected request object, it seems to loop endlessly (?). I haven't had much
>> time yet to delve into what happens, but thought I'd make a quick post here
>> first. I do have a small example project though.
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>