Hi,
I'm trying to use a RequestDispatcher and a
(Sling)HttpServletResponseWrapper in a servlet component to capture
output from another components. My current attempt is:
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final ServletOutputStream stream = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
buffer.write(b);
}
};
final PrintWriter writer = new PrintWriter(stream);
HttpServletResponseWrapper wrapper =
new HttpServletResponseWrapper(response) {
@Override
public ServletOutputStream getOutputStream() {
return stream;
}
@Override
public PrintWriter getWriter() throws IOException {
return writer;
}
};
RequestDispatcher dispatcher = request.getRequestDispatcher(path);
dispatcher.include(request, wrapper);
I traced the code to figure out that the RequestDispatcher correctly
finds the target resource I've identified, but then in
RequestData.service (called by SlingComponentFilterChain.render) the
call requestData.getContentData().getServlet() gives the original
servlet (where I'm trying to do the capture) instead of the component
associated with the target resource.
What am I doing wrong?
BR,
Jukka Zitting