Skip to content

Commit

Permalink
fix name collision with java.util.logging
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Nov 23, 2024
1 parent 95592d9 commit ed8f809
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 48 deletions.
36 changes: 18 additions & 18 deletions avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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<Role> 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;
Expand All @@ -225,7 +225,7 @@ public String getPath() {
}

@Override
public Handler getHandler() {
public ExchangeHandler getHandler() {
return handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions avaje-jex/src/main/java/io/avaje/jex/Routing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -214,7 +214,7 @@ interface Entry {
/**
* Return the handler.
*/
Handler getHandler();
ExchangeHandler getHandler();

/**
* Return the roles.
Expand Down
11 changes: 4 additions & 7 deletions avaje-jex/src/main/java/io/avaje/jex/jdk/BaseHandler.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -25,12 +23,11 @@ void waitForIdle(long maxSeconds) {
public void handle(HttpExchange exchange) {

JdkContext ctx = (JdkContext) exchange.getAttribute("JdkContext");
@SuppressWarnings("unchecked")
Consumer<Context> handlerConsumer =
(Consumer<Context>) 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);
}
}
5 changes: 2 additions & 3 deletions avaje-jex/src/main/java/io/avaje/jex/jdk/RoutingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +55,7 @@ public void doFilter(HttpExchange exchange, Filter.Chain chain) {
try {
ctx.setMode(Type.FILTER);
exchange.setAttribute("JdkContext", ctx);
Consumer<Context> handlerConsumer = route::handle;
ExchangeHandler handlerConsumer = route::handle;
exchange.setAttribute("SpiRoutes.Entry.Handler", handlerConsumer);
chain.doFilter(exchange);
} catch (Exception e) {
Expand Down
6 changes: 3 additions & 3 deletions avaje-jex/src/main/java/io/avaje/jex/routes/RouteEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Role> roles;

RouteEntry(PathParser path, Handler handler, Set<Role> roles) {
RouteEntry(PathParser path, ExchangeHandler handler, Set<Role> roles) {
this.path = path;
this.handler = handler;
this.roles = roles;
Expand Down
2 changes: 1 addition & 1 deletion avaje-jex/src/main/java/io/avaje/jex/spi/SpiContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ed8f809

Please sign in to comment.