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

cziegeler pushed a commit to branch http-4.x
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/http-4.x by this push:
     new a8be1bfef5 Port changes from main branch to 1.0.x branch
a8be1bfef5 is described below

commit a8be1bfef565c2a8eed0af48856e12d22a209b6d
Author: Carsten Ziegeler <cziege...@apache.org>
AuthorDate: Thu Jun 20 08:04:47 2024 +0200

    Port changes from main branch to 1.0.x branch
---
 http/wrappers/pom.xml                              | 35 +++++++++++++++--
 .../jakartawrappers/HttpServletRequestWrapper.java |  6 ++-
 .../jakartawrappers/ServletRequestWrapper.java     |  2 +-
 .../javaxwrappers/HttpServletRequestWrapper.java   |  6 ++-
 .../http/javaxwrappers/ServletRequestWrapper.java  |  2 +-
 .../HttpServletRequestWrapperTest.java             | 35 +++++++++++++++++
 .../http/jakartawrappers/ServletRequestTest.java   | 44 +++++++++++++++++-----
 .../HttpServletRequestWrapperTest.java             | 38 +++++++++++++++++++
 .../http/javaxwrappers/ServletRequestTest.java     | 42 ++++++++++++++++-----
 9 files changed, 182 insertions(+), 28 deletions(-)

diff --git a/http/wrappers/pom.xml b/http/wrappers/pom.xml
index 50a8bc4109..4809efe500 100644
--- a/http/wrappers/pom.xml
+++ b/http/wrappers/pom.xml
@@ -21,14 +21,14 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.felix</groupId>
-        <artifactId>org.apache.felix.http.parent</artifactId>
-        <version>13</version>
-        <relativePath>../parent/pom.xml</relativePath>
+        <artifactId>felix-parent</artifactId>
+        <version>9</version>
+        <relativePath>../pom/pom.xml</relativePath>
     </parent>
 
     <name>Apache Felix Http Wrappers</name>
     <artifactId>org.apache.felix.http.wrappers</artifactId>
-    <version>1.0.3-SNAPSHOT</version>
+    <version>1.0.5-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <scm>
@@ -49,11 +49,38 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <version>5.1.9</version>
                 <extensions>true</extensions>
+                <executions>
+                    <execution>
+                        <id>bundle</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>bundle</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>baseline</id>
+                        <goals>
+                          <goal>baseline</goal>
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
         </plugins>
     </build>
 
     <dependencies>
+        <dependency>
+            <groupId>org.jetbrains</groupId>
+            <artifactId>annotations</artifactId>
+            <version>16.0.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.annotation</artifactId>
+            <version>6.0.1</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>javax.servlet-api</artifactId>
diff --git 
a/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapper.java
 
b/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapper.java
index 2967dd3c63..5916e74713 100644
--- 
a/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapper.java
+++ 
b/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapper.java
@@ -231,7 +231,11 @@ public class HttpServletRequestWrapper extends 
ServletRequestWrapper
     @Override
     public Part getPart(final String name) throws IOException, 
ServletException {
         try {
-            return new PartWrapper(this.request.getPart(name));
+            final javax.servlet.http.Part p = this.request.getPart(name);
+            if (p != null) {
+                return new PartWrapper(p);
+            }
+            return null;
         } catch ( final javax.servlet.ServletException e ) {
             throw ServletExceptionUtil.getServletException(e);
         }
diff --git 
a/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/ServletRequestWrapper.java
 
b/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/ServletRequestWrapper.java
index 2d11a541a0..71ec9a0977 100644
--- 
a/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/ServletRequestWrapper.java
+++ 
b/http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/ServletRequestWrapper.java
@@ -307,8 +307,8 @@ public class ServletRequestWrapper implements 
ServletRequest {
     public void setAttribute(final String name, final Object o) {
         final String translatedName = getTranslatedAttributeName(name);
         if (translatedName != null) {
-            this.request.setAttribute(translatedName, o);
             this.request.removeAttribute(name);
+            this.request.setAttribute(translatedName, o);
         } else {
             this.request.setAttribute(name, o);
         }
diff --git 
a/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapper.java
 
b/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapper.java
index 7396e62db3..2cf055a4dd 100644
--- 
a/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapper.java
+++ 
b/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapper.java
@@ -227,7 +227,11 @@ public class HttpServletRequestWrapper extends 
ServletRequestWrapper
     @Override
     public javax.servlet.http.Part getPart(final String name) throws 
IOException, javax.servlet.ServletException {
         try {
-            return new PartWrapper(this.request.getPart(name));
+            final Part p = this.request.getPart(name);
+            if (p != null) {
+                return new PartWrapper(p);
+            }
+            return null;
         } catch ( final jakarta.servlet.ServletException e ) {
             throw ServletExceptionUtil.getServletException(e);
         }
diff --git 
a/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/ServletRequestWrapper.java
 
b/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/ServletRequestWrapper.java
index 70030206bd..57a2b809c2 100644
--- 
a/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/ServletRequestWrapper.java
+++ 
b/http/wrappers/src/main/java/org/apache/felix/http/javaxwrappers/ServletRequestWrapper.java
@@ -305,8 +305,8 @@ public class ServletRequestWrapper implements 
javax.servlet.ServletRequest {
     public void setAttribute(final String name, final Object o) {
         final String translatedName = getTranslatedAttributeName(name);
         if (translatedName != null) {
-            this.request.setAttribute(translatedName, o);
             this.request.removeAttribute(name);
+            this.request.setAttribute(translatedName, o);
         } else {
             this.request.setAttribute(name, o);
         }
diff --git 
a/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapperTest.java
 
b/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapperTest.java
new file mode 100644
index 0000000000..562cc35cea
--- /dev/null
+++ 
b/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/HttpServletRequestWrapperTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.felix.http.jakartawrappers;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class HttpServletRequestWrapperTest {
+
+    @Test public void testGetPart() throws Exception {
+        final javax.servlet.http.HttpServletRequest orig = 
Mockito.mock(javax.servlet.http.HttpServletRequest.class);
+        final HttpServletRequestWrapper wrapper = new 
HttpServletRequestWrapper(orig);
+        assertNull(wrapper.getPart("test"));
+
+        
Mockito.when(orig.getPart("foo")).thenReturn(Mockito.mock(javax.servlet.http.Part.class));
+        assertNotNull(wrapper.getPart("foo"));
+    }
+}
diff --git 
a/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/ServletRequestTest.java
 
b/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/ServletRequestTest.java
index 322068352f..d6a1f41979 100644
--- 
a/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/ServletRequestTest.java
+++ 
b/http/wrappers/src/test/java/org/apache/felix/http/jakartawrappers/ServletRequestTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.felix.http.jakartawrappers;
 
-import jakarta.servlet.ServletRequest;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -38,14 +36,15 @@ import javax.servlet.DispatcherType;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
 import org.junit.Test;
 
 public class ServletRequestTest {
 
-    private javax.servlet.ServletRequest createRequest() {
-        return new javax.servlet.ServletRequest() {
+    private ServletRequest createRequest() {
+        return new ServletRequest() {
 
             final private Map<String, Object> attributes = new HashMap<>();
 
@@ -229,7 +228,7 @@ public class ServletRequestTest {
             }
 
             @Override
-            public AsyncContext startAsync(javax.servlet.ServletRequest 
servletRequest, ServletResponse servletResponse)
+            public AsyncContext startAsync(ServletRequest servletRequest, 
ServletResponse servletResponse)
                     throws IllegalStateException {
                 return null;
             }            
@@ -237,12 +236,36 @@ public class ServletRequestTest {
     }
 
     @Test public void testAttributeGetterSetter() {
-        final javax.servlet.ServletRequest sr = createRequest();
-        final ServletRequest req = ServletRequestWrapper.getWrapper(sr);
+        final ServletRequest sr = createRequest();
+        final jakarta.servlet.ServletRequest req = 
ServletRequestWrapper.getWrapper(sr);
+        req.setAttribute("foo", "bar");
+        assertEquals("bar", req.getAttribute("foo"));
+        req.setAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE, 
"500");
+        assertEquals("500", 
req.getAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+
+        final List<String> names = Collections.list(req.getAttributeNames());
+        assertEquals(2, names.size());
+        assertTrue(names.contains("foo"));
+        
assertTrue(names.contains(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+
+        req.removeAttribute("foo");
+        assertNull(req.getAttribute("foo"));
+        
req.removeAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE);
+        
assertNull(req.getAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+        assertFalse(req.getAttributeNames().hasMoreElements());
+    }
+
+    @Test public void testAttributeGetterSetterMultipleLayers() {
+        final ServletRequest sr = createRequest();
+        final jakarta.servlet.ServletRequest layer1 = new 
jakarta.servlet.ServletRequestWrapper(ServletRequestWrapper.getWrapper(sr));
+        final ServletRequest layer2 = new 
javax.servlet.ServletRequestWrapper(org.apache.felix.http.javaxwrappers.ServletRequestWrapper.getWrapper(layer1));
+        final jakarta.servlet.ServletRequest req = 
ServletRequestWrapper.getWrapper(layer2);
         req.setAttribute("foo", "bar");
         assertEquals("bar", req.getAttribute("foo"));
         req.setAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE, 
"500");
         assertEquals("500", 
req.getAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+        assertEquals("500", 
req.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
+        assertEquals("500", 
sr.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
 
         final List<String> names = Collections.list(req.getAttributeNames());
         assertEquals(2, names.size());
@@ -253,15 +276,16 @@ public class ServletRequestTest {
         assertNull(req.getAttribute("foo"));
         
req.removeAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE);
         
assertNull(req.getAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+        assertNull(req.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
         assertFalse(req.getAttributeNames().hasMoreElements());
     }
 
     @Test public void testProvidedAttributes() {
-        final javax.servlet.ServletRequest sr = createRequest();
-        sr.setAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE, 
"500");
+        final ServletRequest sr = createRequest();
+        sr.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, "500");
         sr.setAttribute("foo", "bar");
 
-        final ServletRequest req = ServletRequestWrapper.getWrapper(sr);
+        final jakarta.servlet.ServletRequest req = 
ServletRequestWrapper.getWrapper(sr);
         assertEquals("bar", req.getAttribute("foo"));
         assertEquals("500", 
req.getAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE));
 
diff --git 
a/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapperTest.java
 
b/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapperTest.java
new file mode 100644
index 0000000000..3900094e4f
--- /dev/null
+++ 
b/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/HttpServletRequestWrapperTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.felix.http.javaxwrappers;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.Part;
+
+public class HttpServletRequestWrapperTest {
+
+    @Test public void testGetPart() throws Exception {
+        final HttpServletRequest orig = Mockito.mock(HttpServletRequest.class);
+        final HttpServletRequestWrapper wrapper = new 
HttpServletRequestWrapper(orig);
+        assertNull(wrapper.getPart("test"));
+
+        Mockito.when(orig.getPart("foo")).thenReturn(Mockito.mock(Part.class));
+        assertNotNull(wrapper.getPart("foo"));
+    }
+}
diff --git 
a/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/ServletRequestTest.java
 
b/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/ServletRequestTest.java
index 54bd7ecc95..f8831a6ea2 100644
--- 
a/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/ServletRequestTest.java
+++ 
b/http/wrappers/src/test/java/org/apache/felix/http/javaxwrappers/ServletRequestTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.felix.http.javaxwrappers;
 
-import javax.servlet.ServletRequest;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
@@ -38,14 +36,15 @@ import jakarta.servlet.DispatcherType;
 import jakarta.servlet.RequestDispatcher;
 import jakarta.servlet.ServletContext;
 import jakarta.servlet.ServletInputStream;
+import jakarta.servlet.ServletRequest;
 import jakarta.servlet.ServletResponse;
 
 import org.junit.Test;
 
 public class ServletRequestTest {
 
-    private jakarta.servlet.ServletRequest createRequest() {
-        return new jakarta.servlet.ServletRequest() {
+    private ServletRequest createRequest() {
+        return new ServletRequest() {
 
             final private Map<String, Object> attributes = new HashMap<>();
 
@@ -229,7 +228,7 @@ public class ServletRequestTest {
             }
 
             @Override
-            public AsyncContext startAsync(jakarta.servlet.ServletRequest 
servletRequest, ServletResponse servletResponse)
+            public AsyncContext startAsync(ServletRequest servletRequest, 
ServletResponse servletResponse)
                     throws IllegalStateException {
                 return null;
             }
@@ -237,12 +236,35 @@ public class ServletRequestTest {
     }
 
     @Test public void testAttributeGetterSetter() {
-        final jakarta.servlet.ServletRequest sr = createRequest();
-        final ServletRequest req = ServletRequestWrapper.getWrapper(sr);
+        final ServletRequest sr = createRequest();
+        final javax.servlet.ServletRequest req = 
ServletRequestWrapper.getWrapper(sr);
+        req.setAttribute("foo", "bar");
+        assertEquals("bar", req.getAttribute("foo"));
+        req.setAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE, 
"500");
+
+        final List<String> names = Collections.list(req.getAttributeNames());
+        assertEquals(2, names.size());
+        assertTrue(names.contains("foo"));
+        
assertTrue(names.contains(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+
+        req.removeAttribute("foo");
+        assertNull(req.getAttribute("foo"));
+        req.removeAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE);
+        
assertNull(req.getAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+        assertFalse(req.getAttributeNames().hasMoreElements());
+    }
+
+    @Test public void testAttributeGetterSetterMultipleLayers() {
+        final ServletRequest sr = createRequest();
+        final javax.servlet.ServletRequest layer1 = new 
javax.servlet.ServletRequestWrapper(ServletRequestWrapper.getWrapper(sr));
+        final ServletRequest layer2 = new 
jakarta.servlet.ServletRequestWrapper(org.apache.felix.http.jakartawrappers.ServletRequestWrapper.getWrapper(layer1));
+        final javax.servlet.ServletRequest req = 
ServletRequestWrapper.getWrapper(layer2);
         req.setAttribute("foo", "bar");
         assertEquals("bar", req.getAttribute("foo"));
         req.setAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE, 
"500");
         assertEquals("500", 
req.getAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+        assertEquals("500", 
req.getAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE));
+        assertEquals("500", 
sr.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
 
         final List<String> names = Collections.list(req.getAttributeNames());
         assertEquals(2, names.size());
@@ -257,11 +279,11 @@ public class ServletRequestTest {
     }
 
     @Test public void testProvidedAttributes() {
-        final jakarta.servlet.ServletRequest sr = createRequest();
-        sr.setAttribute(jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE, 
"500");
+        final ServletRequest sr = createRequest();
+        sr.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, "500");
         sr.setAttribute("foo", "bar");
 
-        final ServletRequest req = ServletRequestWrapper.getWrapper(sr);
+        final javax.servlet.ServletRequest req = 
ServletRequestWrapper.getWrapper(sr);
         assertEquals("bar", req.getAttribute("foo"));
         assertEquals("500", 
req.getAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE));
 

Reply via email to