RequestDispatcher, wrapper, and file upload - ANSWER

2008-03-08 Thread John O'Hanley
Found the answer to my question.

The call to request.getRequestDispathcher(String aPath) works as it should. 
However, this method represents a kind of 'back door', through which query 
params may be added. 

Since my wrappER doesn't override this method, it does a call forward to the 
'wrappEE'. The wrappEE sees the query params, and saves them, but this info is 
not made automatically visible to the wrappER. **The wrappER needs to do extra 
work to ensure that such 'extra' query params are also made visible to it.**

Roughly, the wrapper should be something like this :

@Override public String getParameter(String aName){
  //first try wrapper's internal version of the parameter map
  //if not found, try super.getParameter(String), and see if it has any data 
for aName
}

That way, when the JSP uses the wrappER, it will see the extra query params in 
the usual way.

I have altered the code to reflect the above style, and it now works.

Regards,
John

RequestDispatcher, wrapper, and file upload

2008-03-07 Thread John O'Hanley
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'Hanleyweb-app 
  xmlns=http://java.sun.com/xml/ns/j2ee; 
  xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
  xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd;
  version=2.4


  display-nameTest/display-name
  descriptionTest/description
  
  filter
   filter-nameTestFilter/filter-name
   display-nameTestFilter/display-name
   filter-classhirondelle.fish.exercise.fileupload.TestFilter/filter-class
 /filter
 
  filter-mapping
   filter-nameTestFilter/filter-name
   servlet-nameTestController/servlet-name
  /filter-mapping
  
  !-- Required by file upload tool. --
  listener
listener-classorg.apache.commons.fileupload.servlet.FileCleanerCleanup/listener-class
  /listener 

  servlet
servlet-nameTestController/servlet-name
servlet-classhirondelle.fish.exercise.fileupload.TestController/servlet-class
  /servlet
  

  servlet-mapping
servlet-nameTestController/servlet-name
url-pattern*.test/url-pattern
  /servlet-mapping
  
  session-config
session-timeout15/session-timeout
  /session-config
  

  
  taglib
   taglib-urihttp://java.sun.com/jsp/jstl/core/taglib-uri
   taglib-location/WEB-INF/tlds/c.tld/taglib-location
  /taglib
  
  taglib
   taglib-urihttp://java.sun.com/jsp/jstl/fmt/taglib-uri
   taglib-location/WEB-INF/tlds/fmt.tld/taglib-location
  /taglib

  taglib
   taglib-urihttp://java.sun.com/jsp/jstl/functions/taglib-uri
   taglib-location/WEB-INF/tlds/fn.tld/taglib-location
  /taglib
  
  
/web-app

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

RequestDispatcher, wrapper, and file upload

2008-03-07 Thread John O'Hanley
[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