summaryrefslogtreecommitdiffstats
path: root/container-core
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2021-05-02 19:27:57 +0200
committerGitHub <noreply@github.com>2021-05-02 19:27:57 +0200
commitedd0efdce13c9e4e264062a5c8e8163975164dc5 (patch)
tree05eb70684174321cf6ad3fda1578d0fce6be55c2 /container-core
parent2daa854096154742885d8ef2d7ca5d0745abb9d2 (diff)
parentb947b3750ce77bbb28addf1a86b7cfaf22d8243d (diff)
Merge pull request #17697 from vespa-engine/jonmv/reapply-rest-apis-without-trailing-slash-requirement
Jonmv/reapply rest apis without trailing slash requirement
Diffstat (limited to 'container-core')
-rw-r--r--container-core/src/main/java/com/yahoo/restapi/RestApiException.java4
-rw-r--r--container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java5
2 files changed, 7 insertions, 2 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiException.java b/container-core/src/main/java/com/yahoo/restapi/RestApiException.java
index d9da320499f..68e46a3a9b8 100644
--- a/container-core/src/main/java/com/yahoo/restapi/RestApiException.java
+++ b/container-core/src/main/java/com/yahoo/restapi/RestApiException.java
@@ -42,6 +42,7 @@ public class RestApiException extends RuntimeException {
public static class NotFound extends RestApiException {
public NotFound() { this(null, null); }
+ public NotFound(HttpRequest request) { this("Nothing at '" + request.getUri().getRawPath() + "'", null); }
public NotFound(Throwable cause) { this(cause.getMessage(), cause); }
public NotFound(String message) { this(message, null); }
public NotFound(String message, Throwable cause) { super(ErrorResponse::notFoundError, message, cause); }
@@ -50,7 +51,8 @@ public class RestApiException extends RuntimeException {
public static class MethodNotAllowed extends RestApiException {
public MethodNotAllowed() { super(ErrorResponse::methodNotAllowed, "Method not allowed", null); }
public MethodNotAllowed(HttpRequest request) {
- super(ErrorResponse::methodNotAllowed, "Method '" + request.getMethod().name() + "' is not allowed", null);
+ super(ErrorResponse::methodNotAllowed, "Method '" + request.getMethod().name() + "' is not allowed at '" +
+ request.getUri().getRawPath() + "'", null);
}
}
diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java
index 8ba94f9aca9..d63add5ed1d 100644
--- a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java
+++ b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java
@@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
@@ -144,7 +145,7 @@ class RestApiImpl implements RestApi {
private static Route createDefaultRoute() {
RouteBuilder routeBuilder = new RouteBuilderImpl("{*}")
.defaultHandler(context -> {
- throw new RestApiException.NotFound();
+ throw new RestApiException.NotFound(context.request());
});
return ((RouteBuilderImpl)routeBuilder).build();
}
@@ -155,6 +156,8 @@ class RestApiImpl implements RestApi {
if (!disableDefaultMappers){
exceptionMappers.add(new ExceptionMapperHolder<>(RestApiException.class, (context, exception) -> exception.response()));
}
+ // Topologically sort children before superclasses, so most the specific match is found by iterating through mappers in order.
+ exceptionMappers.sort((a, b) -> (a.type.isAssignableFrom(b.type) ? 1 : 0) + (b.type.isAssignableFrom(a.type) ? -1 : 0));
return exceptionMappers;
}