views:

130

answers:

1

I am trying to dispatch in a servlet request handler to the JSP processor and capture the content of it.

I am providing wrapper instances for the ServletRequest and ServletResponse, they implement the corresponding HTTPServletRequest/-Response interfaces, so they should be drop-in replacements. All methods are currently passed to the original Servlet Request object (I am planning to modify some of them soon). Additionally I have introduced some new methods. (If you want to see the code: http://code.google.com/p/gloudy/source/browse/trunk/gloudyPortal/src/java/org/gloudy/gloudlet/impl/RenderResponseImpl.java)

The HttpServletResponse uses its own output streams to capture the output.

When I try to call

request.getRequestDispatcher("/WEB-INF/views/test.jsp").include(request, response);    

With my request and response wrappers the method returns and no content has been captured. When I tried to pass the original request object it worked! But that's not what I need in the long run...

request.getRequestDispatcher("/WEB-INF/views/test.jsp").include(request.getServletRequest(), response);

This works. getservletRequest() returns the original Request, given by the servlet container.

Does anyone know why this is not working with my wrappers?

Update: I am trying this on the google app engine dev environment, which uses the geronimo implementation for the servlet container IIRC

+1  A: 

OK, found the problem...

I have replaced the attribute related functions with my own implementation. That was the reason that the jsp processor returned empty results (without any error message...)

So it's a bad idea to do this in your ServletRequest Wrappers if you want to use Request Dispatcher:

 private Map<String, Object> attributes = new HashMap<String, Object>();
 ...

 public Object getAttribute(String string) {
    return attributes.get(this);
  }

  public Enumeration<String> getAttributeNames() {
    return (Enumeration<String>) attributes.keySet();
  }

  public void setAttribute(String string, Object o) {
    attributes.put(string, o);
  }

  public void removeAttribute(String string) {
    attributes.remove(string);
  }

It works without these lines. Maybe this helps someone who tries similar things...

Patrick Cornelissen
They will work if you call `super.methodname(whateverargs)` as well.
BalusC
I've tried that without success :-(
Patrick Cornelissen