Skip to content

Commit

Permalink
handle checked exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Dec 2, 2024
1 parent 99193d7 commit 6059327
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
16 changes: 7 additions & 9 deletions avaje-jex-htmx/src/main/java/io/avaje/jex/htmx/DHxHandler.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.avaje.jex.htmx;

import static io.avaje.jex.htmx.HxHeaders.HX_REQUEST;
import static io.avaje.jex.htmx.HxHeaders.HX_TARGET;
import static io.avaje.jex.htmx.HxHeaders.HX_TRIGGER;
import static io.avaje.jex.htmx.HxHeaders.HX_TRIGGER_NAME;

import io.avaje.jex.Context;
import io.avaje.jex.ExchangeHandler;

import java.io.IOException;

import static io.avaje.jex.htmx.HxHeaders.*;

final class DHxHandler implements ExchangeHandler {

private final ExchangeHandler delegate;
Expand All @@ -22,17 +23,14 @@ final class DHxHandler implements ExchangeHandler {
}

@Override
public void handle(Context ctx) throws IOException {
public void handle(Context ctx) throws Exception {
if (ctx.header(HX_REQUEST) != null && matched(ctx)) {
delegate.handle(ctx);
}
}

private boolean matched(Context ctx) {
if (target != null && notMatched(ctx.header(HX_TARGET), target)) {
return false;
}
if (trigger != null && notMatched(ctx.header(HX_TRIGGER), trigger)) {
if ((target != null && notMatched(ctx.header(HX_TARGET), target)) || (trigger != null && notMatched(ctx.header(HX_TRIGGER), trigger))) {
return false;
}
return triggerName == null || !notMatched(ctx.header(HX_TRIGGER_NAME), triggerName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.avaje.jex.core;

import java.io.IOException;
import java.util.List;
import java.util.ListIterator;

Expand Down
7 changes: 3 additions & 4 deletions avaje-jex/src/main/java/io/avaje/jex/core/RoutingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.sun.net.httpserver.HttpHandler;

import io.avaje.jex.HttpFilter;
import io.avaje.jex.Routing;
import io.avaje.jex.compression.CompressionConfig;
import io.avaje.jex.http.NotFoundException;
import io.avaje.jex.routes.SpiRoutes;
Expand All @@ -34,9 +33,9 @@ void waitForIdle(long maxSeconds) {

@Override
public void handle(HttpExchange exchange) {
final String uri = exchange.getRequestURI().getPath();
final Routing.Type routeType = mgr.lookupRoutingType(exchange.getRequestMethod());
final SpiRoutes.Entry route = routes.match(routeType, uri);
final var uri = exchange.getRequestURI().getPath();
final var routeType = mgr.lookupRoutingType(exchange.getRequestMethod());
final var route = routes.match(routeType, uri);

if (route == null) {
var ctx = new JdkContext(mgr, compressionConfig, exchange, uri, Set.of());
Expand Down

0 comments on commit 6059327

Please sign in to comment.