[ http://mc4j.org/jira/browse/STS-235?page=comments#action_10404 ] 
            
Tim Fennell commented on STS-235:
---------------------------------

Unfortunately it's not that wasy.  This is one of those moments where you 
really have to wonder, why oh why, did the Servlet spec not include support for 
mime/multipart data.  You see, for a normal post the stream of data that is 
sent by the browser is parsed by the servlet container and turned into the 
usual map of parameters.

But in the case of multipart/form-data the container doesn't know what to do, 
so the only thing that is available through the HttpServletRequest is the 
InputStream full of data that the client sent (or a Reader wrapped around it).  
So what most frameworks do is intercept the request, check to see if it's a 
multipart request and then consume the input stream.  In doing so they usually 
provide a wrapper or facade that makes it look just like a regular request, 
with a parameters map etc.  But once that input stream is consumed once, it 
can't be consumed again.

Section SRV.4.1.1 of the Servlet 2.4 specification kinda/sorta explains this.  
It's a painful omission from the spec because it leads to situations just like 
this.

I think you should be able to work around this by subclassing the StripesFilter 
and the StripesRequestWrapper.  Something like this:

public MyRequestWrapper extends StripesRequestWrapper() {
    public MyRequestWrapper(HttpServletRequest request, String pathToTempDir, 
int maxTotalPostSize) throws StripesServletException {
       try {
           super(request, pathToTempDir, maxTotalPostSize);
       } 
       catch (StripesServletException see) {
           if (see.getCause().getMessage().equals("Corrupt form data: premature 
ending") == false) throw sse;
       }
    }
}

public MyFilter extends StripesFilter {
    protected StripesRequestWrapper wrapRequest(HttpServletRequest 
servletRequest) throws StripesServletException {
        String tempDirPath = getTempDirectoryPath();
        return new StripesRequestWrapper(servletRequest, 
getTempDirectoryPath(), 10000000); // last is upload limit in bytes
    }
}

I think if you do that, and then use the custom filter instead of the Stripes 
Filter you should be able to work arond this problem.  I'd still like to find a 
way to determine when the request's input stream has already been eaten though.

> multipart/form-data without file upload
> ---------------------------------------
>
>                 Key: STS-235
>                 URL: http://mc4j.org/jira/browse/STS-235
>             Project: Stripes
>          Issue Type: Bug
>    Affects Versions: Release 1.3.2
>            Reporter: Andreas Schulz
>         Assigned To: Tim Fennell
>
> If the StripesFilter receives a multipart/form-data request with no file 
> attached to it an IOException is thrown. But some applications like Magnolia 
> CMS use this enctype by default. So it crashes when using Stripes.
> Stacktrace:
> java.io.IOException: Corrupt form data: premature ending
>       at 
> com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:205)
>       at 
> com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:222)
>       at 
> com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:173)
>       at 
> net.sourceforge.stripes.controller.StripesRequestWrapper.<init>(StripesRequestWrapper.java:109)
>       at 
> net.sourceforge.stripes.controller.StripesFilter.wrapRequest(StripesFilter.java:239)
>       at 
> net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:209)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>       at 
> info.magnolia.cms.filters.MagnoliaManagedFilter$CustomFilterChain.doFilter(MagnoliaManagedFilter.java:80)
>       at 
> info.magnolia.cms.filters.UnsetContextFilter.doFilter(UnsetContextFilter.java:44)
>       at 
> info.magnolia.cms.filters.MagnoliaManagedFilter$CustomFilterChain.doFilter(MagnoliaManagedFilter.java:84)
>       at 
> info.magnolia.cms.security.SecurityFilter.doFilter(SecurityFilter.java:96)
>       at 
> info.magnolia.cms.filters.MagnoliaManagedFilter$CustomFilterChain.doFilter(MagnoliaManagedFilter.java:84)
>       at 
> info.magnolia.cms.filters.MultipartRequestFilter.doFilter(MultipartRequestFilter.java:80)
>       at 
> info.magnolia.cms.filters.MagnoliaManagedFilter$CustomFilterChain.doFilter(MagnoliaManagedFilter.java:84)
>       at 
> info.magnolia.cms.filters.ContentTypeFilter.doFilter(ContentTypeFilter.java:66)
>       at 
> info.magnolia.cms.filters.MagnoliaManagedFilter$CustomFilterChain.doFilter(MagnoliaManagedFilter.java:84)
>       at 
> info.magnolia.cms.filters.MagnoliaManagedFilter.doFilter(MagnoliaManagedFilter.java:53)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
>       at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>       at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>       at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
>       at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>       at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
>       at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>       at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>       at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
>       at 
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
>       at 
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
>       at 
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
>       at 
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
>       at java.lang.Thread.run(Unknown Source)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to