Skip to content

Commit 39797f0

Browse files
Jacob MeachamAdrian Cole
authored andcommitted
Strip regex allowed by the jaxrs spec.
1 parent d195c53 commit 39797f0

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
7777
if (!methodAnnotationValue.startsWith("/") && !data.template().toString().endsWith("/")) {
7878
methodAnnotationValue = "/" + methodAnnotationValue;
7979
}
80+
int regexIndex = methodAnnotationValue.indexOf(":");
81+
if (methodAnnotationValue.indexOf("{") != -1 && regexIndex != -1) {
82+
// The method annotation includes a regex, which should be stripped to get the true path parameter name.
83+
methodAnnotationValue = methodAnnotationValue.substring(0, regexIndex) + "}";
84+
}
8085
data.template().append(methodAnnotationValue);
8186
} else if (annotationType == Produces.class) {
8287
String[] serverProduces = ((Produces) methodAnnotation).value();

‎jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ public void emptyPathParam() throws Exception {
248248
PathOnType.class.getDeclaredMethod("emptyPathParam", String.class));
249249
}
250250

251+
@Test
252+
public void regexPathOnMethod() throws Exception {
253+
assertThat(contract.parseAndValidatateMetadata(
254+
PathOnType.class.getDeclaredMethod("pathParamWithRegex", String.class)).template())
255+
.hasUrl("/base/regex/{param}");
256+
}
257+
251258
@Test
252259
public void withPathAndURIParams() throws Exception {
253260
MethodMetadata md = contract.parseAndValidatateMetadata(
@@ -485,6 +492,10 @@ interface PathOnType {
485492
@GET
486493
@Path("/{param}")
487494
Response emptyPathParam(@PathParam("") String empty);
495+
496+
@GET
497+
@Path("regex/{param:.+}")
498+
Response pathParamWithRegex(@PathParam("param") String path);
488499
}
489500

490501
interface WithURIParam {

0 commit comments

Comments
 (0)