|
|
|
@ -44,13 +44,11 @@ import org.springframework.util.Assert; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ServletServerHttpRequest implements ServerHttpRequest { |
|
|
|
public class ServletServerHttpRequest implements ServerHttpRequest { |
|
|
|
|
|
|
|
|
|
|
|
private static final String FORM_CONTENT_TYPE = "application/x-www-form-urlencoded"; |
|
|
|
protected static final String FORM_CONTENT_TYPE = "application/x-www-form-urlencoded"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String POST_METHOD = "POST"; |
|
|
|
protected static final String FORM_CHARSET = "UTF-8"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String PUT_METHOD = "PUT"; |
|
|
|
private static final String METHOD_POST = "POST"; |
|
|
|
|
|
|
|
|
|
|
|
private static final String FORM_CHARSET = "UTF-8"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final HttpServletRequest servletRequest; |
|
|
|
private final HttpServletRequest servletRequest; |
|
|
|
|
|
|
|
|
|
|
|
@ -105,20 +103,26 @@ public class ServletServerHttpRequest implements ServerHttpRequest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public InputStream getBody() throws IOException { |
|
|
|
public InputStream getBody() throws IOException { |
|
|
|
if (isFormSubmittal(this.servletRequest)) { |
|
|
|
if (isFormPost(this.servletRequest)) { |
|
|
|
return getFormBody(this.servletRequest); |
|
|
|
return getBodyFromServletRequestParameters(this.servletRequest); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
return this.servletRequest.getInputStream(); |
|
|
|
return this.servletRequest.getInputStream(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isFormSubmittal(HttpServletRequest request) { |
|
|
|
private boolean isFormPost(HttpServletRequest request) { |
|
|
|
return FORM_CONTENT_TYPE.equals(request.getContentType()) && |
|
|
|
return (request.getContentType() != null && request.getContentType().contains(FORM_CONTENT_TYPE) && |
|
|
|
(POST_METHOD.equalsIgnoreCase(request.getMethod()) || PUT_METHOD.equalsIgnoreCase(request.getMethod())); |
|
|
|
METHOD_POST.equalsIgnoreCase(request.getMethod())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private InputStream getFormBody(HttpServletRequest request) throws IOException { |
|
|
|
/** |
|
|
|
|
|
|
|
* Use {@link javax.servlet.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(); |
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
|
|
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET); |
|
|
|
Writer writer = new OutputStreamWriter(bos, FORM_CHARSET); |
|
|
|
|
|
|
|
|
|
|
|
|