Skip to content

Commit

Permalink
Merge pull request #237 from rsertelon/add-uri-template-regex-support
Browse files Browse the repository at this point in the history
Adds support for regex in URI templates
  • Loading branch information
mkristian committed Mar 13, 2015
2 parents c049eeb + 57c292b commit 1fb299a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -375,7 +375,7 @@ private void writeSubresourceLocatorImpl(JMethod method) throws UnableToComplete

private String pathExpression(String pathExpression, JParameter arg, PathParam paramPath) {
String expr = toStringExpression(arg);
return pathExpression.replaceAll(Pattern.quote("{" + paramPath.value() + "}"),
return pathExpression.replaceAll(Pattern.quote("{" + paramPath.value()) + "(\\s*:\\s*(.)+)?\\}",
"\"+(" + expr + "== null? null : ((\"\" + " + expr +").startsWith(\"http\") ? " + expr +
" : com.google.gwt.http.client.URL.encodePathSegment(" + expr + ")))+\"");
}
Expand Down
Expand Up @@ -60,6 +60,9 @@ static interface TestRestService extends RestService {
@Path("/get/{id}")
void get(@PathParam(value = "id") String i, MethodCallback<Echo> callback);

@GET @Path("/get/{id : \\d+}")
void getRegex(@PathParam(value = "id") Integer i, MethodCallback<Echo> callback);

@GET @Path("{url}")
void absolute(@PathParam(value = "url") String u, MethodCallback<Echo> callback);
}
Expand Down Expand Up @@ -131,6 +134,11 @@ public void testGetWithInt() {

}

public void testGetWithIntRegex() {
service.getRegex(123, echoMethodCallback("/get/123"));
delayTestFinish(10000);
}

public void testAbsolute() {

service.absolute(GWT.getModuleBaseURL() + "echo/somewhere", echoMethodCallback("/somewhere") );
Expand Down

0 comments on commit 1fb299a

Please sign in to comment.