This is an automated email from the ASF dual-hosted git repository.
johndament pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 0d8847c [CXF-7579] Adding missing validation on unmatched path
templates.
0d8847c is described below
commit 0d8847cca3cb6a3a7044d13047845fb5d49dc5bb
Author: John D. Ament <[email protected]>
AuthorDate: Fri Dec 22 08:24:38 2017 -0500
[CXF-7579] Adding missing validation on unmatched path templates.
---
.../org/apache/cxf/microprofile/client/Messages.properties | 1 +
.../java/org/apache/cxf/microprofile/client/Validator.java | 13 +++++++++++++
.../org/apache/cxf/microprofile/client/ValidatorTest.java | 11 +++++++++++
3 files changed, 25 insertions(+)
diff --git
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Messages.properties
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Messages.properties
index d2d5363..2280582 100644
---
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Messages.properties
+++
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Messages.properties
@@ -22,3 +22,4 @@
VALIDATION_NOT_AN_INTERFACE=The type, {0}, passed in to the build method is
not an interface.
VALIDATION_METHOD_WITH_MULTIPLE_VERBS=The client interface contains a method,
{0} annotated with more than one HTTP method: {1}
VALIDATION_UNRESOLVED_PATH_PARAMS=The client interface, {0} has one or more
methods with unresolved path template variables: {1}
+VALIDATION_EXTRA_PATH_PARAMS=The client interface, {0} has one or more extra
path segments not in the template: {1}
\ No newline at end of file
diff --git
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Validator.java
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Validator.java
index 8d77e02..bcabd29 100644
---
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Validator.java
+++
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/Validator.java
@@ -21,9 +21,11 @@ package org.apache.cxf.microprofile.client;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
@@ -112,6 +114,17 @@ final class Validator {
} catch (IllegalArgumentException ex) {
throwException("VALIDATION_UNRESOLVED_PATH_PARAMS",
userType, method);
}
+ } else {
+ List<String> foundParams = new ArrayList<>();
+ for (Parameter p : method.getParameters()) {
+ PathParam pathParam = p.getAnnotation(PathParam.class);
+ if (pathParam != null) {
+ foundParams.add(pathParam.value());
+ }
+ }
+ if (!foundParams.isEmpty()) {
+ throwException("VALIDATION_EXTRA_PATH_PARAMS", userType,
method);
+ }
}
}
}
diff --git
a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/ValidatorTest.java
b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/ValidatorTest.java
index 7877574..96cfc90 100644
---
a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/ValidatorTest.java
+++
b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/ValidatorTest.java
@@ -85,6 +85,12 @@ public class ValidatorTest extends Assert {
Response post(@PathParam("class")String className);
}
+ @Path("/rest")
+ public interface ExtraParamTemplate {
+ @GET
+ Response get(@PathParam("any") String any);
+ }
+
private static RestClientBuilder newBuilder() {
RestClientBuilder builder = RestClientBuilder.newBuilder();
try {
@@ -118,6 +124,11 @@ public class ValidatorTest extends Assert {
"post");
}
+ @Test
+ public void testMissingTemplate() {
+ test(ExtraParamTemplate.class, "extra path segments",
"ExtraParamTemplate");
+ }
+
private void test(Class<?> clientInterface, String...expectedMessageTexts)
{
try {
newBuilder().build(clientInterface);
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].