final RequestDispatcher dispatcher = request.getRequestDispatcher(location);
if (dispatcher != null) {
// Wrap request
final ServletRequest servletRequest = getWrappedServletRequest(request, location);
// Wrap response
final ServletResponse servletResponse = new RedirectedStreamServletResponseWrapper(os, response);
LOG.debug("dispatching request to location: {}", location);
// use dispatcher
dispatcher.include(servletRequest, servletResponse);
warnOnEmptyStream = true;
// force flushing - the content will be written to BytArrayOutputStream.
// Otherwise exactly 32K of data will be written.
servletResponse.getWriter().flush();
os.close();
}
} catch (final Exception e) {
LOG.debug("Could not dispatch request for location {}", location);
// Not only servletException can be thrown, also dispatch.include can throw NPE when the scheduler runs outside