cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7071] Supporting reading of form params from HttpServletRequest and FormParams at the same time
Date Thu, 30 Mar 2017 10:07:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes f10ba987b -> c83919aa2


[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/c83919aa
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c83919aa
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c83919aa

Branch: refs/heads/3.0.x-fixes
Commit: c83919aa2fe939520208e0f4e222fdfb889bde6b
Parents: f10ba98
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Mar 30 10:54:07 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Mar 30 11:07:28 2017 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/c83919aa/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 97fe796..6c968d3 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
@@ -111,14 +111,19 @@ 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, "UTF-8");
-            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, "UTF-8");
+                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/c83919aa/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 caa97c3..bfc33ae 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/c83919aa/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 675490f..c387c5d 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
@@ -164,6 +164,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);


Mime
View raw message