You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2022/02/20 10:07:16 UTC

[felix-dev] 03/19: Add missing attribute mappings

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

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

commit 04d7a0045e891babb7cba5fa83af8da00b824282
Author: Carsten Ziegeler <cz...@adobe.com>
AuthorDate: Mon Jan 3 06:59:23 2022 +0100

    Add missing attribute mappings
---
 .../jakartawrappers/HttpServletMappingWrapper.java | 73 ++++++++++++++++++++++
 .../jakartawrappers/ServletRequestWrapper.java     | 42 +++++++++++++
 .../javaxwrappers/HttpServletMappingWrapper.java   | 72 +++++++++++++++++++++
 .../javaxwrappers/ServletRequestWrapper.java       | 43 +++++++++++++
 4 files changed, 230 insertions(+)

diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/HttpServletMappingWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/HttpServletMappingWrapper.java
new file mode 100644
index 0000000..22a5aea
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/HttpServletMappingWrapper.java
@@ -0,0 +1,73 @@
+/*
+ * 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.base.internal.jakartawrappers;
+
+import org.jetbrains.annotations.NotNull;
+
+import jakarta.servlet.http.HttpServletMapping;
+import jakarta.servlet.http.MappingMatch;
+
+/**
+ * Http Mapping wrapper
+ */
+public class HttpServletMappingWrapper implements HttpServletMapping {
+
+    private final javax.servlet.http.HttpServletMapping mapping;
+
+    /**
+     * Create new wrapper
+     * @param c Wrapped mapper
+     */
+    public HttpServletMappingWrapper(@NotNull final javax.servlet.http.HttpServletMapping c) {
+        this.mapping = c;
+    }
+
+    @Override
+    public String getMatchValue() {
+        return mapping.getMatchValue();
+    }
+
+    @Override
+    public String getPattern() {
+        return mapping.getPattern();
+    }
+
+    @Override
+    public String getServletName() {
+        return mapping.getServletName();
+    }
+
+    @Override
+    public MappingMatch getMappingMatch() {
+        switch (mapping.getMappingMatch()) {
+        case CONTEXT_ROOT : return MappingMatch.CONTEXT_ROOT;
+        case DEFAULT : return MappingMatch.DEFAULT;
+        case EXACT : return MappingMatch.EXACT;
+        case EXTENSION : return MappingMatch.EXTENSION;
+        case PATH : return MappingMatch.PATH;
+        }
+        return null;
+    }
+
+    /**
+     * Get the wrapped mapping
+     * @return The mapping
+     */
+    public javax.servlet.http.HttpServletMapping getMapping() {
+        return this.mapping;
+    }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/ServletRequestWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/ServletRequestWrapper.java
index c787525..0d42f91 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/ServletRequestWrapper.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/jakartawrappers/ServletRequestWrapper.java
@@ -16,6 +16,12 @@
  */
 package org.apache.felix.http.base.internal.jakartawrappers;
 
+import static jakarta.servlet.AsyncContext.ASYNC_CONTEXT_PATH;
+import static jakarta.servlet.AsyncContext.ASYNC_MAPPING;
+import static jakarta.servlet.AsyncContext.ASYNC_PATH_INFO;
+import static jakarta.servlet.AsyncContext.ASYNC_QUERY_STRING;
+import static jakarta.servlet.AsyncContext.ASYNC_REQUEST_URI;
+import static jakarta.servlet.AsyncContext.ASYNC_SERVLET_PATH;
 import static jakarta.servlet.RequestDispatcher.ERROR_EXCEPTION;
 import static jakarta.servlet.RequestDispatcher.ERROR_EXCEPTION_TYPE;
 import static jakarta.servlet.RequestDispatcher.ERROR_MESSAGE;
@@ -23,11 +29,13 @@ import static jakarta.servlet.RequestDispatcher.ERROR_REQUEST_URI;
 import static jakarta.servlet.RequestDispatcher.ERROR_SERVLET_NAME;
 import static jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE;
 import static jakarta.servlet.RequestDispatcher.FORWARD_CONTEXT_PATH;
+import static jakarta.servlet.RequestDispatcher.FORWARD_MAPPING;
 import static jakarta.servlet.RequestDispatcher.FORWARD_PATH_INFO;
 import static jakarta.servlet.RequestDispatcher.FORWARD_QUERY_STRING;
 import static jakarta.servlet.RequestDispatcher.FORWARD_REQUEST_URI;
 import static jakarta.servlet.RequestDispatcher.FORWARD_SERVLET_PATH;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_CONTEXT_PATH;
+import static jakarta.servlet.RequestDispatcher.INCLUDE_MAPPING;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_PATH_INFO;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_QUERY_STRING;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_REQUEST_URI;
@@ -89,11 +97,24 @@ public class ServletRequestWrapper implements ServletRequest {
         return this.request;
     }
 
+    private Object wrapHttpServletMapping(final Object value) {
+        if ( value instanceof org.apache.felix.http.base.internal.javaxwrappers.HttpServletMappingWrapper ) {
+            return ((org.apache.felix.http.base.internal.javaxwrappers.HttpServletMappingWrapper)value).getMapping();
+        }
+        if ( value instanceof javax.servlet.http.HttpServletMapping ) {
+            return new HttpServletMappingWrapper((javax.servlet.http.HttpServletMapping)value);
+        }
+        return value;
+    }
+
     @Override
     public Object getAttribute(final String name) {
         if ( FORWARD_CONTEXT_PATH.equals(name) ) {
             return this.request.getAttribute(javax.servlet.RequestDispatcher.FORWARD_CONTEXT_PATH);
 
+        } else if ( FORWARD_MAPPING.equals(name) ) {
+            return wrapHttpServletMapping(this.request.getAttribute(javax.servlet.RequestDispatcher.FORWARD_MAPPING));
+
         } else if ( FORWARD_PATH_INFO.equals(name) ) {
             return this.request.getAttribute(javax.servlet.RequestDispatcher.FORWARD_PATH_INFO);
 
@@ -109,6 +130,9 @@ public class ServletRequestWrapper implements ServletRequest {
         } else if ( INCLUDE_CONTEXT_PATH.equals(name) ) {
             return this.request.getAttribute(javax.servlet.RequestDispatcher.INCLUDE_CONTEXT_PATH);
 
+        } else if ( INCLUDE_MAPPING.equals(name) ) {
+            return wrapHttpServletMapping(this.request.getAttribute(javax.servlet.RequestDispatcher.INCLUDE_MAPPING));
+
         } else if ( INCLUDE_PATH_INFO.equals(name) ) {
             return this.request.getAttribute(javax.servlet.RequestDispatcher.INCLUDE_PATH_INFO);
 
@@ -138,6 +162,24 @@ public class ServletRequestWrapper implements ServletRequest {
 
         } else if ( ERROR_STATUS_CODE.equals(name) ) {
             return this.request.getAttribute(javax.servlet.RequestDispatcher.ERROR_STATUS_CODE);
+
+        } else if ( ASYNC_CONTEXT_PATH.equals(name) ) {
+            return this.request.getAttribute(javax.servlet.AsyncContext.ASYNC_CONTEXT_PATH);
+
+        } else if ( ASYNC_MAPPING.equals(name) ) {
+            return wrapHttpServletMapping(this.request.getAttribute(javax.servlet.AsyncContext.ASYNC_MAPPING));
+
+        } else if ( ASYNC_PATH_INFO.equals(name) ) {
+            return this.request.getAttribute(javax.servlet.AsyncContext.ASYNC_PATH_INFO);
+
+        } else if ( ASYNC_QUERY_STRING.equals(name) ) {
+            return this.request.getAttribute(javax.servlet.AsyncContext.ASYNC_QUERY_STRING);
+
+        } else if ( ASYNC_REQUEST_URI.equals(name) ) {
+            return this.request.getAttribute(javax.servlet.AsyncContext.ASYNC_REQUEST_URI);
+
+        } else if ( ASYNC_SERVLET_PATH.equals(name) ) {
+            return this.request.getAttribute(javax.servlet.AsyncContext.ASYNC_SERVLET_PATH);
         }
         return this.request.getAttribute(name);
     }
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/HttpServletMappingWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/HttpServletMappingWrapper.java
new file mode 100644
index 0000000..d8a8679
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/HttpServletMappingWrapper.java
@@ -0,0 +1,72 @@
+/*
+ * 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.base.internal.javaxwrappers;
+
+import org.jetbrains.annotations.NotNull;
+
+import jakarta.servlet.http.HttpServletMapping;
+
+/**
+ * Http Mapping wrapper
+ */
+public class HttpServletMappingWrapper implements javax.servlet.http.HttpServletMapping {
+
+    private final HttpServletMapping mapping;
+
+    /**
+     * Create new wrapper
+     * @param c Wrapped mapper
+     */
+    public HttpServletMappingWrapper(@NotNull final HttpServletMapping c) {
+        this.mapping = c;
+    }
+
+    @Override
+    public String getMatchValue() {
+        return mapping.getMatchValue();
+    }
+
+    @Override
+    public String getPattern() {
+        return mapping.getPattern();
+    }
+
+    @Override
+    public String getServletName() {
+        return mapping.getServletName();
+    }
+
+    @Override
+    public javax.servlet.http.MappingMatch getMappingMatch() {
+        switch (mapping.getMappingMatch()) {
+        case CONTEXT_ROOT : return javax.servlet.http.MappingMatch.CONTEXT_ROOT;
+        case DEFAULT : return javax.servlet.http.MappingMatch.DEFAULT;
+        case EXACT : return javax.servlet.http.MappingMatch.EXACT;
+        case EXTENSION : return javax.servlet.http.MappingMatch.EXTENSION;
+        case PATH : return javax.servlet.http.MappingMatch.PATH;
+        }
+        return null;
+    }
+
+    /**
+     * Get the wrapped mapping
+     * @return The mapping
+     */
+    public HttpServletMapping getMapping() {
+        return this.mapping;
+    }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/ServletRequestWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/ServletRequestWrapper.java
index d0bf473..73a2672 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/ServletRequestWrapper.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/javaxwrappers/ServletRequestWrapper.java
@@ -16,6 +16,12 @@
  */
 package org.apache.felix.http.base.internal.javaxwrappers;
 
+import static jakarta.servlet.AsyncContext.ASYNC_CONTEXT_PATH;
+import static jakarta.servlet.AsyncContext.ASYNC_MAPPING;
+import static jakarta.servlet.AsyncContext.ASYNC_PATH_INFO;
+import static jakarta.servlet.AsyncContext.ASYNC_QUERY_STRING;
+import static jakarta.servlet.AsyncContext.ASYNC_REQUEST_URI;
+import static jakarta.servlet.AsyncContext.ASYNC_SERVLET_PATH;
 import static jakarta.servlet.RequestDispatcher.ERROR_EXCEPTION;
 import static jakarta.servlet.RequestDispatcher.ERROR_EXCEPTION_TYPE;
 import static jakarta.servlet.RequestDispatcher.ERROR_MESSAGE;
@@ -23,11 +29,13 @@ import static jakarta.servlet.RequestDispatcher.ERROR_REQUEST_URI;
 import static jakarta.servlet.RequestDispatcher.ERROR_SERVLET_NAME;
 import static jakarta.servlet.RequestDispatcher.ERROR_STATUS_CODE;
 import static jakarta.servlet.RequestDispatcher.FORWARD_CONTEXT_PATH;
+import static jakarta.servlet.RequestDispatcher.FORWARD_MAPPING;
 import static jakarta.servlet.RequestDispatcher.FORWARD_PATH_INFO;
 import static jakarta.servlet.RequestDispatcher.FORWARD_QUERY_STRING;
 import static jakarta.servlet.RequestDispatcher.FORWARD_REQUEST_URI;
 import static jakarta.servlet.RequestDispatcher.FORWARD_SERVLET_PATH;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_CONTEXT_PATH;
+import static jakarta.servlet.RequestDispatcher.INCLUDE_MAPPING;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_PATH_INFO;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_QUERY_STRING;
 import static jakarta.servlet.RequestDispatcher.INCLUDE_REQUEST_URI;
@@ -45,6 +53,7 @@ import org.jetbrains.annotations.NotNull;
 
 import jakarta.servlet.RequestDispatcher;
 import jakarta.servlet.ServletRequest;
+import jakarta.servlet.http.HttpServletMapping;
 import jakarta.servlet.http.HttpServletRequest;
 
 /**
@@ -85,11 +94,24 @@ public class ServletRequestWrapper implements javax.servlet.ServletRequest {
         return this.request;
     }
 
+    private Object wrapHttpServletMapping(final Object value) {
+        if ( value instanceof org.apache.felix.http.base.internal.jakartawrappers.HttpServletMappingWrapper ) {
+            return ((org.apache.felix.http.base.internal.jakartawrappers.HttpServletMappingWrapper)value).getMapping();
+        }
+        if ( value instanceof HttpServletMapping ) {
+            return new HttpServletMappingWrapper((HttpServletMapping)value);
+        }
+        return value;
+    }
+
     @Override
     public Object getAttribute(final String name) {
         if ( javax.servlet.RequestDispatcher.FORWARD_CONTEXT_PATH.equals(name) ) {
             return this.request.getAttribute(FORWARD_CONTEXT_PATH);
 
+        } else if ( javax.servlet.RequestDispatcher.FORWARD_MAPPING.equals(name) ) {
+            return wrapHttpServletMapping(this.request.getAttribute(FORWARD_MAPPING));
+
         } else if ( javax.servlet.RequestDispatcher.FORWARD_PATH_INFO.equals(name) ) {
             return this.request.getAttribute(FORWARD_PATH_INFO);
 
@@ -105,6 +127,9 @@ public class ServletRequestWrapper implements javax.servlet.ServletRequest {
         } else if ( javax.servlet.RequestDispatcher.INCLUDE_CONTEXT_PATH.equals(name) ) {
             return this.request.getAttribute(INCLUDE_CONTEXT_PATH);
 
+        } else if ( javax.servlet.RequestDispatcher.INCLUDE_MAPPING.equals(name) ) {
+            return wrapHttpServletMapping(this.request.getAttribute(INCLUDE_MAPPING));
+
         } else if ( javax.servlet.RequestDispatcher.INCLUDE_PATH_INFO.equals(name) ) {
             return this.request.getAttribute(INCLUDE_PATH_INFO);
 
@@ -134,6 +159,24 @@ public class ServletRequestWrapper implements javax.servlet.ServletRequest {
 
         } else if ( javax.servlet.RequestDispatcher.ERROR_STATUS_CODE.equals(name) ) {
             return this.request.getAttribute(ERROR_STATUS_CODE);
+
+        } else if ( javax.servlet.AsyncContext.ASYNC_CONTEXT_PATH.equals(name) ) {
+            return this.request.getAttribute(ASYNC_CONTEXT_PATH);
+
+        } else if ( javax.servlet.AsyncContext.ASYNC_MAPPING.equals(name) ) {
+            return wrapHttpServletMapping(this.request.getAttribute(ASYNC_MAPPING));
+
+        } else if ( javax.servlet.AsyncContext.ASYNC_PATH_INFO.equals(name) ) {
+            return this.request.getAttribute(ASYNC_PATH_INFO);
+
+        } else if ( javax.servlet.AsyncContext.ASYNC_QUERY_STRING.equals(name) ) {
+            return this.request.getAttribute(ASYNC_QUERY_STRING);
+
+        } else if ( javax.servlet.AsyncContext.ASYNC_REQUEST_URI.equals(name) ) {
+            return this.request.getAttribute(ASYNC_REQUEST_URI);
+
+        } else if ( javax.servlet.AsyncContext.ASYNC_SERVLET_PATH.equals(name) ) {
+            return this.request.getAttribute(ASYNC_SERVLET_PATH);
         }
         return this.request.getAttribute(name);
     }