[cxf] branch 3.3.x-fixes updated (95a5525 -> 55af321)

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

[cxf] branch 3.3.x-fixes updated (95a5525 -> 55af321)

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

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


    from 95a5525  Recording .gitmergeinfo Changes
     new f35bf79  CXF-8227: Failure to comply with JAX-RS spec with ContainerRequestContext and WriterInterceptorContext (#692)
     new 55af321  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                                      |  1 +
 .../cxf/jaxrs/impl/PropertyHolderFactory.java      | 59 ++++++++++++++++++
 .../jaxrs/impl/ServletRequestPropertyHolder.java   | 70 ----------------------
 .../apache/cxf/systest/jaxrs/BookApplication.java  | 12 +++-
 .../jaxrs/JAXRSClientServerNonSpringBookTest.java  | 19 +++++-
 5 files changed, 89 insertions(+), 72 deletions(-)
 delete mode 100644 rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ServletRequestPropertyHolder.java

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.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit f35bf79d7c44286281e2c1fb857052255da55419
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)
---
 .../cxf/jaxrs/impl/PropertyHolderFactory.java      | 59 ++++++++++++++++++
 .../jaxrs/impl/ServletRequestPropertyHolder.java   | 70 ----------------------
 .../apache/cxf/systest/jaxrs/BookApplication.java  | 12 +++-
 .../jaxrs/JAXRSClientServerNonSpringBookTest.java  | 19 +++++-
 4 files changed, 88 insertions(+), 72 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/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ServletRequestPropertyHolder.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ServletRequestPropertyHolder.java
deleted file mode 100644
index 88b2ba2..0000000
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ServletRequestPropertyHolder.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.util.Collection;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.cxf.jaxrs.impl.PropertyHolderFactory.PropertyHolder;
-import org.apache.cxf.message.Message;
-
-public class ServletRequestPropertyHolder implements PropertyHolder {
-    private static final String ENDPOINT_ADDRESS_PROPERTY = "org.apache.cxf.transport.endpoint.address";
-    private HttpServletRequest request;
-    public ServletRequestPropertyHolder(Message m) {
-        request = (HttpServletRequest)m.get("HTTP.REQUEST");
-    }
-
-    @Override
-    public Object getProperty(String name) {
-        return request.getAttribute(name);
-    }
-
-    @Override
-    public void removeProperty(String name) {
-        request.removeAttribute(name);
-    }
-
-    @Override
-    public void setProperty(String name, Object value) {
-        if (value == null) {
-            removeProperty(name);
-        } else {
-            request.setAttribute(name, value);
-        }
-    }
-
-    @Override
-    public Collection<String> getPropertyNames() {
-        List<String> list = new LinkedList<>();
-        Enumeration<String> attrNames = request.getAttributeNames();
-        while (attrNames.hasMoreElements()) {
-            String name = attrNames.nextElement();
-            if (!ENDPOINT_ADDRESS_PROPERTY.equals(name)) {
-                list.add(name);
-            }
-        }
-        return list;
-    }
-
-}
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 605d5a6..0465916 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 c3ff4dc..6192000 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;
@@ -186,6 +188,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 {
@@ -193,10 +204,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.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 55af32128989e88ad4c5c2b60d1507528355884b
Author: reta <[hidden email]>
AuthorDate: Wed Sep 9 20:13:45 2020 -0400

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

diff --git a/.gitmergeinfo b/.gitmergeinfo
index e21d166..ec658cc 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -416,6 +416,7 @@ M 7a655b49fd6d432127a55b38f15c1212f7064196
 M 7aa6e0a402b8ce7dfff8a931a507b884d7152cea
 M 7b50181ebc445bb84d3463b284643432399bc0f8
 M 7c6bf1a843f2d4860d1bd7541139911ad47c7964
+M 7cfc8d07e1175c35877e7368f020db0749a78fab
 M 7e1bc67acf02fe6049a4bfb7e13fe6933e618ae8
 M 7ef814556d727c147d6f625cbb1170edfd24a752
 M 7f733555945f1faed66b0b6163d24889d4cf60fc