You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rz...@apache.org on 2022/10/04 18:52:57 UTC

[tomee] branch tomee-8.x updated: TOMEE-4057 - Ports the changes from CXF-8478 and CXF-8688 to our patched version of CXF

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

rzo1 pushed a commit to branch tomee-8.x
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/tomee-8.x by this push:
     new 2815ce5a76 TOMEE-4057 - Ports the changes from CXF-8478 and CXF-8688 to our patched version of CXF
2815ce5a76 is described below

commit 2815ce5a76ea43e4dd540dad5cc265a294d516e3
Author: Richard Zowalla <13...@users.noreply.github.com>
AuthorDate: Tue Oct 4 19:27:51 2022 +0200

    TOMEE-4057 - Ports the changes from CXF-8478 and CXF-8688 to our patched version of CXF
---
 .../java/org/apache/cxf/jaxrs/utils/HttpUtils.java | 43 ++++++++++++++++++----
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
index aa42382348..ff6267a63f 100644
--- a/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ b/deps/cxf-shade/src/patch/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
@@ -94,12 +94,14 @@ public final class HttpUtils {
     // there are more of such characters, ex, '*' but '*' is not affected by UrlEncode
     private static final String PATH_RESERVED_CHARACTERS = "=@/:!$&\'(),;~";
     private static final String QUERY_RESERVED_CHARACTERS = "?/,";
-    
+
     private static final Set<String> KNOWN_HTTP_VERBS_WITH_NO_REQUEST_CONTENT =
         new HashSet<>(Arrays.asList(new String[]{"GET", "HEAD", "OPTIONS", "TRACE"}));
     private static final Set<String> KNOWN_HTTP_VERBS_WITH_NO_RESPONSE_CONTENT =
         new HashSet<>(Arrays.asList(new String[]{"HEAD", "OPTIONS"}));
 
+    private static final Pattern HTTP_SCHEME_PATTERN = Pattern.compile("^(?i)(http|https)$");
+
     private HttpUtils() {
     }
 
@@ -303,7 +305,7 @@ public final class HttpUtils {
         if (value == null) {
             return null;
         }
-        final String language;
+        String language = null;
         String locale = null;
         int index = value.indexOf('-');
         if (index == 0 || index == value.length() - 1) {
@@ -372,6 +374,13 @@ public final class HttpUtils {
         return URI.create(base + relativePath);
     }
 
+    public static void setHttpRequestURI(Message message, String uriTemplate) {
+        HttpServletRequest request =
+                (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
+        request.setAttribute("org.springframework.web.servlet.HandlerMapping.bestMatchingPattern", uriTemplate);
+    }
+
+
     public static URI toAbsoluteUri(URI u, Message message) {
         HttpServletRequest request =
             (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
@@ -471,8 +480,10 @@ public final class HttpUtils {
             URI uri = new URI(endpointAddress);
             String path = uri.getRawPath();
             String scheme = uri.getScheme();
-            if (scheme != null && !scheme.startsWith(HttpUtils.HTTP_SCHEME)
-                && HttpUtils.isHttpRequest(m)) {
+            // RFC-3986: the scheme and host are case-insensitive and therefore should
+            // be normalized to lowercase.
+            if (scheme != null && !scheme.toLowerCase().startsWith(HttpUtils.HTTP_SCHEME)
+                    && HttpUtils.isHttpRequest(m)) {
                 path = HttpUtils.toAbsoluteUri(path, m).getRawPath();
             }
             return (path == null || path.length() == 0) ? "/" : path;
@@ -481,6 +492,20 @@ public final class HttpUtils {
         }
     }
 
+    public static String getEndpointUri(Message m) {
+        final Object servletRequest = m.get(AbstractHTTPDestination.HTTP_REQUEST);
+
+        if (servletRequest != null) {
+            final Object property = ((javax.servlet.http.HttpServletRequest)servletRequest)
+                    .getAttribute("org.apache.cxf.transport.endpoint.uri");
+            if (property != null) {
+                return property.toString();
+            }
+        }
+
+        return getEndpointAddress(m);
+    }
+
     public static String getEndpointAddress(Message m) {
         String address;
         Destination d = m.getExchange().getDestination();
@@ -594,7 +619,7 @@ public final class HttpUtils {
 
     public static String getMediaTypeCharsetParameter(MediaType mt) {
         String charset = mt.getParameters().get(CHARSET_PARAMETER);
-        if (charset != null && charset.startsWith(DOUBLE_QUOTE) 
+        if (charset != null && charset.startsWith(DOUBLE_QUOTE)
             && charset.endsWith(DOUBLE_QUOTE) && charset.length() > 1) {
             charset = charset.substring(1,  charset.length() - 1);
         }
@@ -675,7 +700,7 @@ public final class HttpUtils {
 
         return false;
     }
-    
+
     public static <T> T createServletResourceValue(Message m, Class<T> clazz) {
 
         Object value = null;
@@ -697,8 +722,12 @@ public final class HttpUtils {
     public static boolean isMethodWithNoRequestContent(String method) {
         return KNOWN_HTTP_VERBS_WITH_NO_REQUEST_CONTENT.contains(method);
     }
-    
+
     public static boolean isMethodWithNoResponseContent(String method) {
         return KNOWN_HTTP_VERBS_WITH_NO_RESPONSE_CONTENT.contains(method);
     }
+
+    public static boolean isHttpScheme(final String scheme) {
+        return scheme != null && HTTP_SCHEME_PATTERN.matcher(scheme).matches();
+    }
 }