mirror of
https://gitee.com/BDWare/front-base
synced 2025-01-09 01:13:59 +00:00
merge update
This commit is contained in:
parent
dffcadd116
commit
1785426e53
@ -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"
|
||||
}
|
||||
|
@ -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<io.netty.handler.codec.http.HttpMethod, List<Tuple<String, Method, Object>>> handlers;
|
||||
private Map<io.netty.handler.codec.http.HttpMethod, List<Tuple<String, Method, Object>>> handlers;
|
||||
|
||||
public URIHandler() {
|
||||
handlers = new HashMap<>();
|
||||
@ -59,15 +59,27 @@ public class URIHandler {
|
||||
});
|
||||
}
|
||||
|
||||
public Tuple<String, Method, Object> findHandler(FullHttpRequest msg) {
|
||||
List<Tuple<String, Method, Object>> handlerList = handlers.get(msg.method());
|
||||
for (Tuple<String, Method, Object> t : handlerList)
|
||||
if (msg.uri().startsWith(t.t)) {
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) {
|
||||
Tuple<String, Method, Object> t = findHandler(msg);
|
||||
handle(ctx, msg, t);
|
||||
}
|
||||
|
||||
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg,
|
||||
Tuple<String, Method, Object> t) {
|
||||
try {
|
||||
List<Tuple<String, Method, Object>> handlerList = handlers.get(msg.method());
|
||||
for (Tuple<String, Method, Object> 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, U, S> {
|
||||
T t;
|
||||
U u;
|
||||
S s;
|
||||
public static class Tuple<T, U, S> {
|
||||
public T t;
|
||||
public U u;
|
||||
public S s;
|
||||
|
||||
Tuple(T t, U u, S s) {
|
||||
this.t = t;
|
||||
|
Loading…
Reference in New Issue
Block a user