1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .web .bind .support ;
18
18
19
- import java .io .IOException ;
20
19
import java .util .List ;
21
20
import java .util .Map ;
22
-
23
- import javax .servlet .ServletException ;
24
21
import javax .servlet .http .HttpServletRequest ;
25
22
import javax .servlet .http .Part ;
26
23
73
70
*/
74
71
public class WebRequestDataBinder extends WebDataBinder {
75
72
76
-
77
73
/**
78
74
* Create a new WebRequestDataBinder instance, with default object name.
79
75
* @param target the target object to bind onto (or {@code null}
@@ -115,8 +111,7 @@ public WebRequestDataBinder(Object target, String objectName) {
115
111
*/
116
112
public void bind (WebRequest request ) {
117
113
MutablePropertyValues mpvs = new MutablePropertyValues (request .getParameterMap ());
118
-
119
- if (isMultipartRequest (request ) && (request instanceof NativeWebRequest )) {
114
+ if (isMultipartRequest (request ) && request instanceof NativeWebRequest ) {
120
115
MultipartRequest multipartRequest = ((NativeWebRequest ) request ).getNativeRequest (MultipartRequest .class );
121
116
if (multipartRequest != null ) {
122
117
bindMultipart (multipartRequest .getMultiFileMap (), mpvs );
@@ -129,6 +124,15 @@ else if (ClassUtils.hasMethod(HttpServletRequest.class, "getParts")) {
129
124
doBind (mpvs );
130
125
}
131
126
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
+
132
136
/**
133
137
* Treats errors as fatal.
134
138
* <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 {
141
145
}
142
146
}
143
147
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
-
154
148
155
149
/**
156
150
* Encapsulate Part binding code for Servlet 3.0+ only containers.
@@ -160,12 +154,10 @@ private static class Servlet3MultipartHelper {
160
154
161
155
private final boolean bindEmptyMultipartFiles ;
162
156
163
-
164
157
public Servlet3MultipartHelper (boolean bindEmptyMultipartFiles ) {
165
158
this .bindEmptyMultipartFiles = bindEmptyMultipartFiles ;
166
159
}
167
160
168
-
169
161
public void bindParts (HttpServletRequest request , MutablePropertyValues mpvs ) {
170
162
try {
171
163
MultiValueMap <String , Part > map = new LinkedMultiValueMap <String , Part >();
@@ -184,14 +176,10 @@ public void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) {
184
176
}
185
177
}
186
178
}
187
- catch (IOException ex ) {
188
- throw new MultipartException ("Failed to get request parts" , ex );
189
- }
190
- catch (ServletException ex ) {
179
+ catch (Exception ex ) {
191
180
throw new MultipartException ("Failed to get request parts" , ex );
192
181
}
193
182
}
194
-
195
183
}
196
184
197
185
}
0 commit comments