You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2017/03/30 09:54:22 UTC

cxf git commit: [CXF-7071] Supporting reading of form params from HttpServletRequest and FormParams at the same time

Repository: cxf
Updated Branches:
  refs/heads/master 16163d804 -> fe55813cc


[CXF-7071] Supporting reading of form params from HttpServletRequest and FormParams at the same time


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fe55813c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fe55813c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fe55813c

Branch: refs/heads/master
Commit: fe55813cc934667664863117921ff8ea08b9ff24
Parents: 16163d8
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Thu Mar 30 10:54:07 2017 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Thu Mar 30 10:54:07 2017 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/HttpServletRequestFilter.java     | 15 ++++++++++-----
 .../apache/cxf/systest/jaxrs/BookStoreSpring.java    | 13 +++++++++++++
 .../jaxrs/JAXRSClientServerSpringBookTest.java       |  7 +++++++
 3 files changed, 30 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fe55813c/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletRequestFilter.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletRequestFilter.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletRequestFilter.java
index 750c2f5..4e4b52a 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletRequestFilter.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletRequestFilter.java
@@ -113,13 +113,18 @@ public class HttpServletRequestFilter extends HttpServletRequestWrapper {
         };
     }
 
+    @SuppressWarnings("unchecked")
     private void readFromParamsIfNeeded() {
         if (formParams == null) {
-            formParams = new MetadataMap<String, String>();
-            MediaType mt = JAXRSUtils.toMediaType((String)m.get(Message.CONTENT_TYPE));
-            String enc = HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name());
-            String body = FormUtils.readBody(m.getContent(InputStream.class), enc);
-            FormUtils.populateMapFromString(formParams, m, body, enc, true);
+            if (m.containsKey(FormUtils.FORM_PARAM_MAP)) {
+                formParams = (MultivaluedMap<String, String>)m.get(FormUtils.FORM_PARAM_MAP);
+            } else {
+                formParams = new MetadataMap<String, String>();
+                MediaType mt = JAXRSUtils.toMediaType((String)m.get(Message.CONTENT_TYPE));
+                String enc = HttpUtils.getEncoding(mt, StandardCharsets.UTF_8.name());
+                String body = FormUtils.readBody(m.getContent(InputStream.class), enc);
+                FormUtils.populateMapFromString(formParams, m, body, enc, true);
+            }
         }
 
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/fe55813c/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
index 90255ef..1c21c15 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
@@ -33,6 +33,7 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
 import javax.ws.rs.GET;
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.MatrixParam;
@@ -121,6 +122,18 @@ public class BookStoreSpring {
         return new Book(name, id);
     }
     @POST
+    @Path("/bookform5")
+    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+    @Produces("application/xml")
+    public Book echoBookForm5(@Context HttpServletRequest req, @FormParam("id") Long formId) {
+        String name = req.getParameter("name");
+        long id = Long.valueOf(req.getParameter("id"));
+        if (id != formId) {
+            throw new WebApplicationException();
+        }
+        return new Book(name, id);
+    }
+    @POST
     @Path("/bookform")
     @Consumes("application/xml")
     @Produces("application/xml")

http://git-wip-us.apache.org/repos/asf/cxf/blob/fe55813c/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index a5a3c82..f6be049 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -172,6 +172,13 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform4";
         doTestEchoBookForm(address);
     }
+    
+    @Test
+    public void testEchoBookForm5() throws Exception {
+        String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform5";
+        doTestEchoBookForm(address);
+    }
+    
     private void doTestEchoBookForm(String address) throws Exception {
         WebClient wc = WebClient.create(address);
         WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);