From ad4ad3e774e9e7d6f79790581e26c3963bcc0a3a Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:44:04 -0500 Subject: [PATCH 1/2] fix name collision with java.util.logging --- .../java/io/avaje/jex/DefaultRouting.java | 36 +++++++++---------- .../{Handler.java => ExchangeHandler.java} | 2 +- .../src/main/java/io/avaje/jex/Routing.java | 30 ++++++++-------- .../java/io/avaje/jex/jdk/BaseHandler.java | 11 +++--- .../java/io/avaje/jex/jdk/RoutingFilter.java | 5 ++- .../java/io/avaje/jex/routes/RouteEntry.java | 6 ++-- .../java/io/avaje/jex/spi/SpiContext.java | 2 +- 7 files changed, 44 insertions(+), 48 deletions(-) rename avaje-jex/src/main/java/io/avaje/jex/{Handler.java => ExchangeHandler.java} (93%) diff --git a/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java b/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java index 4b2ef8a9..999aaddd 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java +++ b/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java @@ -94,7 +94,7 @@ public Routing withRoles(Role... permittedRoles) { return withRoles(Set.of(permittedRoles)); } - private void add(Type verb, String path, Handler handler) { + private void add(Type verb, String path, ExchangeHandler handler) { lastEntry = new Entry(verb, path(path), handler); handlers.add(lastEntry); } @@ -104,85 +104,85 @@ private void add(Type verb, String path, Handler handler) { // ******************************************************************************************** @Override - public Routing get(String path, Handler handler) { + public Routing get(String path, ExchangeHandler handler) { add(Type.GET, path, handler); return this; } @Override - public Routing get(Handler handler) { + public Routing get(ExchangeHandler handler) { get("", handler); return this; } @Override - public Routing post(String path, Handler handler) { + public Routing post(String path, ExchangeHandler handler) { add(Type.POST, path, handler); return this; } @Override - public Routing post(Handler handler) { + public Routing post(ExchangeHandler handler) { post("", handler); return this; } @Override - public Routing put(String path, Handler handler) { + public Routing put(String path, ExchangeHandler handler) { add(Type.PUT, path, handler); return this; } @Override - public Routing put(Handler handler) { + public Routing put(ExchangeHandler handler) { put("", handler); return this; } @Override - public Routing patch(String path, Handler handler) { + public Routing patch(String path, ExchangeHandler handler) { add(Type.PATCH, path, handler); return this; } @Override - public Routing patch(Handler handler) { + public Routing patch(ExchangeHandler handler) { patch("", handler); return this; } @Override - public Routing delete(String path, Handler handler) { + public Routing delete(String path, ExchangeHandler handler) { add(Type.DELETE, path, handler); return this; } @Override - public Routing delete(Handler handler) { + public Routing delete(ExchangeHandler handler) { delete("", handler); return this; } @Override - public Routing head(String path, Handler handler) { + public Routing head(String path, ExchangeHandler handler) { add(Type.HEAD, path, handler); return this; } @Override - public Routing head(Handler handler) { + public Routing head(ExchangeHandler handler) { head("", handler); return this; } @Override - public Routing trace(String path, Handler handler) { + public Routing trace(String path, ExchangeHandler handler) { add(Type.TRACE, path, handler); return this; } @Override - public Routing trace(Handler handler) { + public Routing trace(ExchangeHandler handler) { trace("", handler); return this; } @@ -201,10 +201,10 @@ private static class Entry implements Routing.Entry { private final Type type; private final String path; - private final Handler handler; + private final ExchangeHandler handler; private Set roles = Collections.emptySet(); - Entry(Type type, String path, Handler handler) { + Entry(Type type, String path, ExchangeHandler handler) { this.type = type; this.path = path; this.handler = handler; @@ -225,7 +225,7 @@ public String getPath() { } @Override - public Handler getHandler() { + public ExchangeHandler getHandler() { return handler; } diff --git a/avaje-jex/src/main/java/io/avaje/jex/Handler.java b/avaje-jex/src/main/java/io/avaje/jex/ExchangeHandler.java similarity index 93% rename from avaje-jex/src/main/java/io/avaje/jex/Handler.java rename to avaje-jex/src/main/java/io/avaje/jex/ExchangeHandler.java index aacbf15f..0a6a7d5c 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/Handler.java +++ b/avaje-jex/src/main/java/io/avaje/jex/ExchangeHandler.java @@ -5,7 +5,7 @@ * these handlers. */ @FunctionalInterface -public interface Handler { +public interface ExchangeHandler { /** * Handle the given request and generate an appropriate response. See {@link Context} for a diff --git a/avaje-jex/src/main/java/io/avaje/jex/Routing.java b/avaje-jex/src/main/java/io/avaje/jex/Routing.java index 064715a6..8779eae5 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/Routing.java +++ b/avaje-jex/src/main/java/io/avaje/jex/Routing.java @@ -63,72 +63,72 @@ public sealed interface Routing permits DefaultRouting { /** * Add a HEAD handler. */ - Routing head(String path, Handler handler); + Routing head(String path, ExchangeHandler handler); /** * Add a HEAD handler for "/". */ - Routing head(Handler handler); + Routing head(ExchangeHandler handler); /** * Add a GET handler. */ - Routing get(String path, Handler handler); + Routing get(String path, ExchangeHandler handler); /** * Add a GET handler for "/". */ - Routing get(Handler handler); + Routing get(ExchangeHandler handler); /** * Add a POST handler. */ - Routing post(String path, Handler handler); + Routing post(String path, ExchangeHandler handler); /** * Add a POST handler for "/". */ - Routing post(Handler handler); + Routing post(ExchangeHandler handler); /** * Add a PUT handler. */ - Routing put(String path, Handler handler); + Routing put(String path, ExchangeHandler handler); /** * Add a PUT handler for "/". */ - Routing put(Handler handler); + Routing put(ExchangeHandler handler); /** * Add a PATCH handler. */ - Routing patch(String path, Handler handler); + Routing patch(String path, ExchangeHandler handler); /** * Add a PATCH handler for "/". */ - Routing patch(Handler handler); + Routing patch(ExchangeHandler handler); /** * Add a DELETE handler. */ - Routing delete(String path, Handler handler); + Routing delete(String path, ExchangeHandler handler); /** * Add a DELETE handler for "/". */ - Routing delete(Handler handler); + Routing delete(ExchangeHandler handler); /** * Add a TRACE handler. */ - Routing trace(String path, Handler handler); + Routing trace(String path, ExchangeHandler handler); /** * Add a TRACE handler for "/". */ - Routing trace(Handler handler); + Routing trace(ExchangeHandler handler); /** * Add a filter for all requests. @@ -214,7 +214,7 @@ interface Entry { /** * Return the handler. */ - Handler getHandler(); + ExchangeHandler getHandler(); /** * Return the roles. diff --git a/avaje-jex/src/main/java/io/avaje/jex/jdk/BaseHandler.java b/avaje-jex/src/main/java/io/avaje/jex/jdk/BaseHandler.java index 04715a6b..4ae5d14c 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/jdk/BaseHandler.java +++ b/avaje-jex/src/main/java/io/avaje/jex/jdk/BaseHandler.java @@ -1,11 +1,9 @@ package io.avaje.jex.jdk; -import java.util.function.Consumer; - import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; -import io.avaje.jex.Context; +import io.avaje.jex.ExchangeHandler; import io.avaje.jex.Routing.Type; import io.avaje.jex.routes.SpiRoutes; @@ -25,12 +23,11 @@ void waitForIdle(long maxSeconds) { public void handle(HttpExchange exchange) { JdkContext ctx = (JdkContext) exchange.getAttribute("JdkContext"); - @SuppressWarnings("unchecked") - Consumer handlerConsumer = - (Consumer) exchange.getAttribute("SpiRoutes.Entry.Handler"); + ExchangeHandler handlerConsumer = + (ExchangeHandler) exchange.getAttribute("SpiRoutes.Entry.Handler"); ctx.setMode(null); - handlerConsumer.accept(ctx); + handlerConsumer.handle(ctx); ctx.setMode(Type.FILTER); } } diff --git a/avaje-jex/src/main/java/io/avaje/jex/jdk/RoutingFilter.java b/avaje-jex/src/main/java/io/avaje/jex/jdk/RoutingFilter.java index 35498273..a092f0cf 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/jdk/RoutingFilter.java +++ b/avaje-jex/src/main/java/io/avaje/jex/jdk/RoutingFilter.java @@ -2,12 +2,11 @@ import java.util.Map; import java.util.Set; -import java.util.function.Consumer; import com.sun.net.httpserver.Filter; import com.sun.net.httpserver.HttpExchange; -import io.avaje.jex.Context; +import io.avaje.jex.ExchangeHandler; import io.avaje.jex.Routing; import io.avaje.jex.Routing.Type; import io.avaje.jex.http.HttpResponseException; @@ -56,7 +55,7 @@ public void doFilter(HttpExchange exchange, Filter.Chain chain) { try { ctx.setMode(Type.FILTER); exchange.setAttribute("JdkContext", ctx); - Consumer handlerConsumer = route::handle; + ExchangeHandler handlerConsumer = route::handle; exchange.setAttribute("SpiRoutes.Entry.Handler", handlerConsumer); chain.doFilter(exchange); } catch (Exception e) { diff --git a/avaje-jex/src/main/java/io/avaje/jex/routes/RouteEntry.java b/avaje-jex/src/main/java/io/avaje/jex/routes/RouteEntry.java index 275989c8..48177a4f 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/routes/RouteEntry.java +++ b/avaje-jex/src/main/java/io/avaje/jex/routes/RouteEntry.java @@ -5,17 +5,17 @@ import java.util.concurrent.atomic.AtomicLong; import io.avaje.jex.Context; -import io.avaje.jex.Handler; +import io.avaje.jex.ExchangeHandler; import io.avaje.jex.security.Role; class RouteEntry implements SpiRoutes.Entry { private final AtomicLong active = new AtomicLong(); private final PathParser path; - private final Handler handler; + private final ExchangeHandler handler; private final Set roles; - RouteEntry(PathParser path, Handler handler, Set roles) { + RouteEntry(PathParser path, ExchangeHandler handler, Set roles) { this.path = path; this.handler = handler; this.roles = roles; diff --git a/avaje-jex/src/main/java/io/avaje/jex/spi/SpiContext.java b/avaje-jex/src/main/java/io/avaje/jex/spi/SpiContext.java index c75c3360..29a6ef9e 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/spi/SpiContext.java +++ b/avaje-jex/src/main/java/io/avaje/jex/spi/SpiContext.java @@ -29,7 +29,7 @@ public interface SpiContext extends Context { InputStream inputStream(); /** - * Set to indicate BEFORE, Handler and AFTER modes of the request. + * Set to indicate BEFORE, ExchangeHandler and AFTER modes of the request. */ void setMode(Routing.Type type); From 8bfc7eceab58697f867937434accbbbd3ca042af Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:50:22 -0500 Subject: [PATCH 2/2] fix service collision --- .../avaje/jex/render/freemarker/FreeMarkerRenderTest.java | 6 +++--- avaje-jex/src/main/java/io/avaje/jex/DJex.java | 6 +++--- avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java | 8 ++++---- avaje-jex/src/main/java/io/avaje/jex/Jex.java | 4 ++-- avaje-jex/src/main/java/io/avaje/jex/Routing.java | 8 ++++---- avaje-jex/src/main/java/io/avaje/jex/http/ErrorCode.java | 2 +- avaje-jex/src/main/java/io/avaje/jex/spi/JsonService.java | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/avaje-jex-freemarker/src/test/java/io/avaje/jex/render/freemarker/FreeMarkerRenderTest.java b/avaje-jex-freemarker/src/test/java/io/avaje/jex/render/freemarker/FreeMarkerRenderTest.java index 73017de3..2b8cdff8 100644 --- a/avaje-jex-freemarker/src/test/java/io/avaje/jex/render/freemarker/FreeMarkerRenderTest.java +++ b/avaje-jex-freemarker/src/test/java/io/avaje/jex/render/freemarker/FreeMarkerRenderTest.java @@ -17,21 +17,21 @@ class FreeMarkerRenderTest { static TestPair pair = init(); static TestPair init() { - final List services = List.of(new NoModel(), new WithModel()); + final List services = List.of(new NoModel(), new WithModel()); var app = Jex.create() .routing(services) .register(new FreeMarkerRender(), "ftl"); return TestPair.create(app); } - static class NoModel implements Routing.Service { + static class NoModel implements Routing.HttpService { @Override public void add(Routing routing) { routing.get("/noModel", ctx -> ctx.render("one.ftl")); } } - static class WithModel implements Routing.Service { + static class WithModel implements Routing.HttpService { @Override public void add(Routing routing) { routing.get("/withModel", ctx -> ctx.render("two.ftl", Map.of("message", "hello"))); diff --git a/avaje-jex/src/main/java/io/avaje/jex/DJex.java b/avaje-jex/src/main/java/io/avaje/jex/DJex.java index ed24cce8..f5fd7320 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/DJex.java +++ b/avaje-jex/src/main/java/io/avaje/jex/DJex.java @@ -36,13 +36,13 @@ public T attribute(Class cls) { } @Override - public Jex routing(Routing.Service routes) { + public Jex routing(Routing.HttpService routes) { routing.add(routes); return this; } @Override - public Jex routing(Collection routes) { + public Jex routing(Collection routes) { routing.addAll(routes); return this; } @@ -70,7 +70,7 @@ public Jex configureWith(BeanScope beanScope) { for (JexPlugin plugin : beanScope.list(JexPlugin.class)) { plugin.apply(this); } - routing.addAll(beanScope.list(Routing.Service.class)); + routing.addAll(beanScope.list(Routing.HttpService.class)); beanScope.getOptional(JsonService.class).ifPresent(this::jsonService); return this; } diff --git a/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java b/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java index 999aaddd..c0ef2a59 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java +++ b/avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java @@ -12,7 +12,7 @@ import io.avaje.jex.Routing.Entry; import io.avaje.jex.Routing.Group; -import io.avaje.jex.Routing.Service; +import io.avaje.jex.Routing.HttpService; import io.avaje.jex.Routing.Type; import io.avaje.jex.security.Role; @@ -55,14 +55,14 @@ private void addEndpoints(String path, Group group) { } @Override - public Routing add(Routing.Service routes) { + public Routing add(Routing.HttpService routes) { routes.add(this); return this; } @Override - public Routing addAll(Collection routes) { - for (Service route : routes) { + public Routing addAll(Collection routes) { + for (HttpService route : routes) { route.add(this); } return this; diff --git a/avaje-jex/src/main/java/io/avaje/jex/Jex.java b/avaje-jex/src/main/java/io/avaje/jex/Jex.java index b0e42346..459ccf91 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/Jex.java +++ b/avaje-jex/src/main/java/io/avaje/jex/Jex.java @@ -58,12 +58,12 @@ static Jex create() { /** * Add routes and handlers to the routing. */ - Jex routing(Routing.Service routes); + Jex routing(Routing.HttpService routes); /** * Add many routes and handlers to the routing. */ - Jex routing(Collection routes); + Jex routing(Collection routes); /** * Return the Routing to configure. diff --git a/avaje-jex/src/main/java/io/avaje/jex/Routing.java b/avaje-jex/src/main/java/io/avaje/jex/Routing.java index 8779eae5..f0deaf3f 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/Routing.java +++ b/avaje-jex/src/main/java/io/avaje/jex/Routing.java @@ -11,14 +11,14 @@ public sealed interface Routing permits DefaultRouting { /** - * Add the routes provided by the Routing Service. + * Add the routes provided by the Routing HttpService. */ - Routing add(Routing.Service routes); + Routing add(Routing.HttpService routes); /** * Add all the routes provided by the Routing Services. */ - Routing addAll(Collection routes); + Routing addAll(Collection routes); /** * Specify permittedRoles for the last added handler. @@ -186,7 +186,7 @@ interface Group { * Adds to the Routing. */ @FunctionalInterface - interface Service { + interface HttpService { /** * Add to the routing. diff --git a/avaje-jex/src/main/java/io/avaje/jex/http/ErrorCode.java b/avaje-jex/src/main/java/io/avaje/jex/http/ErrorCode.java index f1123dd4..f6b4bad8 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/http/ErrorCode.java +++ b/avaje-jex/src/main/java/io/avaje/jex/http/ErrorCode.java @@ -16,7 +16,7 @@ public enum ErrorCode { // 5xx Server Error INTERNAL_SERVER_ERROR(500, "Internal Server Error"), BAD_GATEWAY(502, "Bad Gateway"), - SERVICE_UNAVAILABLE(503, "Service Unavailable"), + SERVICE_UNAVAILABLE(503, "HttpService Unavailable"), GATEWAY_TIMEOUT(504, "Gateway Timeout"), HTTP_VERSION_NOT_SUPPORTED(505, "HTTP Version Not Supported"), VARIANT_ALSO_NEGOTIATES(506, "Variant Also Negotiates"), diff --git a/avaje-jex/src/main/java/io/avaje/jex/spi/JsonService.java b/avaje-jex/src/main/java/io/avaje/jex/spi/JsonService.java index 821c407c..91834abb 100644 --- a/avaje-jex/src/main/java/io/avaje/jex/spi/JsonService.java +++ b/avaje-jex/src/main/java/io/avaje/jex/spi/JsonService.java @@ -3,7 +3,7 @@ import java.util.Iterator; /** - * Service used to convert request/response bodies to beans. + * HttpService used to convert request/response bodies to beans. */ public non-sealed interface JsonService extends JexExtension {