[cxf] branch 3.2.x-fixes updated (04c19fe -> 5b0ddc5)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[cxf] branch 3.2.x-fixes updated (04c19fe -> 5b0ddc5)

reta
This is an automated email from the ASF dual-hosted git repository.

reta pushed a change to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from 04c19fe  Recording .gitmergeinfo Changes
     new 870ced5  CXF-8227: Failure to comply with JAX-RS spec with ContainerRequestContext and WriterInterceptorContext (#692)
     new 5b0ddc5  Recording .gitmergeinfo Changes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmergeinfo                                      |  2 +
 .../cxf/jaxrs/impl/PropertyHolderFactory.java      | 59 ++++++++++++++++++++++
 .../apache/cxf/systest/jaxrs/BookApplication.java  | 12 ++++-
 .../jaxrs/JAXRSClientServerNonSpringBookTest.java  | 19 ++++++-
 4 files changed, 90 insertions(+), 2 deletions(-)

Reply | Threaded
Open this post in threaded view
|

[cxf] 01/02: CXF-8227: Failure to comply with JAX-RS spec with ContainerRequestContext and WriterInterceptorContext (#692)

reta
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 870ced5c56b20925949e2860d2b099ae0b9883a0
Author: Andriy Redko <[hidden email]>
AuthorDate: Wed Sep 9 20:02:12 2020 -0400

    CXF-8227: Failure to comply with JAX-RS spec with ContainerRequestContext and WriterInterceptorContext (#692)
   
    * CXF-8227: Failure to comply with JAX-RS spec with ContainerRequestContext and WriterInterceptorContext. Addressing review comments
    (cherry picked from commit 6d5fddfa467cb7d9a54c066029b2a6d055fb5546)
   
    (cherry picked from commit f35bf79d7c44286281e2c1fb857052255da55419)
   
    # Conflicts:
    # rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ServletRequestPropertyHolder.java
---
 .../cxf/jaxrs/impl/PropertyHolderFactory.java      | 59 ++++++++++++++++++++++
 .../apache/cxf/systest/jaxrs/BookApplication.java  | 12 ++++-
 .../jaxrs/JAXRSClientServerNonSpringBookTest.java  | 19 ++++++-
 3 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PropertyHolderFactory.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PropertyHolderFactory.java
index 23be014..052eb48 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PropertyHolderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/PropertyHolderFactory.java
@@ -20,8 +20,13 @@ package org.apache.cxf.jaxrs.impl;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
@@ -41,6 +46,60 @@ public final class PropertyHolderFactory {
         void setProperty(String name, Object value);
         Collection<String> getPropertyNames();
     }
+    
+    private static class ServletRequestPropertyHolder extends MessagePropertyHolder {
+        private static final String ENDPOINT_ADDRESS_PROPERTY = "org.apache.cxf.transport.endpoint.address";
+        private final HttpServletRequest request;
+        
+        ServletRequestPropertyHolder(Message m) {
+            super(m);
+            request = (HttpServletRequest)m.get("HTTP.REQUEST");
+        }
+
+        @Override
+        public Object getProperty(String name) {
+            final Object value = request.getAttribute(name);
+
+            if (value != null) {
+                return value;
+            }
+            
+            return super.getProperty(name);
+        }
+
+        @Override
+        public void removeProperty(String name) {
+            super.removeProperty(name);
+            request.removeAttribute(name);
+        }
+
+        @Override
+        public void setProperty(String name, Object value) {
+            if (value == null) {
+                removeProperty(name);
+            } else {
+                super.setProperty(name, value);
+                request.setAttribute(name, value);
+            }
+        }
+
+        @Override
+        public Collection<String> getPropertyNames() {
+            final Set<String> list = new LinkedHashSet<>();
+            
+            Enumeration<String> attrNames = request.getAttributeNames();
+            while (attrNames.hasMoreElements()) {
+                String name = attrNames.nextElement();
+                if (!ENDPOINT_ADDRESS_PROPERTY.equals(name)) {
+                    list.add(name);
+                }
+            }
+            
+            list.addAll(super.getPropertyNames());
+            return list;
+        }
+
+    }
 
     private static class MessagePropertyHolder implements PropertyHolder {
         private static final String PROPERTY_KEY = "jaxrs.filter.properties";
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
index 2297900..2896a3e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
@@ -106,6 +106,12 @@ public class BookApplication extends Application {
         public void aroundWriteTo(WriterInterceptorContext context) throws IOException,
             WebApplicationException {
             context.getHeaders().putSingle("BookWriter", "TheBook");
+            
+            final Object property = context.getProperty("property");
+            if (property != null) {
+                context.getHeaders().putSingle("X-Property-WriterInterceptor", property);
+            }
+            
             context.proceed();
         }
 
@@ -131,7 +137,11 @@ public class BookApplication extends Application {
                 || uri.contains("/application6")) {
                 context.getHeaders().put("BOOK", Arrays.asList("1", "2"));
             }
-
+            
+            final String value = context.getUriInfo().getQueryParameters().getFirst("property");
+            if (value != null) {
+                context.setProperty("property", value);
+            }
         }
 
     }
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
index d8c9685..1fc5f95 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
@@ -20,8 +20,10 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.io.InputStream;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
@@ -181,6 +183,15 @@ public class JAXRSClientServerNonSpringBookTest extends AbstractBusClientServerT
             doTestPerRequest("http://localhost:" + PORT + "/application11/thebooks/bookstore2/bookheaders");
         assertEquals("TheBook", r.getHeaderString("BookWriter"));
     }
+    
+    @Test
+    public void testGetBook123PropagatingContextPropertyToWriterInterceptor() throws Exception {
+        Response r =
+            doTestPerRequest("http://localhost:" + PORT + "/application6/thebooks/bookstore2/bookheaders",
+                new SimpleEntry<>("property", "PropValue"));
+        assertEquals("PropValue", r.getHeaderString("X-Property-WriterInterceptor"));
+    }
+
 
     @Test
     public void testGetBook123TwoApplications() throws Exception {
@@ -188,10 +199,16 @@ public class JAXRSClientServerNonSpringBookTest extends AbstractBusClientServerT
         doTestPerRequest("http://localhost:" + PORT + "/application6/the%20books2/bookstore2/book%20headers");
     }
 
-    private Response doTestPerRequest(String address) throws Exception {
+    @SafeVarargs
+    private final Response doTestPerRequest(String address, Map.Entry<String, String> ... params) throws Exception {
         WebClient wc = WebClient.create(address);
         WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L);
         wc.accept("application/xml");
+        
+        for (Map.Entry<String, String> param: params) {
+            wc.query(param.getKey(), param.getValue());
+        }
+        
         Response r = wc.get();
         Book book = r.readEntity(Book.class);
         assertEquals("CXF in Action", book.getName());

Reply | Threaded
Open this post in threaded view
|

[cxf] 02/02: Recording .gitmergeinfo Changes

reta
In reply to this post by reta
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 5b0ddc5ad7ec2935c196509247e5ab9d651240be
Author: reta <[hidden email]>
AuthorDate: Thu Sep 10 08:47:16 2020 -0400

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 39fd13d..c96f87e 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -339,6 +339,7 @@ B 54d812a2cbba2d132e288902ce4a43d868a2282f
 B 5544a990e1272bf72fbbb7bb5104409d020328e3
 B 5578e0b82bcd4ea19c1de5b4a008af35f9c8451b
 B 558d3a15e18a54ba797d317add96e34d67850d54
+B 55af32128989e88ad4c5c2b60d1507528355884b
 B 55afdc9373257d8c111468926c7278b4e9b28a61
 B 55d5b1abf6dff2056289a0433de828c49f25afcc
 B 5601ae06f2f85e09c2319a0086a1a1ea5a1df270
@@ -1147,6 +1148,7 @@ M ef67a7f64ee1dd84c84a2cef86e73dd9ad7bb112
 M efb2c3082fe8799a9d90a696e31239551b4f1823
 M f044a02831ad2adff59155924682f73ffdf6213a
 M f09ae1ed3bbc88a6d7860697dd65821fd9958d99
+M f35bf79d7c44286281e2c1fb857052255da55419
 M f6bb4090926baa935dba14b655441e79bdabccdd
 M f7ae16dff9561db9bc16e1ad82ae75e93fdb735d
 M fc4f94f663db6a27d2352a9b6424e42c89f7a522