diff --git a/core/src/main/java/net/cactusthorn/routing/RoutingConfig.java b/core/src/main/java/net/cactusthorn/routing/RoutingConfig.java index 53d97ae..37e9cc6 100644 --- a/core/src/main/java/net/cactusthorn/routing/RoutingConfig.java +++ b/core/src/main/java/net/cactusthorn/routing/RoutingConfig.java @@ -44,7 +44,7 @@ public Object ddefault() { } } - private List> entryPointClasses; + private List> resourceClasses; private ConvertersHolder convertersHolder; @@ -64,7 +64,7 @@ public Object ddefault() { private RoutingConfig( ComponentProvider componentProvider, ConvertersHolder convertersHolder, - List> entryPointClasses, + List> resourceClasses, List bodyWriters, List bodyReaders, Map configProperties, @@ -72,7 +72,7 @@ private RoutingConfig( String applicationPath) { this.componentProvider = componentProvider; this.convertersHolder = convertersHolder; - this.entryPointClasses = entryPointClasses; + this.resourceClasses = resourceClasses; this.bodyWriters = bodyWriters; this.bodyReaders = bodyReaders; this.configProperties = configProperties; @@ -89,8 +89,8 @@ public ConvertersHolder convertersHolder() { return convertersHolder; } - public List> entryPointClasses() { - return entryPointClasses; + public List> resourceClasses() { + return resourceClasses; } public List bodyWriters() { @@ -123,7 +123,7 @@ public static final class Builder { private final ConvertersHolder convertersHolder = new ConvertersHolder(); - private final List> entryPointClasses = new ArrayList<>(); + private final List> resourceClasses = new ArrayList<>(); private final List bodyWriters = new ArrayList<>(); @@ -158,13 +158,13 @@ public Builder addConverter(Class clazz, Converter converter) { return this; } - public Builder addEntryPoint(Class entryPoint) { - entryPointClasses.add(entryPoint); + public Builder addResource(Class resource) { + resourceClasses.add(resource); return this; } - public Builder addEntryPoint(Collection> entryPoints) { - entryPointClasses.addAll(entryPoints); + public Builder addResource(Collection> resources) { + resourceClasses.addAll(resources); return this; } @@ -217,7 +217,7 @@ public RoutingConfig build() { Map unmodifiableConfigProperties = Collections.unmodifiableMap(configProperties); - return new RoutingConfig(componentProvider, convertersHolder, Collections.unmodifiableList(entryPointClasses), + return new RoutingConfig(componentProvider, convertersHolder, Collections.unmodifiableList(resourceClasses), unmodifiableBodyWriters, unmodifiableBodyReaders, unmodifiableConfigProperties, validator, applicationPath); } } diff --git a/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java b/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java index a736bfe..b27630f 100644 --- a/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java +++ b/core/src/main/java/net/cactusthorn/routing/RoutingServlet.java @@ -19,11 +19,12 @@ import javax.ws.rs.core.Response.StatusType; import javax.ws.rs.ext.MessageBodyWriter; -import net.cactusthorn.routing.EntryPointScanner.EntryPoint; import net.cactusthorn.routing.RoutingConfig.ConfigProperty; import net.cactusthorn.routing.body.writer.BodyWriter; import net.cactusthorn.routing.body.writer.MessageBodyHeadersWriter; import net.cactusthorn.routing.invoke.MethodInvoker.ReturnObjectInfo; +import net.cactusthorn.routing.resource.ResourceScanner; +import net.cactusthorn.routing.resource.ResourceScanner.Resource; import net.cactusthorn.routing.PathTemplate.PathValues; public class RoutingServlet extends HttpServlet { @@ -32,7 +33,7 @@ public class RoutingServlet extends HttpServlet { private static final Logger LOG = Logger.getLogger(RoutingServlet.class.getName()); - private transient Map> allEntryPoints; + private transient Map> allResources; private transient ServletContext servletContext; private transient RoutingConfig routingConfig; private transient String responseCharacterEncoding; @@ -53,8 +54,8 @@ public void init() throws ServletException { routingConfig.bodyReaders().forEach(r -> r.init(servletContext, routingConfig)); routingConfig.validator().ifPresent(v -> v.init(servletContext, routingConfig.provider())); - EntryPointScanner scanner = new EntryPointScanner(routingConfig); - allEntryPoints = scanner.scan(); + ResourceScanner scanner = new ResourceScanner(routingConfig); + allResources = scanner.scan(); } @Override // @@ -67,70 +68,70 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws } protected void doPatch(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.PATCH)); + process(req, resp, allResources.get(HttpMethod.PATCH)); } @Override // protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.HEAD)); + process(req, resp, allResources.get(HttpMethod.HEAD)); } @Override // protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.POST)); + process(req, resp, allResources.get(HttpMethod.POST)); } @Override // protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.PUT)); + process(req, resp, allResources.get(HttpMethod.PUT)); } @Override // protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.DELETE)); + process(req, resp, allResources.get(HttpMethod.DELETE)); } @Override // protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.OPTIONS)); + process(req, resp, allResources.get(HttpMethod.OPTIONS)); } @Override // protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - process(req, resp, allEntryPoints.get(HttpMethod.GET)); + process(req, resp, allResources.get(HttpMethod.GET)); } - private void process(HttpServletRequest req, HttpServletResponse resp, List entryPoints) throws IOException { + private void process(HttpServletRequest req, HttpServletResponse resp, List resources) throws IOException { String contentType = contentType(req); if (req.getCharacterEncoding() == null) { req.setCharacterEncoding(defaultRequestCharacterEncoding); } String path = getPath(contentType, req); - if (entryPoints.isEmpty()) { + if (resources.isEmpty()) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Not Found"); return; } List accept = Http.parseAccept(req.getHeaders(HttpHeaders.ACCEPT)); boolean matchContentTypeFail = false; boolean matchAcceptFail = false; - for (EntryPoint entryPoint : entryPoints) { - PathValues pathValues = entryPoint.parse(path); + for (Resource resource : resources) { + PathValues pathValues = resource.parse(path); if (pathValues != null) { - if (!entryPoint.matchUserRole(req)) { + if (!resource.matchUserRole(req)) { resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden"); return; } try { - if (!entryPoint.matchContentType(contentType)) { + if (!resource.matchContentType(contentType)) { matchContentTypeFail = true; continue; } - Optional producesMediaType = entryPoint.matchAccept(accept); + Optional producesMediaType = resource.matchAccept(accept); if (!producesMediaType.isPresent()) { matchAcceptFail = true; continue; } - Response result = entryPoint.invoke(req, resp, servletContext, pathValues); + Response result = resource.invoke(req, resp, servletContext, pathValues); //It could be that in resource method Response object was created manually and media-type was set, //and this media-type do not match request Accept-header. //In this case -> response error at ones. @@ -138,7 +139,7 @@ private void process(HttpServletRequest req, HttpServletResponse resp, List produces(Class clazz) { diff --git a/core/src/main/java/net/cactusthorn/routing/EntryPointScanner.java b/core/src/main/java/net/cactusthorn/routing/resource/ResourceScanner.java similarity index 84% rename from core/src/main/java/net/cactusthorn/routing/EntryPointScanner.java rename to core/src/main/java/net/cactusthorn/routing/resource/ResourceScanner.java index 8ba406b..280a590 100644 --- a/core/src/main/java/net/cactusthorn/routing/EntryPointScanner.java +++ b/core/src/main/java/net/cactusthorn/routing/resource/ResourceScanner.java @@ -1,4 +1,4 @@ -package net.cactusthorn.routing; +package net.cactusthorn.routing.resource; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -17,19 +17,22 @@ import net.cactusthorn.routing.annotation.Template; import net.cactusthorn.routing.annotation.UserRoles; +import net.cactusthorn.routing.PathTemplate; +import net.cactusthorn.routing.RoutingConfig; +import net.cactusthorn.routing.Templated; import net.cactusthorn.routing.PathTemplate.PathValues; import net.cactusthorn.routing.invoke.MethodInvoker; import net.cactusthorn.routing.invoke.MethodInvoker.ReturnObjectInfo; -public class EntryPointScanner { +public class ResourceScanner { private static final ConsumesParser CONSUMES_PARSER = new ConsumesParser(); private static final PathTemplateParser PATHTEMPLATE_PARSER = new PathTemplateParser(); private static final ProducesParser PRODUCES_PARSER = new ProducesParser(); - public static final class EntryPoint { + public static final class Resource { - private static final Comparator COMPARATOR = (o1, o2) -> PathTemplate.COMPARATOR.compare(o1.pathTemplate, + private static final Comparator COMPARATOR = (o1, o2) -> PathTemplate.COMPARATOR.compare(o1.pathTemplate, o2.pathTemplate); private PathTemplate pathTemplate; @@ -39,7 +42,7 @@ public static final class EntryPoint { private String template; private Set userRoles; - private EntryPoint(PathTemplate pathTemplate, String template, List producesMediaTypes, + private Resource(PathTemplate pathTemplate, String template, List producesMediaTypes, Set consumesMediaTypes, MethodInvoker methodInvoker, Set userRoles) { this.pathTemplate = pathTemplate; this.producesMediaTypes = producesMediaTypes; @@ -119,15 +122,15 @@ public boolean matchContentType(String contenttype) { private RoutingConfig routingConfig; - public EntryPointScanner(RoutingConfig routingConfig) { + public ResourceScanner(RoutingConfig routingConfig) { this.routingConfig = routingConfig; } - public Map> scan() { + public Map> scan() { - Map> entryPoints = createMap(); + Map> resources = createMap(); - for (Class clazz : routingConfig.entryPointClasses()) { + for (Class clazz : routingConfig.resourceClasses()) { String classPath = PATHTEMPLATE_PARSER.prepare(routingConfig.applicationPath(), clazz.getAnnotation(Path.class)); Set classConsumesMediaTypes = CONSUMES_PARSER.consumes(clazz); @@ -153,19 +156,19 @@ public Map> scan() { Set userRoles = findUserRoles(method); - EntryPoint entryPoint = new EntryPoint(pathTemplate, template, producesMediaTypes, consumesMediaTypes, + Resource resource = new Resource(pathTemplate, template, producesMediaTypes, consumesMediaTypes, methodInvoker, userRoles); - entryPoints.get(httpMethod).add(entryPoint); + resources.get(httpMethod).add(resource); } } } } - for (Map.Entry> entry : entryPoints.entrySet()) { - Collections.sort(entry.getValue(), EntryPoint.COMPARATOR); + for (Map.Entry> entry : resources.entrySet()) { + Collections.sort(entry.getValue(), Resource.COMPARATOR); } - return entryPoints; + return resources; } private String findTemplate(Method method) { @@ -195,11 +198,11 @@ private String getHttpMethod(Annotation annotation) { return null; } - private Map> createMap() { - Map> entryPoints = new HashMap<>(); + private Map> createMap() { + Map> resources = new HashMap<>(); for (String method : HTTP_METHODS) { - entryPoints.put(method, new ArrayList<>()); + resources.put(method, new ArrayList<>()); } - return entryPoints; + return resources; } } diff --git a/core/src/test/java/net/cactusthorn/routing/RoutingServletTest.java b/core/src/test/java/net/cactusthorn/routing/RoutingServletTest.java index 5b3f8c8..afcc0c1 100644 --- a/core/src/test/java/net/cactusthorn/routing/RoutingServletTest.java +++ b/core/src/test/java/net/cactusthorn/routing/RoutingServletTest.java @@ -182,7 +182,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - static RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + static RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); static RoutingServlet servlet; static { @@ -224,7 +224,7 @@ public void wrong() throws ServletException, IOException { @Test // public void templated() throws ServletException, IOException { - RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .addBodyWriter(new TestTemplated()).build(); RoutingServlet toSpy = new RoutingServlet(c); RoutingServlet s = Mockito.spy(toSpy); @@ -239,7 +239,7 @@ public void templated() throws ServletException, IOException { @Test // public void templatedA() throws ServletException, IOException { - RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .addBodyWriter(new TestTemplated()).build(); RoutingServlet toSpy = new RoutingServlet(c); RoutingServlet s = Mockito.spy(toSpy); @@ -452,7 +452,7 @@ public void redirect() throws ServletException, IOException { @Test // public void validation() throws ServletException, IOException { - RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .setParametersValidator(TEST_VALIDATOR).build(); RoutingServlet servlet = new RoutingServlet(c); RoutingServlet s = Mockito.spy(servlet); @@ -473,7 +473,7 @@ public void validation() throws ServletException, IOException { @Test // public void userRoles() throws ServletException, IOException { - RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig c = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .setParametersValidator(TEST_VALIDATOR).build(); RoutingServlet servlet = new RoutingServlet(c); RoutingServlet s = Mockito.spy(servlet); @@ -527,7 +527,7 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void initializationException() throws ServletException { - RoutingConfig config = RoutingConfig.builder(new EntryPointWrongProvider()).addEntryPoint(EntryPointWrong.class).build(); + RoutingConfig config = RoutingConfig.builder(new EntryPointWrongProvider()).addResource(EntryPointWrong.class).build(); RoutingServlet servlet = new RoutingServlet(config); RoutingServlet s = Mockito.spy(servlet); Mockito.doReturn(null).when(s).getServletContext(); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/BodyReaderParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/BodyReaderParameterTest.java index 10d7130..281be4f 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/BodyReaderParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/BodyReaderParameterTest.java @@ -65,7 +65,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @BeforeAll // protected static void beforeAll() throws Exception { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java index dd3f6a7..4e13349 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/CookieParamParameterTest.java @@ -42,7 +42,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @Test // public void wrongType() throws Exception { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java index 06d9bf0..bfa5efd 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/FormParamParameterTest.java @@ -49,7 +49,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @Test // public void wrongContentType() { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java index b1400fb..f432510 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/FormPartParameterTest.java @@ -96,7 +96,7 @@ public TestPart(String name) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @Test // public void wrongType() { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java index e695296..60f7a3f 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/HeaderParamParameterTest.java @@ -49,7 +49,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @Test // public void simpleArray() { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java index 0a71ae0..3d54a5b 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/MethodInvokerTest.java @@ -117,7 +117,7 @@ protected void setUp() throws Exception { @ParameterizedTest @MethodSource("provideArguments") // public void invokeMethod(String methodName, PathValues pathValues, Object expectedResult) { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .setParametersValidator(VALIDATOR).build(); Method method = findMethod(EntryPoint1.class, methodName); @@ -136,7 +136,7 @@ public void invokeM7() throws IOException { Mockito.when(request.getCharacterEncoding()).thenReturn("UTF-8"); Mockito.when(request.getHeaderNames()).thenReturn(Collections.emptyEnumeration()); - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .setParametersValidator(VALIDATOR).build(); config.bodyReaders().forEach(r -> r.init(null, config)); @@ -154,7 +154,7 @@ public void invokeM7() throws IOException { @Test // public void invokeM8() throws IOException { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class) + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class) .setParametersValidator(VALIDATOR).build(); Method method = findMethod(EntryPoint1.class, "m8"); diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java index e63f9e6..3e504c2 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/PathParamParameterTest.java @@ -56,7 +56,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @ParameterizedTest @ValueSource(strings = { "array", "collection", "math" }) // public void testThrows(String method) { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/PrincipalParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/PrincipalParameterTest.java index f941f69..c08f236 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/PrincipalParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/PrincipalParameterTest.java @@ -35,7 +35,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @Test // public void simple() throws Exception { diff --git a/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java b/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java index cd682d6..072b288 100644 --- a/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java +++ b/core/src/test/java/net/cactusthorn/routing/invoke/QueryParamParameterTest.java @@ -65,7 +65,7 @@ public Object provide(Class clazz, HttpServletRequest request) { } } - private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addEntryPoint(EntryPoint1.class).build(); + private static final RoutingConfig CONFIG = RoutingConfig.builder(new EntryPoint1Provider()).addResource(EntryPoint1.class).build(); @ParameterizedTest @MethodSource("collectionArguments") // public void collections(String methodName, String[] requestValues, Integer[] expected) throws Exception { diff --git a/core/src/test/java/net/cactusthorn/routing/scanner/ConsumesTest.java b/core/src/test/java/net/cactusthorn/routing/resource/ConsumesTest.java similarity index 89% rename from core/src/test/java/net/cactusthorn/routing/scanner/ConsumesTest.java rename to core/src/test/java/net/cactusthorn/routing/resource/ConsumesTest.java index 39d11a3..602cdee 100644 --- a/core/src/test/java/net/cactusthorn/routing/scanner/ConsumesTest.java +++ b/core/src/test/java/net/cactusthorn/routing/resource/ConsumesTest.java @@ -1,4 +1,4 @@ -package net.cactusthorn.routing.scanner; +package net.cactusthorn.routing.resource; import static org.junit.jupiter.api.Assertions.*; @@ -19,7 +19,7 @@ import org.junit.jupiter.params.provider.MethodSource; import net.cactusthorn.routing.*; -import net.cactusthorn.routing.EntryPointScanner.EntryPoint; +import net.cactusthorn.routing.resource.ResourceScanner.Resource; public class ConsumesTest { @@ -73,10 +73,10 @@ public Object provide(Class clazz, HttpServletRequest request) { @ParameterizedTest @MethodSource("provideArguments") // public void testIt(ComponentProvider provider, Class entryPointClass, String httpMethod, String match ) { - RoutingConfig config = RoutingConfig.builder(provider).addEntryPoint(entryPointClass).build(); - EntryPointScanner scanner = new EntryPointScanner(config); - Map> entryPoints = scanner.scan(); - EntryPoint entryPoint = entryPoints.get(httpMethod).get(0); + RoutingConfig config = RoutingConfig.builder(provider).addResource(entryPointClass).build(); + ResourceScanner scanner = new ResourceScanner(config); + Map> entryPoints = scanner.scan(); + Resource entryPoint = entryPoints.get(httpMethod).get(0); assertTrue(entryPoint.matchContentType(match)); } diff --git a/core/src/test/java/net/cactusthorn/routing/scanner/ScannerCollectionTest.java b/core/src/test/java/net/cactusthorn/routing/resource/ScannerCollectionTest.java similarity index 81% rename from core/src/test/java/net/cactusthorn/routing/scanner/ScannerCollectionTest.java rename to core/src/test/java/net/cactusthorn/routing/resource/ScannerCollectionTest.java index cb175e1..6750e01 100644 --- a/core/src/test/java/net/cactusthorn/routing/scanner/ScannerCollectionTest.java +++ b/core/src/test/java/net/cactusthorn/routing/resource/ScannerCollectionTest.java @@ -1,4 +1,4 @@ -package net.cactusthorn.routing.scanner; +package net.cactusthorn.routing.resource; import static org.junit.jupiter.api.Assertions.*; @@ -14,9 +14,8 @@ import org.junit.jupiter.api.Test; import net.cactusthorn.routing.ComponentProvider; -import net.cactusthorn.routing.EntryPointScanner; import net.cactusthorn.routing.RoutingConfig; -import net.cactusthorn.routing.EntryPointScanner.EntryPoint; +import net.cactusthorn.routing.resource.ResourceScanner.Resource; public class ScannerCollectionTest { @@ -73,12 +72,12 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void entryPoint() { List> classes = Arrays.asList(EntryPoint1.class, EntryPoint2.class, EntryPoint3.class, EntryPoint4.class); - RoutingConfig config = RoutingConfig.builder(new EntryPointProvider()).addEntryPoint(classes).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - List gets = entryPoints.get(HttpMethod.GET); + RoutingConfig config = RoutingConfig.builder(new EntryPointProvider()).addResource(classes).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + List gets = entryPoints.get(HttpMethod.GET); assertEquals(4, gets.size()); - for (EntryPoint entryPoint : gets) { + for (Resource entryPoint : gets) { assertTrue(entryPoint.match("/api/dddd/")); } } diff --git a/core/src/test/java/net/cactusthorn/routing/scanner/ScannerSortingTest.java b/core/src/test/java/net/cactusthorn/routing/resource/ScannerSortingTest.java similarity index 74% rename from core/src/test/java/net/cactusthorn/routing/scanner/ScannerSortingTest.java rename to core/src/test/java/net/cactusthorn/routing/resource/ScannerSortingTest.java index bce8403..052cbcc 100644 --- a/core/src/test/java/net/cactusthorn/routing/scanner/ScannerSortingTest.java +++ b/core/src/test/java/net/cactusthorn/routing/resource/ScannerSortingTest.java @@ -1,4 +1,4 @@ -package net.cactusthorn.routing.scanner; +package net.cactusthorn.routing.resource; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -13,10 +13,9 @@ import org.junit.jupiter.api.Test; import net.cactusthorn.routing.ComponentProvider; -import net.cactusthorn.routing.EntryPointScanner; import net.cactusthorn.routing.RoutingConfig; -import net.cactusthorn.routing.EntryPointScanner.EntryPoint; -import net.cactusthorn.routing.scanner.ScannerTest.EntryPoint1Provider1; +import net.cactusthorn.routing.resource.ResourceScanner.Resource; +import net.cactusthorn.routing.resource.ScannerTest.EntryPoint1Provider1; public class ScannerSortingTest { @@ -48,10 +47,10 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void entryPoint1() { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider1()).addEntryPoint(EntryPoint1.class).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - List gets = entryPoints.get(HttpMethod.GET); + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider1()).addResource(EntryPoint1.class).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + List gets = entryPoints.get(HttpMethod.GET); assertEquals("/api/dddd/sssss/", gets.get(0).pathTemplatePattern()); assertEquals("/api/(\\d{3})/dddd/", gets.get(1).pathTemplatePattern()); diff --git a/core/src/test/java/net/cactusthorn/routing/scanner/ScannerTest.java b/core/src/test/java/net/cactusthorn/routing/resource/ScannerTest.java similarity index 75% rename from core/src/test/java/net/cactusthorn/routing/scanner/ScannerTest.java rename to core/src/test/java/net/cactusthorn/routing/resource/ScannerTest.java index 791e727..f92862d 100644 --- a/core/src/test/java/net/cactusthorn/routing/scanner/ScannerTest.java +++ b/core/src/test/java/net/cactusthorn/routing/resource/ScannerTest.java @@ -1,4 +1,4 @@ -package net.cactusthorn.routing.scanner; +package net.cactusthorn.routing.resource; import static org.junit.jupiter.api.Assertions.*; @@ -13,13 +13,12 @@ import org.junit.jupiter.api.Test; import net.cactusthorn.routing.ComponentProvider; -import net.cactusthorn.routing.EntryPointScanner; import net.cactusthorn.routing.PathTemplate; -import net.cactusthorn.routing.EntryPointScanner.EntryPoint; import net.cactusthorn.routing.Http; import net.cactusthorn.routing.PathTemplate.PathValues; import net.cactusthorn.routing.RoutingConfig; import net.cactusthorn.routing.annotation.Template; +import net.cactusthorn.routing.resource.ResourceScanner.Resource; import javax.ws.rs.GET; import javax.ws.rs.HEAD; @@ -67,12 +66,12 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void entryPoint1() { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider1()).addEntryPoint(EntryPoint1.class).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - List gets = entryPoints.get(HttpMethod.GET); + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider1()).addResource(EntryPoint1.class).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + List gets = entryPoints.get(HttpMethod.GET); - for (EntryPoint entryPoint : gets) { + for (Resource entryPoint : gets) { assertTrue(entryPoint.match("/api/dddd/")); } } @@ -107,12 +106,12 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void entryPoint2() { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider2()).addEntryPoint(EntryPoint2.class).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - List gets = entryPoints.get(HttpMethod.GET); + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider2()).addResource(EntryPoint2.class).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + List gets = entryPoints.get(HttpMethod.GET); - for (EntryPoint entryPoint : gets) { + for (Resource entryPoint : gets) { assertTrue(entryPoint.match("/dddd/")); } } @@ -133,10 +132,10 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void entryPoint3() { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider3()).addEntryPoint(EntryPoint3.class).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - EntryPoint entryPoint = entryPoints.get(HttpMethod.GET).get(0); + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider3()).addResource(EntryPoint3.class).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + Resource entryPoint = entryPoints.get(HttpMethod.GET).get(0); assertTrue(entryPoint.match("/")); @@ -174,10 +173,10 @@ public Object provide(Class clazz, HttpServletRequest request) { @Test // public void entryPoint4() { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider4()).addEntryPoint(EntryPoint4.class).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - EntryPoint entryPoint = entryPoints.get(HttpMethod.GET).get(0); + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider4()).addResource(EntryPoint4.class).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + Resource entryPoint = entryPoints.get(HttpMethod.GET).get(0); PathTemplate.PathValues values = entryPoint.parse("/api/"); assertEquals(PathValues.EMPTY, values); @@ -191,10 +190,10 @@ public void entryPoint4() { @Test // public void wow() { - RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider4()).addEntryPoint(EntryPoint4.class).build(); - EntryPointScanner f = new EntryPointScanner(config); - Map> entryPoints = f.scan(); - EntryPoint entryPoint = entryPoints.get(HttpMethod.HEAD).get(0); + RoutingConfig config = RoutingConfig.builder(new EntryPoint1Provider4()).addResource(EntryPoint4.class).build(); + ResourceScanner f = new ResourceScanner(config); + Map> entryPoints = f.scan(); + Resource entryPoint = entryPoints.get(HttpMethod.HEAD).get(0); assertEquals("wow.html", entryPoint.template()); } } diff --git a/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/Application.java b/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/Application.java index cb648a1..f147cde 100644 --- a/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/Application.java +++ b/demo-jetty/src/main/java/net/cactusthorn/routing/demo/jetty/Application.java @@ -76,8 +76,8 @@ private static ServletContextHandler createRoutingServlet() { // @formatter:off RoutingConfig config = RoutingConfig.builder(ComponentProvider) - .addEntryPoint(main.entryPoints().keySet()) - .addEntryPoint(main.sessionBuilder().build().entryPoints().keySet()) + .addResource(main.entryPoints().keySet()) + .addResource(main.sessionBuilder().build().entryPoints().keySet()) .addBodyWriter(new SimpleGsonBodyWriter<>()) .addBodyReader(new SimpleGsonBodyReader<>()) .addBodyWriter(new SimpleThymeleafBodyWriter("/thymeleaf/"))