[Resending - attachments not accepted.]
Hello,
I have a nagging problem with a wrapper-filter for file upload requests. The
core of the problem is that
request.getRequestDispatcher(String aPath)
is not behaving as expected. I am passing *query params* in 'aPath'. When I use
a file upload wrapper on the request, these query params are not visible to the
target JSP.
Attached is a minimal harness to demonstrate the problem. It uses a Controller
that traps all '*.test' requests, and does a hard-coded forward to
'test.jsp?x=1', using RequestDispatcher.
The test.jsp displays all request params that it can see. It also does double
duty by POSTing data to the Controller.
When (and only when) the FileUploadWrapper is used, the hard-coded x=1 param is
no longer visible in test.jsp - that is the issue. Am I missing something?
For reference :
The docs for ServletRequestWrapper:
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequestWrapper.html#getRequestDispatcher(java.lang.String)
The wrapper I am using (FileUploadWrapper):
- extends HttpsServletRequestWrapper
- does not override getRequestDispatcher(String)
Hence :
- the default impl in ServletRequestWrapper is used for
getRequestDispatcher(String)
- that impl does a call-forward to the underlying request (right?)
Given that, why does it fail? Is there something different about file upload
requests that makes this fail? Why? It's not that the forward fails entirely -
only that the *params* are not passed along.Using Tomcat 5.5.23 on Win
XP.Thanks in advance,John
O'Hanley---(Sorry if the formatting
is crappy...)CONTROLLER :package hirondelle.fish.exercise.fileupload;import
java.io.IOException;import javax.servlet.*;import javax.servlet.http.*;public
final class TestController extends HttpServlet { @Override protected void
doGet(HttpServletRequest aRequest, HttpServletResponse aResponse) throws
ServletException, IOException { RequestDispatcher dispatcher =
aRequest.getRequestDispatcher(test.jsp?x=1); dispatcher.forward(aRequest,
aResponse); } @Override protected void doPost(HttpServletRequest aRequest,
HttpServletResponse aResponse) throws ServletException, IOException {
RequestDispatcher dispatcher = aRequest.getRequestDispatcher(test.jsp?x=1);
dispatcher.forward(aRequest, aResponse);
}---TEST
FILTER :package hirondelle.fish.exercise.fileupload;import
java.io.IOException;import javax.servlet.*;import
javax.servlet.http.HttpServletRequest;public final class TestFilter implements
Filter {public void init(FilterConfig aConfig) throws ServletException {
}public void destroy() { }public void doFilter(ServletRequest aRequest,
ServletResponse aResponse, FilterChain aChain) throws IOException,
ServletException { //doNothing(aRequest, aResponse, aChain);
useDoNothingWrapper(aRequest, aResponse, aChain);
//useFileUploadWrapper(aRequest, aResponse, aChain);}/** Behaves as expected :
params OK */private void doNothing(ServletRequest aRequest, ServletResponse
aResponse, FilterChain aChain) throws IOException, ServletException {
aChain.doFilter(aRequest, aResponse);}/** * Behaves as expected : params OK.* *
Params seen in destination page :* - form controls : yes* - x=1 : yes*/private
void useDoNothingWrapper(ServletRequest aRequest, ServletResponse aResponse,
FilterChain aChain) throws IOException, ServletException { HttpServletRequest
request = (HttpServletRequest) aRequest; TestWrapper wrapper = new
TestWrapper(request); aChain.doFilter(wrapper, aResponse);}/*** Does not behave
as expected. The 'x=1' param seen in other styles is not seen here.* *
PParams seen in destination page :* - form controls : yes (the form contains
a file upload control)* - x=1 : NO*/private void
useFileUploadWrapper(ServletRequest aRequest, ServletResponse aResponse,
FilterChain aChain) throws IOException, ServletException { HttpServletRequest
request = (HttpServletRequest) aRequest; FileUploadWrapper wrapper = new
FileUploadWrapper(request); aChain.doFilter(wrapper,
aResponse);}}--TEST
WRAPPER :package hirondelle.fish.exercise.fileupload;import
javax.servlet.http.HttpServletRequestWrapper;import
javax.servlet.http.HttpServletRequest;public final class TestWrapper extends
HttpServletRequestWrapper { public TestWrapper(HttpServletRequest aRequest){
super(aRequest);
}}---FILE
UPLOAD WRAPPER:package hirondelle.fish.exercise.fileupload;import
java.util.*;import java.io.*;import java.util.logging.*;import
javax.servlet.http.HttpServletRequestWrapper;import
javax.servlet.http.HttpServletRequest;import
org.apache.commons.fileupload.FileUploadException;import
org.apache.commons.fileupload.servlet.ServletFileUpload;import