Skip to content

Commit

Permalink
the RestPathActions module allows the user to optionally define reque…
Browse files Browse the repository at this point in the history
…st method(s) that can be used for route matching. See this discussion for details: http://groups.google.com/group/jpublish-user/t/9321265fc4146b1c
  • Loading branch information
florin.patrascu@gmail.com committed Aug 7, 2011
1 parent bf7e367 commit 452414a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.txt
@@ -1,6 +1,11 @@
JPublish 4 change log:

[2011.08.07]
- the RestPathActions module allows the user to optionally define request method(s) that
can be used for route matching.

[2011.06.22]
- RESTPATHACTIONS demo cleanup and module improvements, see restpathactions module's own
- RESTPATHACTIONS demo cleanup and module improvements, see RestPathActions module's own
changelog for details.

[2010-12-09]
Expand Down
11 changes: 11 additions & 0 deletions modules/restpathactions/CHANGELOG
@@ -1,3 +1,14 @@
2011.08.07
- the RestPathActions module allows the user to optionally define request method(s) that
can be used for route matching. Example:

<routes>
<route path="search/{query}/page/{pageNo}" method="GET|POST" action="Search.bsh" page="search/index.html"/>
....

In the example above the Search.bsh action will be executed for the matching path ony if the
request method is GET or POST.

2011.06.22
- cleaned up the demo app html code to explicitly use jQuery instead of '$'; was generating a Velocity error
- the RPA module will return a 404 if there are no matching routes (Thank you for catching it, Alejandro)
Expand Down
Expand Up @@ -53,7 +53,7 @@ public RestPathAction(String modulePath, RestPathActionsModule module) {
}

public void execute(JPublishContext context, Configuration configuration) throws Exception {
String method = context.getRequest().getMethod();
String method = context.getRequest().getMethod(); // no need .toUpperCase() it
String pathInfo = GENERIC_PATH_INFO;
boolean resourceNotFound = true;

Expand All @@ -67,8 +67,9 @@ public void execute(JPublishContext context, Configuration configuration) throws

for (RestPathActionModel rm : module.getRestModels()) {
final UriTemplateMatcher matcher = rm.matcher();
boolean methodMatchesToo = rm.getMethods() != null && rm.getMethods().contains(method);

if (matcher.matches(path)) {
if (matcher.matches(path) && methodMatchesToo) {
resourceNotFound = false;

if (module.isDebug()) {
Expand Down
Expand Up @@ -67,7 +67,9 @@ public String getMethods() {
}

public void setMethods(String methods) {
this.methods = methods;
if (methods != null) {
this.methods = methods.toUpperCase();
}
}

public Configuration getConfiguration() {
Expand Down
Expand Up @@ -121,7 +121,7 @@ public void load(Configuration configuration) throws ConfigurationException {
restModel.setPath(routeConfiguration.getAttribute("path", ""));
restModel.setAction(routeConfiguration.getAttribute("action"));
restModel.setPage(routeConfiguration.getAttribute("page"));
restModel.setMethods(routeConfiguration.getAttribute("method", "get"));
restModel.setMethods(routeConfiguration.getAttribute("method", "GET"));
restModel.setConfiguration(routeConfiguration);

restModels.add(restModel);
Expand Down

0 comments on commit 452414a

Please sign in to comment.