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-6709] The best effort at returning the original IS
Date Mon, 14 Dec 2015 12:25:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 4fb875fa9 -> d62fb7899


[CXF-6709] The best effort at returning the original IS


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

Branch: refs/heads/3.0.x-fixes
Commit: d62fb7899de20a1a359b056af76dad44880e4e85
Parents: 4fb875f
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Dec 14 12:17:26 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Dec 14 12:25:17 2015 +0000

----------------------------------------------------------------------
 .../jaxrs/impl/HttpServletRequestFilter.java    | 51 ++++++++++++++++++++
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  4 +-
 .../cxf/jaxrs/ext/MessageContextImplTest.java   |  8 ++-
 .../apache/cxf/jaxrs/utils/JAXRSUtilsTest.java  | 21 +++++---
 .../cxf/systest/jaxrs/BookStoreSpring.java      | 13 ++++-
 .../jaxrs/JAXRSClientServerSpringBookTest.java  | 12 ++++-
 6 files changed, 96 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d62fb789/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
new file mode 100644
index 0000000..9d393d4
--- /dev/null
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpServletRequestFilter.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.apache.cxf.io.DelegatingInputStream;
+import org.apache.cxf.message.Message;
+
+public class HttpServletRequestFilter extends HttpServletRequestWrapper {
+
+    private Message m;
+    public HttpServletRequestFilter(HttpServletRequest request, Message message) {
+        super(request);
+        m = message;
+    }
+    @Override
+    public ServletInputStream getInputStream() throws IOException {
+        InputStream is = m.getContent(InputStream.class);
+        if (is instanceof DelegatingInputStream) {
+            is = ((DelegatingInputStream)is).getInputStream();
+        }
+        if (is instanceof ServletInputStream) {
+            return (ServletInputStream)is;
+        } else {
+            return super.getInputStream();
+        }
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/cxf/blob/d62fb789/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 5f7ed68..6825b4c 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -102,6 +102,7 @@ import org.apache.cxf.jaxrs.impl.AsyncResponseImpl;
 import org.apache.cxf.jaxrs.impl.ContainerRequestContextImpl;
 import org.apache.cxf.jaxrs.impl.ContainerResponseContextImpl;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
 import org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -1157,7 +1158,8 @@ public final class JAXRSUtils {
         
         Object value = null; 
         if (clazz == HttpServletRequest.class) {
-            value = m.get(AbstractHTTPDestination.HTTP_REQUEST);
+            HttpServletRequest request = (HttpServletRequest)m.get(AbstractHTTPDestination.HTTP_REQUEST);
+            value = request != null ? new HttpServletRequestFilter(request, m) : null;
         } else if (clazz == HttpServletResponse.class) {
             HttpServletResponse response = (HttpServletResponse)m.get(AbstractHTTPDestination.HTTP_RESPONSE);
             value = response != null ? new HttpServletResponseFilter(response, m) : null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/d62fb789/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/MessageContextImplTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/MessageContextImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/MessageContextImplTest.java
index b40c669..64fcd48 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/MessageContextImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/MessageContextImplTest.java
@@ -34,6 +34,7 @@ import javax.xml.bind.JAXBContext;
 
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
 import org.apache.cxf.jaxrs.impl.ProvidersImpl;
 import org.apache.cxf.jaxrs.impl.RequestImpl;
@@ -126,8 +127,11 @@ public class MessageContextImplTest extends Assert {
         MessageContext mc = new MessageContextImpl(m);
         HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
         m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
-        assertSame(request.getClass(), mc.getHttpServletRequest().getClass());
-        assertSame(request.getClass(), mc.getContext(HttpServletRequest.class).getClass());
+        
+        assertSame(request.getClass(), 
+                   ((HttpServletRequestFilter)mc.getHttpServletRequest()).getRequest().getClass());
+        assertSame(request.getClass(), 
+                   ((HttpServletRequestFilter)mc.getContext(HttpServletRequest.class)).getRequest().getClass());
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/cxf/blob/d62fb789/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
index aa051c6..4282a9a 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
@@ -74,6 +74,7 @@ import org.apache.cxf.jaxrs.SimpleFactory;
 import org.apache.cxf.jaxrs.Timezone;
 import org.apache.cxf.jaxrs.ext.ContextProvider;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
+import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
@@ -1718,7 +1719,7 @@ public class JAXRSUtilsTest extends Assert {
         List<Object> params = 
             JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
         assertEquals("4 parameters expected", 4, params.size());
-        assertSame(request.getClass(), params.get(0).getClass());
+        assertSame(request.getClass(), ((HttpServletRequestFilter)params.get(0)).getRequest().getClass());
         assertSame(response.getClass(), params.get(1).getClass());
         assertSame(context.getClass(), params.get(2).getClass());
         assertSame(config.getClass(), params.get(3).getClass());
@@ -1789,8 +1790,10 @@ public class JAXRSUtilsTest extends Assert {
                    ((ThreadLocalProxy<ServletContext>)c.getServletContext()).get());
         assertSame(servletContextMock, 
                    ((ThreadLocalProxy<ServletContext>)c.getSuperServletContext()).get());
-        assertSame(httpRequest, 
-                   ((ThreadLocalProxy<HttpServletRequest>)c.getServletRequest()).get());
+        HttpServletRequest currentReq = 
+            ((ThreadLocalProxy<HttpServletRequest>)c.getServletRequest()).get();
+        assertSame(httpRequest,
+                   ((HttpServletRequestFilter)currentReq).getRequest());
         HttpServletResponseFilter filter = (
             HttpServletResponseFilter)((ThreadLocalProxy<HttpServletResponse>)c.getServletResponse()).get();
         assertSame(httpResponse, filter.getResponse());
@@ -1815,8 +1818,10 @@ public class JAXRSUtilsTest extends Assert {
         InjectionUtils.injectContextFields(c, cri, m);
         assertSame(servletContextMock, 
                    ((ThreadLocalProxy<ServletContext>)c.getServletContextResource()).get());
-        assertSame(httpRequest, 
-                   ((ThreadLocalProxy<HttpServletRequest>)c.getServletRequestResource()).get());
+        HttpServletRequest currentReq = 
+            ((ThreadLocalProxy<HttpServletRequest>)c.getServletRequestResource()).get();
+        assertSame(httpRequest,
+                   ((HttpServletRequestFilter)currentReq).getRequest());
         HttpServletResponseFilter filter = (
             HttpServletResponseFilter)((ThreadLocalProxy<HttpServletResponse>)c.getServletResponseResource())
                 .get();
@@ -1960,7 +1965,8 @@ public class JAXRSUtilsTest extends Assert {
         m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
         
         InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
-        assertSame(request.getClass(), c.getServletRequestResource().getClass());
+        assertSame(request.getClass(), 
+                   ((HttpServletRequestFilter)c.getServletRequestResource()).getRequest().getClass());
         HttpServletResponseFilter filter = (HttpServletResponseFilter)c.getServletResponseResource();
         assertSame(response.getClass(), filter.getResponse().getClass());
         assertSame(context.getClass(), c.getServletContextResource().getClass());
@@ -1970,7 +1976,8 @@ public class JAXRSUtilsTest extends Assert {
         assertNotNull(c.getServletRequestResource());
         assertNotNull(c.getServletResponseResource());
         assertNotNull(c.getServletContextResource());
-        assertSame(request.getClass(), c.getServletRequest().getClass());
+        assertSame(request.getClass(), 
+                   ((HttpServletRequestFilter)c.getServletRequestResource()).getRequest().getClass());
         filter = (HttpServletResponseFilter)c.getServletResponse();
         assertSame(response.getClass(), filter.getResponse().getClass());
         assertSame(context.getClass(), c.getServletContext().getClass());

http://git-wip-us.apache.org/repos/asf/cxf/blob/d62fb789/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 8ae6bff..a367733 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
@@ -21,6 +21,8 @@ package org.apache.cxf.systest.jaxrs;
 
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.util.Collections;
 import java.util.HashMap;
@@ -51,13 +53,12 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 
-import org.apache.cxf.annotations.Logging;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.staxutils.DepthExceededStaxException;
 import org.apache.cxf.staxutils.StaxUtils;
 
 @Path("/")
 @Produces("application/json")
-@Logging
 public class BookStoreSpring {
 
     private Map<Long, Book> books = new HashMap<Long, Book>();
@@ -91,6 +92,14 @@ public class BookStoreSpring {
         long id = Long.valueOf(req.getParameter("id"));
         return new Book(name, id);
     }
+    @POST
+    @Path("/bookform")
+    @Consumes("application/xml")
+    @Produces("application/xml")
+    public String echoBookFormXml(@Context HttpServletRequest req) throws IOException {
+        InputStream is = req.getInputStream();
+        return IOUtils.readStringFromStream(is);
+    }
     
     @GET
     @Path("/books/webex")

http://git-wip-us.apache.org/repos/asf/cxf/blob/d62fb789/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 f4a3aa6..5571952 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
@@ -99,13 +99,23 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
     public void testEchoBookForm() throws Exception {
         String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform";
         WebClient wc = WebClient.create(address);
-        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
         Book b = 
             wc.form(new Form().param("name", "CXFForm").param("id", "125"))
                 .readEntity(Book.class);
         assertEquals("CXFForm", b.getName());
         assertEquals(125L, b.getId());
     }
+    @Test
+    public void testEchoBookFormXml() throws Exception {
+        String address = "http://localhost:" + PORT + "/bus/thebooksform/bookform";
+        WebClient wc = WebClient.create(address);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
+        Book b = 
+            wc.type("application/xml").post(new Book("CXFFormXml", 125L))
+                .readEntity(Book.class);
+        assertEquals("CXFFormXml", b.getName());
+        assertEquals(125L, b.getId());
+    }
     
     @Test
     public void testGetBookWebEx4() throws Exception {


Mime
View raw message