protected final String getDynamicQuery(String queryResource,
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// get the dispatcher
RequestDispatcher dispatcher = getServletContext()
.getRequestDispatcher(queryResource);
if (dispatcher == null) {
throw new ServletException(
"Cannot get a RequestDispatcher for path: " + queryResource);
}
// set some useful information in the request
request.setAttribute("path", ServletParameterUtils
.getPathElements(request));
// wrap the request in order to supply extra functionality (multiparm
// form handling)
CustomHttpServletRequestWrapper requestWrapper = new CustomHttpServletRequestWrapper(
request, this.multipartSizeThreshold, this.multipartMaxSize,
this.multipartRepositoryPath);
// wrap our response, so we can capture the body (and the included
// resource cannot mess with it)
CustomHttpServletResponseWrapper responseWrapper = new CustomHttpServletResponseWrapper(
response);
// include the resource
dispatcher.include(requestWrapper, responseWrapper);
// and get the body
String sql = responseWrapper.getBody();
if (sql == null) {