From 404e1b8eeef45043b40c6bb1334c43407b8d2bae Mon Sep 17 00:00:00 2001 From: redkale Date: Mon, 9 Oct 2023 22:05:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/redkale/boot/Application.java | 4 ++++ .../java/org/redkale/net/http/HttpServer.java | 2 +- src/main/java/org/redkale/net/http/Rest.java | 17 ++++++++++++++--- .../java/org/redkale/util/ResourceFactory.java | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/redkale/boot/Application.java b/src/main/java/org/redkale/boot/Application.java index d7ddbd9b3..06d81bd56 100644 --- a/src/main/java/org/redkale/boot/Application.java +++ b/src/main/java/org/redkale/boot/Application.java @@ -1493,6 +1493,7 @@ public final class Application { } } catch (Exception e) { logger.log(Level.INFO, "Control fail", e); + Utility.sleep(100); System.exit(1); } } @@ -1829,6 +1830,7 @@ public final class Application { } if (server == null) { logger.log(Level.SEVERE, "Not found Server Class for protocol({0})", serconf.getValue("protocol")); + Utility.sleep(100); System.exit(1); } server.init(serconf); @@ -1843,6 +1845,7 @@ public final class Application { } catch (Exception ex) { logger.log(Level.WARNING, serconf + " runServers error", ex); Application.this.shutdownLatch.countDown(); + Utility.sleep(100); System.exit(1); } } @@ -2066,6 +2069,7 @@ public final class Application { application.start(); } catch (Exception e) { application.logger.log(Level.SEVERE, "Application start error", e); + Utility.sleep(100); System.exit(1); } System.exit(0); //必须要有 diff --git a/src/main/java/org/redkale/net/http/HttpServer.java b/src/main/java/org/redkale/net/http/HttpServer.java index 3f0beba12..2f93f3faa 100644 --- a/src/main/java/org/redkale/net/http/HttpServer.java +++ b/src/main/java/org/redkale/net/http/HttpServer.java @@ -319,7 +319,7 @@ public class HttpServer extends Server T createRestServlet(final ClassLoader classLoader, final Class userType0, - final Class baseServletType, final Class serviceType) { + final Class baseServletType, final Class serviceType, String serviceResourceName) { if (baseServletType == null || serviceType == null) { throw new RestException(" Servlet or Service is null Class on createRestServlet"); @@ -1112,8 +1112,19 @@ public final class Rest { } else { stname = stname.replaceAll("Service.*$", ""); } + String namePostfix = Utility.isBlank(serviceResourceName) ? "" : serviceResourceName; + for (char ch : namePostfix.toCharArray()) { + if ((ch == '$' || ch == '_' || (ch >= '0' && ch <= '9') + || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { + continue; + } + //带特殊字符的值不能作为类名的后缀 + namePostfix = Utility.md5Hex(namePostfix); + break; + } //String newDynName = serviceTypeInternalName.substring(0, serviceTypeInternalName.lastIndexOf('/') + 1) + "_Dyn" + stname + "RestServlet"; - final String newDynName = "org/redkaledyn/http/rest/" + "_Dyn" + stname + "RestServlet__" + serviceType.getName().replace('.', '_').replace('$', '_') + "DynServlet"; + final String newDynName = "org/redkaledyn/http/rest/" + "_Dyn" + stname + "RestServlet__" + serviceType.getName().replace('.', '_').replace('$', '_') + + (namePostfix.isEmpty() ? "" : ("_" + namePostfix) + "DynServlet"); try { Class newClazz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.')); @@ -1779,7 +1790,7 @@ public final class Rest { { //注入 @Resource private XXXService _service; fv = cw.visitField(ACC_PRIVATE, REST_SERVICE_FIELD_NAME, serviceDesc, null, null); av0 = fv.visitAnnotation(resDesc, true); - av0.visit("name", ""); + av0.visit("name", Utility.isBlank(serviceResourceName) ? "" : serviceResourceName); av0.visitEnd(); fv.visitEnd(); } diff --git a/src/main/java/org/redkale/util/ResourceFactory.java b/src/main/java/org/redkale/util/ResourceFactory.java index 5bcd2c011..5e8d9af16 100644 --- a/src/main/java/org/redkale/util/ResourceFactory.java +++ b/src/main/java/org/redkale/util/ResourceFactory.java @@ -1010,7 +1010,7 @@ public final class ResourceFactory { } if (rs == null && rc1 != null && rc1.required()) { String t = srcObj.getClass().getName(); - if (srcObj.getClass().getSimpleName().startsWith("_Dyn")) { + if (srcObj.getClass().getSimpleName().startsWith("_Dyn") && !srcObj.getClass().getSimpleName().contains("__")) { t = srcObj.getClass().getSuperclass().getName(); } throw new RedkaleException("resource(type=" + field.getType().getSimpleName() + ".class, field=" + field.getName() + ", name='" + rcname + "') must exists in " + t);