From a834b6ea21bc9087413329a122b3a35c4dd60cc5 Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Sat, 19 Sep 2020 20:23:51 +0800 Subject: [PATCH] --- src/org/redkale/net/http/HttpServlet.java | 47 +++++++++-------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/org/redkale/net/http/HttpServlet.java b/src/org/redkale/net/http/HttpServlet.java index 2096e6070..0a8e912d8 100644 --- a/src/org/redkale/net/http/HttpServlet.java +++ b/src/org/redkale/net/http/HttpServlet.java @@ -39,8 +39,6 @@ public class HttpServlet extends Servlet private Map.Entry[] mappings; //字段名Rest有用到 - private Map mappingMap; - //这里不能直接使用HttpServlet,会造成死循环初始化HttpServlet private final Servlet authSuccessServlet = new Servlet() { @Override @@ -68,34 +66,28 @@ public class HttpServlet extends Servlet private final Servlet preSuccessServlet = new Servlet() { @Override public void execute(HttpRequest request, HttpResponse response) throws IOException { - InnerActionEntry entry = mappingMap.get(request.getRequestURI()); - if (entry == null) { - for (Map.Entry en : mappings) { - if (request.getRequestURI().startsWith(en.getKey() + "/")) { - entry = en.getValue(); - break; + for (Map.Entry en : mappings) { + if (request.getRequestURI().startsWith(en.getKey())) { + InnerActionEntry entry = en.getValue(); + if (!entry.checkMethod(request.getMethod())) { + response.finishJson(new RetResult(RET_METHOD_ERROR, "Method(" + request.getMethod() + ") Error")); + return; } + request.attachment = entry; + request.moduleid = entry.moduleid; + request.actionid = entry.actionid; + request.annotations = entry.annotations; + if (entry.auth) { + response.thenEvent(authSuccessServlet); + authenticate(request, response); + } else { + authSuccessServlet.execute(request, response); + } + return; } } - if (entry == null) { - response.finish404(); - //throw new IOException(this.getClass().getName() + " not found method for URI(" + request.getRequestURI() + ")"); - return; - } - if (!entry.checkMethod(request.getMethod())) { - response.finishJson(new RetResult(RET_METHOD_ERROR, "Method(" + request.getMethod() + ") Error")); - return; - } - request.attachment = entry; - request.moduleid = entry.moduleid; - request.actionid = entry.actionid; - request.annotations = entry.annotations; - if (entry.auth) { - response.thenEvent(authSuccessServlet); - authenticate(request, response); - } else { - authSuccessServlet.execute(request, response); - } + response.finish404(); + //throw new IOException(this.getClass().getName() + " not found method for URI(" + request.getRequestURI() + ")"); } }; @@ -106,7 +98,6 @@ public class HttpServlet extends Servlet WebServlet ws = this.getClass().getAnnotation(WebServlet.class); if (ws != null && !ws.repair()) path = ""; HashMap map = this._tmpentrys != null ? this._tmpentrys : loadActionEntry(); - this.mappingMap = map; this.mappings = new Map.Entry[map.size()]; int i = -1; for (Map.Entry en : map.entrySet()) {