Jersey 2: Fix NotFoundException
The exception NotFoundException no longer stores the missing resource URI;
However the latter can is accessible at any time during the request from
the request context.
References:
https://jakartaee.github.io/rest/apidocs/2.1.6/javax/ws/rs/NotFoundException.html
https://jakartaee.github.io/rest/apidocs/2.1.6/javax/ws/rs/container/ContainerRequestContext.html#getUriInfo()
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java
index 9434016..ecea06f 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java
@@ -3,12 +3,12 @@
import java.util.List;
import javax.annotation.Priority;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.PathSegment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.sun.jersey.api.NotFoundException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
@@ -33,7 +33,7 @@
String version = pathSegments.get(0).getPath();
if (!config.getSupportedVersions().contains(version)) {
- throw new NotFoundException(request.getRequestUri());
+ throw new NotFoundException();
// throw kustvaktResponseHandler.throwit(
// new
// KustvaktException(StatusCodes.UNSUPPORTED_API_VERSION,
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/utils/NotFoundMapper.java b/core/src/main/java/de/ids_mannheim/korap/web/utils/NotFoundMapper.java
index d2536f6..a05983b 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/utils/NotFoundMapper.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/utils/NotFoundMapper.java
@@ -4,6 +4,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.ext.ExceptionMapper;
@@ -15,8 +19,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.sun.jersey.api.NotFoundException;
-
import de.ids_mannheim.korap.config.KustvaktConfiguration;
/**
@@ -38,9 +40,15 @@
@Autowired
private KustvaktConfiguration config;
+ @Context
+ private ResourceContext resourceContext;
+
@Override
public Response toResponse (NotFoundException exception) {
- URI notFoundUri = exception.getNotFoundUri();
+ ContainerRequestContext requestContext =
+ resourceContext.getResource(ContainerRequestContext.class);
+
+ URI notFoundUri = requestContext.getUriInfo().getRequestUri();
String path = notFoundUri.getPath();
String baseUrl = config.getBaseURL();