Browse Source

SPR-8688 Don't use Servlet request params for form 'PUT' in ServletServerHttpRequest.

pull/7/head
Rossen Stoyanchev 13 years ago
parent
commit
7a3f02bce9
  1. 20
      org.springframework.web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

20
org.springframework.web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java

@ -31,6 +31,7 @@ import java.util.Iterator; @@ -31,6 +31,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
@ -51,9 +52,6 @@ public class ServletServerHttpRequest implements ServerHttpRequest { @@ -51,9 +52,6 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
private static final String METHOD_POST = "POST";
private static final String METHOD_PUT = "PUT";
private final HttpServletRequest servletRequest;
private HttpHeaders headers;
@ -107,20 +105,26 @@ public class ServletServerHttpRequest implements ServerHttpRequest { @@ -107,20 +105,26 @@ public class ServletServerHttpRequest implements ServerHttpRequest {
}
public InputStream getBody() throws IOException {
if (isFormSubmittal(this.servletRequest)) {
return getFormBody(this.servletRequest);
if (isFormPost(this.servletRequest)) {
return getBodyFromServletRequestParameters(this.servletRequest);
}
else {
return this.servletRequest.getInputStream();
}
}
private boolean isFormSubmittal(HttpServletRequest request) {
private boolean isFormPost(HttpServletRequest request) {
return request.getContentType() != null && request.getContentType().contains(FORM_CONTENT_TYPE) &&
(METHOD_POST.equalsIgnoreCase(request.getMethod()) || METHOD_PUT.equalsIgnoreCase(request.getMethod()));
(METHOD_POST.equalsIgnoreCase(request.getMethod()));
}
private InputStream getFormBody(HttpServletRequest request) throws IOException {
/**
* Use {@link ServletRequest#getParameterMap()} to reconstruct the body of
* a form 'POST' providing a predictable outcome as opposed to reading
* from the body, which can fail if any other code has used ServletRequest
* to access a parameter thus causing the input stream to be "consumed".
*/
private InputStream getBodyFromServletRequestParameters(HttpServletRequest request) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET);

Loading…
Cancel
Save