This commit is contained in:
redkale
2023-10-09 22:05:57 +08:00
parent 2fd56afe2a
commit 404e1b8eee
4 changed files with 20 additions and 5 deletions

View File

@@ -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); //必须要有

View File

@@ -319,7 +319,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
}
final boolean first = servlet == null;
if (servlet == null) {
servlet = Rest.createRestServlet(classLoader, userType, baseServletType, serviceType);
servlet = Rest.createRestServlet(classLoader, userType, baseServletType, serviceType, resname);
if (servlet != null) {
servlet._reqtopic = MessageAgent.generateHttpReqTopic(Rest.getRestModule(service));
}

View File

@@ -994,7 +994,7 @@ public final class Rest {
}
public static <T extends HttpServlet> T createRestServlet(final ClassLoader classLoader, final Class userType0,
final Class<T> baseServletType, final Class<? extends Service> serviceType) {
final Class<T> baseServletType, final Class<? extends Service> 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();
}

View File

@@ -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);