blob: 7829482b1f7d20d7a15b1a4637d64872a70e35bc [file] [log] [blame]
margaretha398f4722019-01-09 19:07:20 +01001package de.ids_mannheim.korap.web.filter;
margarethaee0cbfe2018-08-28 17:47:14 +02002
3import java.util.List;
4
abcpro12cb86c62022-11-07 18:46:36 +00005import javax.annotation.Priority;
margarethaee0cbfe2018-08-28 17:47:14 +02006
7import org.springframework.beans.factory.annotation.Autowired;
8import org.springframework.stereotype.Component;
9
margarethaee0cbfe2018-08-28 17:47:14 +020010import de.ids_mannheim.korap.config.KustvaktConfiguration;
margaretha96c309d2023-08-16 12:24:12 +020011import jakarta.ws.rs.NotFoundException;
12import jakarta.ws.rs.container.ContainerRequestContext;
13import jakarta.ws.rs.container.ContainerRequestFilter;
14import jakarta.ws.rs.core.PathSegment;
margarethaee0cbfe2018-08-28 17:47:14 +020015
margaretha7926adc2018-08-30 13:45:33 +020016/**
17 * Checks API version in URL path.
margarethaee0cbfe2018-08-28 17:47:14 +020018 *
19 * @author margaretha
20 *
21 */
22@Component
abcpro12cb86c62022-11-07 18:46:36 +000023@Priority(Integer.MIN_VALUE)
margaretha7926adc2018-08-30 13:45:33 +020024public class APIVersionFilter
abcpro1136ff592022-11-07 18:25:03 +000025 implements ContainerRequestFilter {
margarethaee0cbfe2018-08-28 17:47:14 +020026
27 @Autowired
28 private KustvaktConfiguration config;
margarethaee0cbfe2018-08-28 17:47:14 +020029
abcpro1136ff592022-11-07 18:25:03 +000030 public void filter (ContainerRequestContext request) {
abcpro196687242022-11-07 20:00:19 +000031 List<PathSegment> pathSegments = request.getUriInfo().getPathSegments();
margarethaee0cbfe2018-08-28 17:47:14 +020032 String version = pathSegments.get(0).getPath();
33
margaretha7926adc2018-08-30 13:45:33 +020034 if (!config.getSupportedVersions().contains(version)) {
abcpro1edfa6702022-11-07 18:52:14 +000035 throw new NotFoundException();
margaretha7926adc2018-08-30 13:45:33 +020036 // throw kustvaktResponseHandler.throwit(
37 // new
38 // KustvaktException(StatusCodes.UNSUPPORTED_API_VERSION,
39 // "API " + version + " is unsupported.", version));
margarethaee0cbfe2018-08-28 17:47:14 +020040 }
margarethaee0cbfe2018-08-28 17:47:14 +020041 }
42
43}