Skip to content

Commit 4ab7bc6

Browse files
author
graeme
committed
fix for GRAILS-1938
git-svn-id: https://svn.codehaus.org/grails/trunk@6274 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent f02126a commit 4ab7bc6

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/groovy/org/codehaus/groovy/grails/plugins/web/ControllersGrailsPlugin.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import org.springframework.validation.BindException
4444
import org.springframework.validation.Errors
4545
import org.springframework.web.multipart.commons.CommonsMultipartResolver
4646
import org.springframework.web.servlet.ModelAndView
47+
import org.codehaus.groovy.grails.web.multipart.ContentLengthAwareCommonsMultipartResolver
4748

4849
/**
4950
* A plug-in that handles the configuration of controllers for Grails
@@ -72,7 +73,7 @@ class ControllersGrailsPlugin {
7273
exceptionHandler(GrailsExceptionResolver) {
7374
exceptionMappings = ['java.lang.Exception': '/error']
7475
}
75-
multipartResolver(CommonsMultipartResolver)
76+
multipartResolver(ContentLengthAwareCommonsMultipartResolver)
7677
def urlMappings = [:]
7778
grailsUrlMappings(UrlMappingFactoryBean) {
7879
mappings = urlMappings
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* Copyright 2004-2005 Graeme Rocher
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.codehaus.groovy.grails.web.multipart;
16+
17+
import org.apache.commons.fileupload.FileUploadBase;
18+
import org.apache.commons.logging.Log;
19+
import org.apache.commons.logging.LogFactory;
20+
import org.springframework.web.multipart.MultipartException;
21+
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
22+
23+
import javax.servlet.http.HttpServletRequest;
24+
import java.util.Collections;
25+
26+
/**
27+
* Safari includes the multipart packet inside an HTTP redirect without the Content-Length header. This causes
28+
* CommonsMultipartResolver to blow up. We extend it here to catch this exception, printing a warning.
29+
*
30+
* @author Graeme Rocher
31+
* @since 1.0
32+
* <p/>
33+
* Created: Dec 7, 2007
34+
*/
35+
public class ContentLengthAwareCommonsMultipartResolver extends CommonsMultipartResolver {
36+
37+
static final Log LOG = LogFactory.getLog(ContentLengthAwareCommonsMultipartResolver.class );
38+
39+
protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
40+
try {
41+
return super.parseRequest(request);
42+
} catch (MultipartException e) {
43+
if(e.getCause() != null && e.getCause().getClass().equals(FileUploadBase.UnknownSizeException.class)) {
44+
LOG.warn(e.getMessage() );
45+
return new MultipartParsingResult(Collections.EMPTY_MAP,Collections.EMPTY_MAP);
46+
}
47+
else {
48+
throw e;
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)