You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2022/06/07 00:42:41 UTC

[cxf] branch 3.4.x-fixes updated (b83a9bf8c1 -> 5b479390b2)

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

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


    from b83a9bf8c1 Recording .gitmergeinfo Changes
     new 3fcbf9a6c8 CXF-8478: fixing jaxrs.ee.rs.container.requestcontext setRequestUriTwoUrisTest (#953)
     new 5b479390b2 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/ContainerRequestContextImpl.java   | 19 ++++++++++++++++++-
 .../java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java   |  2 +-
 .../java/org/apache/cxf/jaxrs/utils/HttpUtils.java    | 14 ++++++++++++++
 .../org/apache/cxf/systest/jaxrs/BookServer20.java    |  2 ++
 .../systest/jaxrs/JAXRS20ClientServerBookTest.java    |  6 ++++++
 6 files changed, 42 insertions(+), 2 deletions(-)


[cxf] 02/02: Recording .gitmergeinfo Changes

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5b479390b2208730e1011816285e0913ac25f22a
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Mon Jun 6 20:42:31 2022 -0400

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

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 2f7cb1c87b..2e2fe7be5c 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -389,6 +389,7 @@ M dff93aa931d7c4d671c458f63f450c0a4d5fea3f
 M e071fd24c474d37e90b23a2da3561fa2f0525628
 M e0dbc85b5b3383c48fecb97ac11608d7b8c82cc5
 M e31815b50c433a91bac93871bec801c34df2ff57
+M e32cfd0329f1e0405f8b46395dbeac5c1c70dd6d
 M e3bac521f80ebca0fa734d44e49310b1d1d7315f
 M e474ee7d98eb782d1729c1e363ec91706c346069
 M e47b201c3032f64082e9173c0f02d54698388c06


[cxf] 01/02: CXF-8478: fixing jaxrs.ee.rs.container.requestcontext setRequestUriTwoUrisTest (#953)

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 3fcbf9a6c8fc9b01098704bccf3ed7048adb43e3
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Mon Jun 6 20:32:47 2022 -0400

    CXF-8478: fixing jaxrs.ee.rs.container.requestcontext setRequestUriTwoUrisTest (#953)
    
    (cherry picked from commit e32d69cb12f6a2ee84980f1a12e00bcd0d3711dc)
    (cherry picked from commit e32cfd0329f1e0405f8b46395dbeac5c1c70dd6d)
---
 .../cxf/jaxrs/impl/ContainerRequestContextImpl.java   | 19 ++++++++++++++++++-
 .../java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java   |  2 +-
 .../java/org/apache/cxf/jaxrs/utils/HttpUtils.java    | 14 ++++++++++++++
 .../org/apache/cxf/systest/jaxrs/BookServer20.java    |  2 ++
 .../systest/jaxrs/JAXRS20ClientServerBookTest.java    |  6 ++++++
 5 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
index a13f6ee1ea..b3a65bae97 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
@@ -28,6 +28,7 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.DelegatingInputStream;
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
@@ -38,6 +39,7 @@ public class ContainerRequestContextImpl extends AbstractRequestContextImpl
     implements ContainerRequestContext {
 
     private static final String ENDPOINT_ADDRESS_PROPERTY = "org.apache.cxf.transport.endpoint.address";
+    private static final String ENDPOINT_URI_PROPERTY = "org.apache.cxf.transport.endpoint.uri";
 
     private boolean preMatch;
     public ContainerRequestContextImpl(Message message, boolean preMatch, boolean responseContext) {
@@ -108,7 +110,15 @@ public class ContainerRequestContextImpl extends AbstractRequestContextImpl
             String baseUriString = new UriInfoImpl(m).getBaseUri().toString();
             String requestUriString = requestUri.toString();
             if (!requestUriString.startsWith(baseUriString)) {
-                setRequestUri(requestUri, URI.create("/"));
+                String path = requestUri.getRawPath();
+                if (StringUtils.isEmpty(path)) {
+                    path = "/";
+                }
+                String query = requestUri.getRawQuery();
+                if (!StringUtils.isEmpty(query)) {
+                    path = path + "?" + query;
+                }
+                setRequestUri(requestUri.resolve("/"), URI.create(path));
                 return;
             }
             requestUriString = requestUriString.substring(baseUriString.length());
@@ -139,7 +149,14 @@ public class ContainerRequestContextImpl extends AbstractRequestContextImpl
         if (servletRequest != null) {
             ((javax.servlet.http.HttpServletRequest)servletRequest)
                 .setAttribute(ENDPOINT_ADDRESS_PROPERTY, baseUri.toString());
+            
+            // The base URI and request URI should be treated differently
+            if (requestUri.isAbsolute() && baseUri.resolve("/").compareTo(requestUri.resolve("/")) != 0) {
+                ((javax.servlet.http.HttpServletRequest)servletRequest)
+                    .setAttribute(ENDPOINT_URI_PROPERTY, requestUri.resolve("/"));
+            }
         }
+        
     }
 
     @Override
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
index ccce59ff28..47dc26e2ad 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
@@ -219,7 +219,7 @@ public class UriInfoImpl implements UriInfo {
     }
 
     private String getAbsolutePathAsString() {
-        String address = getBaseUri().toString();
+        String address = URI.create(HttpUtils.getEndpointUri(message)).toString();
         if (MessageUtils.isRequestor(message)) {
             return address;
         }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
index bc2f36396d..9d0da677fc 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
@@ -485,6 +485,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 = null;
         Destination d = m.getExchange().getDestination();
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
index d9140e9095..a4354fd0f8 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
@@ -167,6 +167,8 @@ public class BookServer20 extends AbstractBusTestServerBase {
 
             if ("wrongpath".equals(path)) {
                 context.setRequestUri(URI.create("/bookstore/bookheaders/simple"));
+            } else if ("absolutepath".equals(path)) {
+                context.setRequestUri(URI.create("http://xx.yy:888/bookstore/bookheaders/simple?q=1"));
             } else if ("throwException".equals(path)) {
                 context.setProperty("filterexception", "prematch");
                 throw new InternalServerErrorException(
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index c350f1adad..d791b3f346 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -355,6 +355,12 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         String address = "http://localhost:" + PORT + "/wrongpath";
         doTestGetBookAsync(address, false);
     }
+    
+    @Test
+    public void testGetBookAbsolutePathAsync() throws Exception {
+        String address = "http://localhost:" + PORT + "/absolutepath";
+        doTestGetBookAsync(address, false);
+    }
 
     @Test
     public void testPostCollectionGenericEntity() throws Exception {