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/03/26 16:24:18 UTC

[cxf] branch 3.4.x-fixes updated (d15de3d -> a3c249c)

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 d15de3d  Recording .gitmergeinfo Changes
     new 06a1888  CXF-8522: jaxrs.spec.resource.requestmatching consumesOnResourceLocatorTest & other subresource test cases (#925)
     new a3c249c  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                                      |  2 ++
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java     |  9 +++++--
 .../cxf/systest/jaxrs/BookResourceLocator.java     | 20 ++++++++------
 .../apache/cxf/systest/jaxrs/BookServerSub.java    | 31 +++++++++++++++++++++-
 .../cxf/systest/jaxrs/BookStoreSubObject.java      | 14 +++++++++-
 .../jaxrs/JAXRSClientServerSubBookTest.java        | 24 ++++++++++++++++-
 6 files changed, 87 insertions(+), 13 deletions(-)
 copy distribution/src/main/release/samples/jax_rs/minimal_osgi/src/main/java/minimalosgi/SampleResource.java => systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookResourceLocator.java (77%)

[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 a3c249c2d6f2b929752e1470187797cbcb6d51d2
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sat Mar 26 12:24:06 2022 -0400

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

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 7a66634..755bccc 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -127,6 +127,7 @@ B fe058a4c83590e7a768e5be32c94622cbe1a3b6b
 M 0099eed503ce519c7514ac63b67758882f00e14f
 M 011debd91b16215245e039309e620699042a9f4b
 M 0320ad320ba88a123a5296a8060d3ac1794009f6
+M 04068cd8430c98ea5a4986c36353b1c22d2362dc
 M 049ed3c49a05f9997111afd66ba583dc2b4630f2
 M 04c73ab64486b3806c3cc78d5196d2c52280ca89
 M 0903bdd2f5f91de71425dedde8c5d7fbf44d297f
@@ -360,6 +361,7 @@ M ef90164f48e6cea81f98bcda3dcce3b33c053ea0
 M efc5d35498f582335821cc6a2b750df935295f14
 M f02e401b3e46c42b19db22300691f2197b0abfb7
 M f0e67e2874bc23336b5b445ddfc9e11e7357adc7
+M f2c3963682e6ff13ebe75bb21f725aaeac4d33d5
 M f7300e4a3df847c567376734579de7a240ac4111
 M fb7821164ec6d7fb98dc3f8caea67465db230a14
 M fcafcae2809e728c46164119af2e9976889a65d2

[cxf] 01/02: CXF-8522: jaxrs.spec.resource.requestmatching consumesOnResourceLocatorTest & other subresource test cases (#925)

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 06a18887b054a5833e0618eb95af06c80e13355b
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sat Mar 26 12:03:56 2022 -0400

    CXF-8522: jaxrs.spec.resource.requestmatching consumesOnResourceLocatorTest & other subresource test cases (#925)
    
    (cherry picked from commit a0f912b7a54297f4e405a5c8e09df682ece07c9a)
    (cherry picked from commit f2c3963682e6ff13ebe75bb21f725aaeac4d33d5)
    
    # Conflicts:
    #	systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerSub.java
---
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java     |  9 +++++--
 ...toreSubObject.java => BookResourceLocator.java} | 24 ++++++++++-------
 .../apache/cxf/systest/jaxrs/BookServerSub.java    | 31 +++++++++++++++++++++-
 .../cxf/systest/jaxrs/BookStoreSubObject.java      | 14 +++++++++-
 .../jaxrs/JAXRSClientServerSubBookTest.java        | 24 ++++++++++++++++-
 5 files changed, 88 insertions(+), 14 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 908fa9d..acce616 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -510,7 +510,7 @@ public final class JAXRSUtils {
         int pathMatched = 0;
         int methodMatched = 0;
         int consumeMatched = 0;
-
+        
         List<OperationResourceInfo> finalPathSubresources = null;
         for (Map.Entry<ClassResourceInfo, MultivaluedMap<String, String>> rEntry : matchedResources.entrySet()) {
             ClassResourceInfo resource = rEntry.getKey();
@@ -561,7 +561,12 @@ public final class JAXRSUtils {
                 LOG.fine(matchMessageLogSupplier(ori, path, httpMethod, requestType, acceptContentTypes, added));
             }
         }
-        if (finalPathSubresources != null && pathMatched > 0
+        
+        // We may get several matching candidates with different HTTP methods which match subresources
+        // and resources. Before excluding subresources, let us make sure we have at least one matching
+        // HTTP method candidate.
+        boolean isOptions = HttpMethod.OPTIONS.equalsIgnoreCase(httpMethod);
+        if (finalPathSubresources != null && (methodMatched > 0 || isOptions)
             && !MessageUtils.getContextualBoolean(message, KEEP_SUBRESOURCE_CANDIDATES, false)) {
             for (OperationResourceInfo key : finalPathSubresources) {
                 candidateList.remove(key);
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookResourceLocator.java
similarity index 71%
copy from systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java
copy to systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookResourceLocator.java
index 34b8101..76fed9a 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookResourceLocator.java
@@ -19,16 +19,22 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
 
-import javax.ws.rs.Path;
-
-@Path("/bookstore")
-public class BookStoreSubObject {
-
-    @Path("/booksubresourceobject")
-    public Object getBookSubResourceObject() throws BookNotFoundFault {
+public class BookResourceLocator {
+    @GET
+    public Book get() {
         return new Book();
     }
-}
-
 
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public Book post() {
+        return get();
+    }
+}
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerSub.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerSub.java
index 0156cd2..2df764e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerSub.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerSub.java
@@ -19,6 +19,12 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -27,10 +33,33 @@ public class BookServerSub extends AbstractBusTestServerBase {
     public static final String PORT = allocatePort(BookServerSub.class);
 
     org.apache.cxf.endpoint.Server server;
-    
+
+    @Provider
+    public static class ExceptionMatcher implements ExceptionMapper<WebApplicationException> {
+        @Override
+        public Response toResponse(WebApplicationException exception) {
+            Response response = exception.getResponse();
+            int status = response == null ? Status.INTERNAL_SERVER_ERROR.getStatusCode() : response.getStatus();
+            if (response != null && response.getEntity() != null) {
+                return response;
+            }
+        
+            switch (status) {
+            case 404:
+            case 405:
+            case 406:
+            case 415:
+                return Response.status(status).entity(String.valueOf(status)).build();
+            default:
+                return response;
+            }
+        }
+    }
+
     protected void run() {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setStaticSubresourceResolution(true);
+        sf.setProvider(new ExceptionMatcher());
         sf.setResourceClasses(BookStoreSubObject.class);
         sf.setResourceProvider(BookStoreSubObject.class,
                                new SingletonResourceProvider(new BookStoreSubObject(), true));
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java
index 34b8101..33cf177 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSubObject.java
@@ -20,15 +20,27 @@
 package org.apache.cxf.systest.jaxrs;
 
 
+import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 
 @Path("/bookstore")
 public class BookStoreSubObject {
-
     @Path("/booksubresourceobject")
     public Object getBookSubResourceObject() throws BookNotFoundFault {
         return new Book();
     }
+    
+    @Path("consumeslocator")
+    public BookResourceLocator consumeslocator() {
+        return new BookResourceLocator();
+    }
+    
+    @GET
+    @Path("{id}")
+    public Book book(@PathParam("id") Long id) {
+        return new Book("Book", id);
+    }
 }
 
 
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSubBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSubBookTest.java
index 8b55de4..0ccbfca 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSubBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSubBookTest.java
@@ -19,6 +19,12 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -26,7 +32,9 @@ import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class JAXRSClientServerSubBookTest extends AbstractBusClientServerTestBase {
@@ -44,9 +52,23 @@ public class JAXRSClientServerSubBookTest extends AbstractBusClientServerTestBas
     public void testGetChapterFromBookSubObject() throws Exception {
         WebClient wc =
             WebClient.create("http://localhost:" + PORT + "/bookstore/booksubresourceobject/chaptersobject/sub/1");
-        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L);
         Chapter c = wc.accept("application/xml").get(Chapter.class);
         assertNotNull(c);
     }
 
+    @Test
+    public void testSubresourceLocatorFromBookSubObject() throws Exception {
+        final Client c = ClientBuilder.newClient();
+
+        // There are two matching endpoints with different HTTP methods:
+        //  - POST for BookSubObject /consumeslocator"
+        //  - GET for BookStore /{id}
+        // The test verifies that in this case for the POST method the correct subresource
+        // locator is picked.
+        final WebTarget wc = c.target("http://localhost:" + PORT + "/bookstore/consumeslocator");
+        try (Response r = wc.request().header("Content-Type", MediaType.APPLICATION_ATOM_XML).post(null)) {
+            assertThat(r.getStatus(), equalTo(Response.Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode()));
+            assertThat(Integer.toString(r.getStatus()), equalTo(r.readEntity(String.class)));
+        }
+    }
 }