|
| 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