diff --git a/build.gradle b/build.gradle index bf02cca..ce5ebf8 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ dependencies { api 'com.google.code.gson:gson:2.8.8' testImplementation 'junit:junit:4.13.2' } -version = "1.0.0" +version = "1.0.1" task classJar(type: Jar, dependsOn: classes) { classifier = "jar" } diff --git a/src/main/src/org/bdware/server/http/URIHandler.java b/src/main/src/org/bdware/server/http/URIHandler.java index 86c243a..391b73e 100644 --- a/src/main/src/org/bdware/server/http/URIHandler.java +++ b/src/main/src/org/bdware/server/http/URIHandler.java @@ -17,7 +17,7 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; public class URIHandler { private static final Logger LOGGER = LogManager.getLogger(URIHandler.class); - Map>> handlers; + private Map>> handlers; public URIHandler() { handlers = new HashMap<>(); @@ -59,15 +59,27 @@ public class URIHandler { }); } + public Tuple findHandler(FullHttpRequest msg) { + List> handlerList = handlers.get(msg.method()); + for (Tuple t : handlerList) + if (msg.uri().startsWith(t.t)) { + return t; + } + return null; + } + public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) { + Tuple t = findHandler(msg); + handle(ctx, msg, t); + } + + public void handle(ChannelHandlerContext ctx, FullHttpRequest msg, + Tuple t) { try { - List> handlerList = handlers.get(msg.method()); - for (Tuple t : handlerList) - if (msg.uri().startsWith(t.t)) { - t.u.invoke(t.s, ctx, msg); - return; - } - sendUnsupported(ctx); + if (t != null) + t.u.invoke(t.s, ctx, msg); + else + sendUnsupported(ctx); } catch (Exception e) { e.printStackTrace(); } @@ -95,10 +107,10 @@ public class URIHandler { ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } - static class Tuple { - T t; - U u; - S s; + public static class Tuple { + public T t; + public U u; + public S s; Tuple(T t, U u, S s) { this.t = t;