Browse Source

Merge pull request #242 from jacob-meacham/bugfix/multiple-regexes

Fix regex support when there are multiple @Path regexes
pull/244/head
Adrian Cole 10 years ago
parent
commit
44459dae6a
  1. 8
      jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java
  2. 19
      jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java

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

@ -81,11 +81,9 @@ public final class JAXRSContract extends Contract.BaseContract { @@ -81,11 +81,9 @@ public final class JAXRSContract extends Contract.BaseContract {
if (!methodAnnotationValue.startsWith("/") && !data.template().toString().endsWith("/")) {
methodAnnotationValue = "/" + methodAnnotationValue;
}
int regexIndex = methodAnnotationValue.indexOf(":");
if (methodAnnotationValue.indexOf("{") != -1 && regexIndex != -1) {
// The method annotation includes a regex, which should be stripped to get the true path parameter name.
methodAnnotationValue = methodAnnotationValue.substring(0, regexIndex) + "}";
}
// jax-rs allows whitespace around the param name, as well as an optional regex. The contract should
// strip these out appropriately.
methodAnnotationValue = methodAnnotationValue.replaceAll("\\{\\s*(.+?)\\s*(:.+?)?\\}", "\\{$1\\}");
data.template().append(methodAnnotationValue);
} else if (annotationType == Produces.class) {
String[] serverProduces = ((Produces) methodAnnotation).value();

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

@ -248,11 +248,22 @@ public class JAXRSContractTest { @@ -248,11 +248,22 @@ public class JAXRSContractTest {
PathOnType.class.getDeclaredMethod("emptyPathParam", String.class));
}
@Test
public void pathParamWithSpaces() throws Exception {
assertThat(contract.parseAndValidatateMetadata(
PathOnType.class.getDeclaredMethod("pathParamWithSpaces", String.class)).template())
.hasUrl("/base/{param}");
}
@Test
public void regexPathOnMethod() throws Exception {
assertThat(contract.parseAndValidatateMetadata(
PathOnType.class.getDeclaredMethod("pathParamWithRegex", String.class)).template())
.hasUrl("/base/regex/{param}");
assertThat(contract.parseAndValidatateMetadata(
PathOnType.class.getDeclaredMethod("pathParamWithMultipleRegex", String.class, String.class)).template())
.hasUrl("/base/regex/{param1}/{param2}");
}
@Test
@ -509,9 +520,17 @@ public class JAXRSContractTest { @@ -509,9 +520,17 @@ public class JAXRSContractTest {
@Path("/{param}")
Response emptyPathParam(@PathParam("") String empty);
@GET
@Path("/{ param }")
Response pathParamWithSpaces(@PathParam("param") String path);
@GET
@Path("regex/{param:.+}")
Response pathParamWithRegex(@PathParam("param") String path);
@GET
@Path("regex/{param1:[0-9]*}/{ param2 : .+}")
Response pathParamWithMultipleRegex(@PathParam("param1") String param1, @PathParam("param2") String param2);
}
interface WithURIParam {

Loading…
Cancel
Save