Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

apache.commons.FileUpload: parseRequest()-Method changes Request-Object?

 
Daniel Haupt
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,

i've got a problem within my struts application. I've added a filter which is triggered before the request is taken to the struts ActionForm.

I've got a multipart/form-data html formular, so I use apache.commons.FileUpload to parse the request and get my specific request parameter by using the parseRequest(HttpServletRequest)-method of ServletFileUpload class.

By doing filter.chain() I continue processing, but now I've got a nullpointer in my ActionForm because there are no more parameters in the HttpServletRequest-Object.

Is parseRequest() changing my object in any way? Are there any alternatives if I just want to get a parameter value (html-input) inside of my filter?

Thanks for your help

Daniel
[ October 20, 2008: Message edited by: Bear Bibeault ]
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Haupt:
Hi folks,

i've got a problem within my struts application. I've added a filter which is triggered before the request is taken to the struts ActionForm.

I've got a multipart/form-data html formular, so I use apache.commons.FileUpload to parse the request and get my specific request parameter by using the parseRequest(HttpServletRequest)-method of ServletFileUpload class.

By doing filter.chain() I continue processing, but now I've got a nullpointer in my ActionForm because there are no more parameters in the HttpServletRequest-Object.

Is parseRequest() changing my object in any way? Are there any alternatives if I just want to get a parameter value (html-input) inside of my filter?

Thanks for your help

Daniel


What do you mean by 'there are no more parameters'?

One option would be to write an HttpServletRequestWrapper implementation that takes the list of FileItems created by the parseRequest method and make them visible as parameters to all callers. You would then wrap the original request and pass the new wrapper on to filter.doChain().



- Edit - Stupid smilies...
[ October 20, 2008: Message edited by: Steve Luke ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getParameter() methods should not be used when submitting a multi-part form. The whole purpose of the commons library is to parse the multi-part request for you. So yes, it changes the request by reading its input stream so it can gather the uploaded file(s) as well as the other request parameters.

Use the API of the upload package to obtain the values. No need for a wrapper.
[ October 20, 2008: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic