Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 51284 invoked from network); 24 Apr 2005 22:57:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Apr 2005 22:57:01 -0000 Received: (qmail 25166 invoked by uid 500); 24 Apr 2005 22:57:25 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 25072 invoked by uid 500); 24 Apr 2005 22:57:25 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 25055 invoked by uid 99); 24 Apr 2005 22:57:25 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of gertas@o2.pl designates 193.17.41.42 as permitted sender) Received: from mx2.go2.pl (HELO poczta.o2.pl) (193.17.41.42) by apache.org (qpsmtpd/0.28) with ESMTP; Sun, 24 Apr 2005 15:57:25 -0700 Received: from [192.168.0.8] (bal26.neoplus.adsl.tpnet.pl [83.27.175.26]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by poczta.o2.pl (Postfix) with ESMTP id 872F8340092 for ; Mon, 25 Apr 2005 00:56:54 +0200 (CEST) Message-ID: <426C24D7.90400@o2.pl> Date: Mon, 25 Apr 2005 00:59:35 +0200 From: Piotr Gaertig User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: commons-dev@jakarta.apache.org Subject: [fileupload] class contribution - HttpServletRequest wrapping Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hello, Current FileUpload component involves user in current code changes or usage of the nonstandard semantics of the parameter retrieval. That would be nightmare for projects based on huge forms, form digesters (struts) or just maintenanced projects. So I developed small class, which is remedy for presented problems. http://gertas.art.pl/res/files/UploadHttpServletRequest.java It just simply inherits the HttpServletRequestWrapper class, so it's Servlets version independent (2.3+). I'm also using latest FileUpload codebase from the ASF public SVN. A brief description: *

This class is "multipart" extension to servlets' * HttpServletRequest, each instance wraps a genuine request object * containing multipart data and acts as a traditional POST request allowing * access to parameters in standarized way.

.. the other details in the class file. An usage example: File tmp = new File(System.getProperty("java.io.tmpdir")); FileItemFactory fif = new DiskFileItemFactory(1*1024*1024,tmp); ServletFileUpload uploader = new ServletFileUpload(fif); uploader.setSizeMax(10*1024*1024); UploadHttpServletRequest request = new UploadHttpServletRequest(req,uploader); You can even integrate it with the ServletFileUpload through following method: public UploadHttpServletRequest wrapRequest(HttpServletRequest request) throws FileUploadException { return new UploadHttpServletRequest(request, this); } //wrapRequest, convertRequest, extendRequest or whatever Here are few use cases: *
    *
  • wrap a request at the begining of servlet's doPost and use * the extended request
  • *
  • wrap a request in a servlet filter, so all following servlets will be given * the extended request with no code change, casting is necessary * only in code processing files
  • *
  • wrap before RequestDispatcher invocation, this is similar to the filter use case
  • *
... thus wrapper gains code reuse and reduces current code modifications. I think this class can come in useful to many developers (as it was for me), so it is my contribution to the Commons FileUpload component project. The class and examples on this mail are licensed under the Apache License. I will make some test cases for this class if you decide it's worth to add to the project. Best regards, Piotr Gaertig --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org