Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix name collision with JDK 23 module imports #69

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ class FreeMarkerRenderTest {
static TestPair pair = init();

static TestPair init() {
final List<Routing.Service> services = List.of(new NoModel(), new WithModel());
final List<Routing.HttpService> 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")));
Expand Down
6 changes: 3 additions & 3 deletions avaje-jex/src/main/java/io/avaje/jex/DJex.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public <T> T attribute(Class<T> cls) {
}

@Override
public Jex routing(Routing.Service routes) {
public Jex routing(Routing.HttpService routes) {
routing.add(routes);
return this;
}

@Override
public Jex routing(Collection<Routing.Service> routes) {
public Jex routing(Collection<Routing.HttpService> routes) {
routing.addAll(routes);
return this;
}
Expand Down Expand Up @@ -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;
}
Expand Down
44 changes: 22 additions & 22 deletions avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Routing.Service> routes) {
for (Service route : routes) {
public Routing addAll(Collection<Routing.HttpService> routes) {
for (HttpService route : routes) {
route.add(this);
}
return this;
Expand Down 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
4 changes: 2 additions & 2 deletions avaje-jex/src/main/java/io/avaje/jex/Jex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Routing.Service> routes);
Jex routing(Collection<Routing.HttpService> routes);

/**
* Return the Routing to configure.
Expand Down
38 changes: 19 additions & 19 deletions avaje-jex/src/main/java/io/avaje/jex/Routing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Routing.Service> routes);
Routing addAll(Collection<Routing.HttpService> routes);

/**
* Specify permittedRoles for the last added handler.
Expand Down 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 @@ -186,7 +186,7 @@ interface Group {
* Adds to the Routing.
*/
@FunctionalInterface
interface Service {
interface HttpService {

/**
* Add to the routing.
Expand Down Expand Up @@ -214,7 +214,7 @@ interface Entry {
/**
* Return the handler.
*/
Handler getHandler();
ExchangeHandler getHandler();

/**
* Return the roles.
Expand Down
2 changes: 1 addition & 1 deletion avaje-jex/src/main/java/io/avaje/jex/http/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
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);
}
}
Loading
Loading