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 2021/08/07 00:51:47 UTC

[cxf] branch 3.3.x-fixes updated: CXF-8574: MP Rest call on jax-rs interface with long @Path and 3 pathparams causes error since (#831)

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

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


The following commit(s) were added to refs/heads/3.3.x-fixes by this push:
     new 9d3fec9  CXF-8574: MP Rest call on jax-rs interface with long @Path and 3 pathparams causes error since (#831)
9d3fec9 is described below

commit 9d3fec93d49eed63cbe303ba158ae2233a30fbe9
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Fri Aug 6 17:07:25 2021 -0400

    CXF-8574: MP Rest call on jax-rs interface with long @Path and 3 pathparams causes error since (#831)
    
    (cherry picked from commit 1fcd99b312cacade0a52f7577854d82854679301)
    (cherry picked from commit d39eabba4b2d6f34eaf47140a41e961f84367316)
---
 .../client/proxy/MicroProfileClientProxyImpl.java  | 16 ++++++++--
 .../microprofile/rest/client/regex/BookStore.java  |  5 +++
 .../rest/client/regex/BookStoreClient.java         |  7 ++++
 ...okStoreClient.java => BookStoreClientRoot.java} | 11 +++----
 .../rest/client/regex/JaxrsPathRegexTest.java      | 37 ++++++++++++++++++++++
 5 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
index 95d8a4f..4ac2c16 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
@@ -50,6 +50,7 @@ import org.apache.cxf.jaxrs.client.ClientProxyImpl;
 import org.apache.cxf.jaxrs.client.ClientState;
 import org.apache.cxf.jaxrs.client.JaxrsClientCallback;
 import org.apache.cxf.jaxrs.client.LocalClientState;
+import org.apache.cxf.jaxrs.client.spec.TLSConfiguration;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.Parameter;
@@ -105,15 +106,18 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
     private Map<Class<ClientHeadersFactory>, ProviderInfo<ClientHeadersFactory>> clientHeaderFactories = 
         new WeakHashMap<>();
     private List<Instance<?>> cdiInstances = new LinkedList<>();
+    private final TLSConfiguration tlsConfig;
 
     //CHECKSTYLE:OFF
+    @SuppressWarnings("PMD.ExcessiveParameterList")
     public MicroProfileClientProxyImpl(URI baseURI, ClassLoader loader, ClassResourceInfo cri,
                                        boolean isRoot, boolean inheritHeaders, ExecutorService executorService,
-                                       Configuration configuration, CDIInterceptorWrapper interceptorWrapper, 
-                                       Object... varValues) {
+                                       Configuration configuration, CDIInterceptorWrapper interceptorWrapper,
+                                       TLSConfiguration tlsConfig, Object... varValues) {
         super(new LocalClientState(baseURI, configuration.getProperties()), loader, cri,
             isRoot, inheritHeaders, varValues);
         this.interceptorWrapper = interceptorWrapper;
+        this.tlsConfig = tlsConfig;
         
         if (executorService == null) {
             throw new IllegalArgumentException("The executorService is required and must be provided");
@@ -122,12 +126,14 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
         init(executorService, configuration);
     }
 
+    @SuppressWarnings("PMD.ExcessiveParameterList")
     public MicroProfileClientProxyImpl(ClientState initialState, ClassLoader loader, ClassResourceInfo cri,
                                        boolean isRoot, boolean inheritHeaders, ExecutorService executorService,
                                        Configuration configuration, CDIInterceptorWrapper interceptorWrapper,
-                                       Object... varValues) {
+                                       TLSConfiguration tlsConfig, Object... varValues) {
         super(initialState, loader, cri, isRoot, inheritHeaders, varValues);
         this.interceptorWrapper = interceptorWrapper;
+        this.tlsConfig = tlsConfig;
         init(executorService, configuration);
     }
     //CHECKSTYLE:ON
@@ -534,4 +540,8 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
         cdiInstances.forEach(Instance::release);
         super.close();
     }
+    
+    public TLSConfiguration getTlsConfig() {
+        return tlsConfig;
+    }
 }
diff --git a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStore.java b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStore.java
index a7b9556..b03bfee 100644
--- a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStore.java
+++ b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStore.java
@@ -26,4 +26,9 @@ public class BookStore implements BookStoreClient {
         return book;
     }
 
+    @Override
+    public Book echoXmlBookregexMany(Book book, String id, String language, String format) {
+        return book;
+    }
+
 }
\ No newline at end of file
diff --git a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java
index d8257a8..888e31c 100644
--- a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java
+++ b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java
@@ -34,5 +34,12 @@ public interface BookStoreClient {
     @Consumes("application/xml")
     @Produces("application/xml")
     Book echoXmlBookregex(Book book, @PathParam("id") String id);
+    
+    @POST
+    @Path("/echoxmlbookregex/{id : [5-9]{3,4}}/{language:en|fr}/{format:pdf|epub|mobi}/many")
+    @Consumes("application/xml")
+    @Produces("application/xml")
+    Book echoXmlBookregexMany(Book book, @PathParam("id") String id, 
+        @PathParam("language") String language, @PathParam("format") String format);
 
 }
\ No newline at end of file
diff --git a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClientRoot.java
similarity index 77%
copy from systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java
copy to systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClientRoot.java
index d8257a8..78aeb4c 100644
--- a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClient.java
+++ b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/BookStoreClientRoot.java
@@ -25,14 +25,13 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 
-@Path("/bookstore")
-public interface BookStoreClient {
-
-    // Only books with id consisting of 3 or 4 digits of the numbers between 5 and 9 are accepted
+@Path("/bookstore/echoxmlbookregex/{id : [5-9]{3,4}}/{language:en|fr}/{format:pdf|epub|mobi}")
+public interface BookStoreClientRoot {
     @POST
-    @Path("/echoxmlbookregex/{id : [5-9]{3,4}}")
+    @Path("/many")
     @Consumes("application/xml")
     @Produces("application/xml")
-    Book echoXmlBookregex(Book book, @PathParam("id") String id);
+    Book echoXmlBookregexMany(Book book, @PathParam("id") String id, 
+        @PathParam("language") String language, @PathParam("format") String format);
 
 }
\ No newline at end of file
diff --git a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/JaxrsPathRegexTest.java b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/JaxrsPathRegexTest.java
index 660d93a..11fb332 100644
--- a/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/JaxrsPathRegexTest.java
+++ b/systests/microprofile/client/jaxrs/src/test/java/org/apache/cxf/systest/microprofile/rest/client/regex/JaxrsPathRegexTest.java
@@ -122,5 +122,42 @@ public class JaxrsPathRegexTest extends AbstractBusClientServerTestBase {
         echoedBook = bookStoreClient.echoXmlBookregex(book, "8667");
         assertEquals(id, echoedBook.getId());
     }
+    
+    @Test
+    public void testPathRegularExpressionMany() throws Exception {
+
+        String endpointAddress = "http://localhost:" + PORT + "/";
+        long id = 5678;
+        Book book = new Book();
+        book.setId(id);
+
+        // Successful
+        BookStoreClientRoot bookStoreClient = RestClientBuilder.newBuilder()
+            .baseUri(URI.create(endpointAddress))
+            .build(BookStoreClientRoot.class);
+
+        Book echoedBook = bookStoreClient.echoXmlBookregexMany(book, String.valueOf(id), "en", "pdf");
+        assertEquals(id, echoedBook.getId());
+
+        // Wrong language
+        try {
+            bookStoreClient.echoXmlBookregexMany(book, String.valueOf(id), "ru", "pdf");
+            fail("Failure expected on a failing regex");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        // Wrong format
+        try {
+            bookStoreClient.echoXmlBookregexMany(book, String.valueOf(id), "en", "doc");
+            fail("Failure expected on a failing regex");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        // Finally try another successful call
+        echoedBook = bookStoreClient.echoXmlBookregexMany(book, "8667", "fr", "epub");
+        assertEquals(id, echoedBook.getId());
+    }
 
 }