Commit 8689a14e authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-7050] Logging request filter fails on POST requests without a content type

parent bbecc2be
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -108,9 +108,10 @@ public class BufferedRequestWrapper extends HttpServletRequestWrapper {
protected void parseParameters(){
if (myParameterMap != null) return;
if (myWrappedRequest.getMethod().equals("POST") &&
myWrappedRequest.getContentType().startsWith("application/x-www-form-urlencoded")) {
parseFormBody();
String contentType = myWrappedRequest.getContentType();
if (myWrappedRequest.getMethod().equals("POST") && contentType != null
&& contentType.startsWith("application/x-www-form-urlencoded")) {
parseFormBody();
} else {
myParameterMap = new HashMap(super.getParameterMap());
......
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -16,6 +16,8 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.springframework.web.util.WebUtils;
import com.mockrunner.mock.web.MockHttpServletRequest;
public class BufferedRequestWrapperTest extends RequestWrapperTestSupport {
@Test
......@@ -92,4 +94,38 @@ public class BufferedRequestWrapperTest extends RequestWrapperTestSupport {
assertEquals("3", ((String[]) params.get("c"))[0]);
assertEquals("4", ((String[]) params.get("d"))[0]);
}
@Test
public void testNoContentType() throws Exception {
String body = "a=1&b=2";
String queryString = "c=3&d=4";
MockHttpServletRequest req = makeRequest(body, queryString);
// reset the content type
req.setContentType(null);
BufferedReader br = req.getReader();
while ((br.readLine()) != null) { /* clear out the body */
}
// should not NPE like it did
BufferedRequestWrapper wrapper = new BufferedRequestWrapper(req, "UTF-8", body.getBytes());
Map params = wrapper.getParameterMap();
assertEquals(0, params.size());
}
@Test
public void testEmptyPost() throws Exception {
MockHttpServletRequest req = makeRequest("", "");
// reset the content type
req.setContentType(null);
BufferedReader br = req.getReader();
while ((br.readLine()) != null) { /* clear out the body */
}
// should not NPE like it did
BufferedRequestWrapper wrapper = new BufferedRequestWrapper(req, "UTF-8", "".getBytes());
Map params = wrapper.getParameterMap();
assertEquals(0, params.size());
}
}
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -24,7 +24,7 @@ public class RequestWrapperTestSupport {
"test\ncontaining\nnewlines"
};
protected HttpServletRequest makeRequest(String body, String queryString){
protected MockHttpServletRequest makeRequest(String body, String queryString) {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment