Skip to content

Commit e619287

Browse files
committed
#31 - Methods with no GET/POST etc inside Controller class
1 parent 4cf998d commit e619287

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.example.myapp.web;
2+
3+
import io.dinject.controller.Controller;
4+
import io.dinject.controller.Path;
5+
6+
@Controller
7+
@Path("hallo")
8+
public class Hallo {
9+
10+
public String getStuff() {
11+
return "Hallo";
12+
}
13+
}

generator-core/src/main/java/io/dinject/webroutegen/MethodReader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public class MethodReader {
6262
this.produces = produces(bean);
6363

6464
initWebMethodViaAnnotation();
65-
this.pathSegments = PathSegments.parse(Util.combinePath(bean.getPath(), webMethodPath));
65+
if (isWebMethod()) {
66+
this.pathSegments = PathSegments.parse(Util.combinePath(bean.getPath(), webMethodPath));
67+
} else {
68+
this.pathSegments = null;
69+
}
6670
}
6771

6872
private void initWebMethodViaAnnotation() {

generator-core/src/main/java/io/dinject/webroutegen/Util.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ static String combinePath(String beanPath, String webMethodPath) {
3939
if (beanPath != null) {
4040
sb.append(beanPath);
4141
}
42-
if (!webMethodPath.isEmpty() && !webMethodPath.startsWith("/")) {
43-
sb.append("/");
42+
if (webMethodPath != null) {
43+
if (!webMethodPath.isEmpty() && !webMethodPath.startsWith("/")) {
44+
sb.append("/");
45+
}
46+
sb.append(trimTrailingSlash(webMethodPath));
4447
}
45-
sb.append(trimTrailingSlash(webMethodPath));
4648
return sb.toString();
4749
}
4850

generator-core/src/test/java/io/dinject/webroutegen/UtilTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class UtilTest {
1111
@Test
1212
public void combinePath() {
1313

14+
assertEquals(Util.combinePath("/hello", null), "/hello");
15+
1416
assertEquals(Util.combinePath(null, "/hello"), "/hello");
1517
assertEquals(Util.combinePath(null, "/hello/"), "/hello");
1618
assertEquals(Util.combinePath(null, "hello"), "/hello");

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<module>generator-core</module>
1414
<module>generator-javalin</module>
1515
<module>generator-helidon</module>
16-
<!-- <module>examples</module>-->
16+
<module>examples</module>
1717
</modules>
1818
</project>
1919

0 commit comments

Comments
 (0)