Skip to content

Commit be73d0d

Browse files
committed
remove encoder from 404 route
1 parent ff10d0a commit be73d0d

File tree

11 files changed

+31
-42
lines changed

11 files changed

+31
-42
lines changed

jooby/src/main/java/io/jooby/internal/Chi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,20 +804,20 @@ public void destroy() {
804804
root.destroy();
805805
}
806806

807-
public boolean find(String method, String path) {
807+
public boolean exists(String method, String path) {
808808
if (!staticPaths.getOrDefault(path, NO_MATCH).methods.containsKey(method)) {
809809
return root.findRoute(new RouterMatch(), method, new ZeroCopyString(path)) != null;
810810
}
811811
return true;
812812
}
813813

814-
public Router.Match find(String method, String path, MessageEncoder encoder) {
814+
public Router.Match find(String method, String path) {
815815
StaticRouterMatch match = staticPaths.getOrDefault(path, NO_MATCH).methods.get(method);
816816
if (match == null) {
817817
// use radix tree
818818
RouterMatch result = new RouterMatch();
819819
Route route = root.findRoute(result, method, new ZeroCopyString(path));
820-
return route == null ? result.missing(method, path, encoder) : result.found(route);
820+
return route == null ? result.missing(method, path) : result.found(route);
821821
}
822822
return match;
823823
}

jooby/src/main/java/io/jooby/internal/RouteTree.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
*/
66
package io.jooby.internal;
77

8-
import io.jooby.MessageEncoder;
98
import io.jooby.Route;
109
import io.jooby.Router;
1110

1211
interface RouteTree {
1312
void insert(String method, String pattern, Route route);
1413

15-
boolean find(String method, String path);
14+
boolean exists(String method, String path);
1615

17-
Router.Match find(String method, String path, MessageEncoder encoder);
16+
Router.Match find(String method, String path);
1817

1918
void destroy();
2019
}

jooby/src/main/java/io/jooby/internal/RouteTreeForwarding.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public RouteTreeForwarding(RouteTree tree) {
2020
tree.insert(method, pattern, route);
2121
}
2222

23-
@Override public boolean find(String method, String path) {
24-
return tree.find(method, path);
23+
@Override public boolean exists(String method, String path) {
24+
return tree.exists(method, path);
2525
}
2626

27-
@Override public Router.Match find(String method, String path, MessageEncoder encoder) {
28-
return tree.find(method, path, encoder);
27+
@Override public Router.Match find(String method, String path) {
28+
return tree.find(method, path);
2929
}
3030

3131
@Override public void destroy() {

jooby/src/main/java/io/jooby/internal/RouteTreeIgnoreTrailingSlash.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public RouteTreeIgnoreTrailingSlash(RouteTree tree) {
1313
super(tree);
1414
}
1515

16-
@Override public boolean find(String method, String path) {
17-
return super.find(method, Router.noTrailingSlash(path));
16+
@Override public boolean exists(String method, String path) {
17+
return super.exists(method, Router.noTrailingSlash(path));
1818
}
1919

20-
@Override public Router.Match find(String method, String path, MessageEncoder encoder) {
21-
return super.find(method, Router.noTrailingSlash(path), encoder);
20+
@Override public Router.Match find(String method, String path) {
21+
return super.find(method, Router.noTrailingSlash(path));
2222
}
2323
}

jooby/src/main/java/io/jooby/internal/RouteTreeLowerCasePath.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
*/
66
package io.jooby.internal;
77

8-
import io.jooby.MessageEncoder;
98
import io.jooby.Router;
109

1110
public class RouteTreeLowerCasePath extends RouteTreeForwarding {
1211
public RouteTreeLowerCasePath(RouteTree tree) {
1312
super(tree);
1413
}
1514

16-
@Override public boolean find(String method, String path) {
17-
return super.find(method, path.toLowerCase());
15+
@Override public boolean exists(String method, String path) {
16+
return super.exists(method, path.toLowerCase());
1817
}
1918

20-
@Override public Router.Match find(String method, String path, MessageEncoder encoder) {
21-
return super.find(method, path.toLowerCase(), encoder);
19+
@Override public Router.Match find(String method, String path) {
20+
return super.find(method, path.toLowerCase());
2221
}
2322
}

jooby/src/main/java/io/jooby/internal/RouteTreeNormPath.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55
*/
66
package io.jooby.internal;
77

8-
import io.jooby.MessageEncoder;
98
import io.jooby.Router;
109

1110
public class RouteTreeNormPath extends RouteTreeForwarding {
1211
public RouteTreeNormPath(RouteTree tree) {
1312
super(tree);
1413
}
1514

16-
@Override public boolean find(String method, String path) {
17-
return super.find(method, Router.normalizePath(path));
15+
@Override public boolean exists(String method, String path) {
16+
return super.exists(method, Router.normalizePath(path));
1817
}
1918

20-
@Override public Router.Match find(String method, String path, MessageEncoder encoder) {
21-
return super.find(method, Router.normalizePath(path), encoder);
19+
@Override public Router.Match find(String method, String path) {
20+
return super.find(method, Router.normalizePath(path));
2221
}
2322
}

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,20 +607,20 @@ public void destroy() {
607607
if (predicateMap != null) {
608608
for (Map.Entry<Predicate<Context>, RouteTree> e : predicateMap.entrySet()) {
609609
if (e.getKey().test(ctx)) {
610-
Router.Match match = e.getValue().find(ctx.getMethod(), ctx.getRequestPath(), encoder);
610+
Router.Match match = e.getValue().find(ctx.getMethod(), ctx.getRequestPath());
611611
if (match.matches()) {
612612
return match;
613613
}
614614
}
615615
}
616616
}
617-
return chi.find(ctx.getMethod(), ctx.getRequestPath(), encoder);
617+
return chi.find(ctx.getMethod(), ctx.getRequestPath());
618618
}
619619

620620
@Override public boolean match(@Nonnull String pattern, @Nonnull String path) {
621621
Chi chi = new Chi();
622622
chi.insert(Router.GET, pattern, ROUTE_MARK);
623-
return chi.find(Router.GET, path);
623+
return chi.exists(Router.GET, path);
624624
}
625625

626626
@Nonnull @Override public Router errorCode(@Nonnull Class<? extends Throwable> type,

jooby/src/main/java/io/jooby/internal/RouterMatch.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,14 @@ public void execute(Context context) {
9797
}
9898
}
9999

100-
public RouterMatch missing(String method, String path, MessageEncoder encoder) {
100+
public RouterMatch missing(String method, String path) {
101101
Route.Handler h;
102102
if (this.handler == null) {
103103
h = path.endsWith("/favicon.ico") ? Route.FAVICON : Route.NOT_FOUND;
104104
} else {
105105
h = this.handler;
106106
}
107107
this.route = new Route(method, path, h);
108-
this.route.setEncoder(encoder);
109108
this.route.setReturnType(Context.class);
110109
return this;
111110
}

jooby/src/test/java/io/jooby/internal/ChiBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ private Route route(String method, String pattern) {
3939

4040
@Benchmark
4141
public void _plaintext() {
42-
router.find("GET", "/plaintext", null);
42+
router.find("GET", "/plaintext");
4343
}
4444

4545
@Benchmark
4646
public void articles() {
47-
router.find("GET", "/articles/123", null);
47+
router.find("GET", "/articles/123");
4848
}
4949

5050
@Benchmark
5151
public void articlesEdit() {
52-
router.find("GET", "/articles/123/edit", null);
52+
router.find("GET", "/articles/123/edit");
5353
}
5454

5555
}

jooby/src/test/java/io/jooby/internal/ChiTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void routeOverride() {
2424
router.insert(bar);
2525

2626
Router.Match result = router
27-
.find("GET", "/abcd", MessageEncoder.TO_STRING);
27+
.find("GET", "/abcd");
2828
assertTrue(result.matches());
2929
assertEquals(bar, result.route());
3030
}
@@ -38,7 +38,7 @@ public void routeCase() {
3838
router.insert(foos);
3939

4040
Router.Match result = router
41-
.find("GET", "/abcd/", MessageEncoder.TO_STRING);
41+
.find("GET", "/abcd/");
4242
assertTrue(result.matches());
4343
assertEquals(foos, result.route());
4444
}
@@ -174,7 +174,7 @@ public void regexWithQuantity() {
174174
private void find(Chi router, String pattern,
175175
SneakyThrows.Consumer2<Context, Router.Match> consumer) {
176176
Router.Match result = router
177-
.find("GET", pattern, MessageEncoder.TO_STRING);
177+
.find("GET", pattern);
178178
consumer.accept(ctx(pattern), result);
179179
}
180180

0 commit comments

Comments
 (0)