From ed8f809a7891552d53bad1d32769f84d8ee315bd 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] 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);