Skip to content

Commit 51d49ef

Browse files
committed
mvc routes: default to HTTP GET when Path annotation is present fix #370
1 parent fbe868c commit 51d49ef

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.jooby.issues;
2+
3+
import org.jooby.mvc.Path;
4+
import org.jooby.test.ServerFeature;
5+
import org.junit.Test;
6+
7+
public class Issue370 extends ServerFeature {
8+
9+
@Path("/")
10+
public static class S {
11+
12+
@Path("/s")
13+
public String doSomething() {
14+
return "GET";
15+
}
16+
17+
}
18+
19+
{
20+
use(S.class);
21+
}
22+
23+
@Test
24+
public void mvcShouldDefaultToGet() throws Exception {
25+
request()
26+
.get("/s")
27+
.expect("GET");
28+
}
29+
30+
}

jooby/src/main/java/org/jooby/internal/mvc/MvcRoutes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.reflect.AnnotatedElement;
2323
import java.lang.reflect.Method;
2424
import java.util.ArrayList;
25+
import java.util.Arrays;
2526
import java.util.HashMap;
2627
import java.util.LinkedHashMap;
2728
import java.util.List;
@@ -91,6 +92,8 @@ public static List<Route.Definition> routes(final Env env, final RouteMetadata c
9192
}
9293
if (annotations.size() > 0) {
9394
methods.put(method, annotations);
95+
} else if (method.isAnnotationPresent(Path.class)) {
96+
methods.put(method, Arrays.asList(GET.class));
9497
}
9598
}
9699

0 commit comments

Comments
 (0)