11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .web .bind .support ;
1818
19- import java .io .IOException ;
2019import java .util .List ;
2120import java .util .Map ;
22-
23- import javax .servlet .ServletException ;
2421import javax .servlet .http .HttpServletRequest ;
2522import javax .servlet .http .Part ;
2623
7370 */
7471public class WebRequestDataBinder extends WebDataBinder {
7572
76-
7773 /**
7874 * Create a new WebRequestDataBinder instance, with default object name.
7975 * @param target the target object to bind onto (or {@code null}
@@ -115,8 +111,7 @@ public WebRequestDataBinder(Object target, String objectName) {
115111 */
116112 public void bind (WebRequest request ) {
117113 MutablePropertyValues mpvs = new MutablePropertyValues (request .getParameterMap ());
118-
119- if (isMultipartRequest (request ) && (request instanceof NativeWebRequest )) {
114+ if (isMultipartRequest (request ) && request instanceof NativeWebRequest ) {
120115 MultipartRequest multipartRequest = ((NativeWebRequest ) request ).getNativeRequest (MultipartRequest .class );
121116 if (multipartRequest != null ) {
122117 bindMultipart (multipartRequest .getMultiFileMap (), mpvs );
@@ -129,6 +124,15 @@ else if (ClassUtils.hasMethod(HttpServletRequest.class, "getParts")) {
129124 doBind (mpvs );
130125 }
131126
127+ /**
128+ * Check if the request is a multipart request (by checking its Content-Type header).
129+ * @param request request with parameters to bind
130+ */
131+ private boolean isMultipartRequest (WebRequest request ) {
132+ String contentType = request .getHeader ("Content-Type" );
133+ return (contentType != null && StringUtils .startsWithIgnoreCase (contentType , "multipart" ));
134+ }
135+
132136 /**
133137 * Treats errors as fatal.
134138 * <p>Use this method only if it's an error if the input isn't valid.
@@ -141,16 +145,6 @@ public void closeNoCatch() throws BindException {
141145 }
142146 }
143147
144- /**
145- * Check if the request is a multipart request (by checking its Content-Type header).
146- *
147- * @param request request with parameters to bind
148- */
149- private boolean isMultipartRequest (WebRequest request ) {
150- String contentType = request .getHeader ("Content-Type" );
151- return ((contentType != null ) && StringUtils .startsWithIgnoreCase (contentType , "multipart" ));
152- }
153-
154148
155149 /**
156150 * Encapsulate Part binding code for Servlet 3.0+ only containers.
@@ -160,12 +154,10 @@ private static class Servlet3MultipartHelper {
160154
161155 private final boolean bindEmptyMultipartFiles ;
162156
163-
164157 public Servlet3MultipartHelper (boolean bindEmptyMultipartFiles ) {
165158 this .bindEmptyMultipartFiles = bindEmptyMultipartFiles ;
166159 }
167160
168-
169161 public void bindParts (HttpServletRequest request , MutablePropertyValues mpvs ) {
170162 try {
171163 MultiValueMap <String , Part > map = new LinkedMultiValueMap <String , Part >();
@@ -184,14 +176,10 @@ public void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) {
184176 }
185177 }
186178 }
187- catch (IOException ex ) {
188- throw new MultipartException ("Failed to get request parts" , ex );
189- }
190- catch (ServletException ex ) {
179+ catch (Exception ex ) {
191180 throw new MultipartException ("Failed to get request parts" , ex );
192181 }
193182 }
194-
195183 }
196184
197185}
0 commit comments