优化命名规范

This commit is contained in:
Redkale
2022-12-16 09:52:34 +08:00
parent d4def48c99
commit 8fd679d21f
10 changed files with 36 additions and 33 deletions

View File

@@ -36,6 +36,8 @@ public @interface Resource {
* 是否必须存在 * 是否必须存在
* *
* @return boolean * @return boolean
*
* @since 2.8.0
*/ */
public boolean required() default false; public boolean required() default false;

View File

@@ -149,8 +149,8 @@ public final class ApiDocCommand {
mappingMap.put("params", paramsList); mappingMap.put("params", paramsList);
List<String> results = new ArrayList<>(); List<String> results = new ArrayList<>();
Type resultType = action.result(); Type resultType = action.result();
if (!action.resultref().isEmpty()) { if (!action.resultRef().isEmpty()) {
Field f = servlet.getClass().getDeclaredField(action.resultref()); Field f = servlet.getClass().getDeclaredField(action.resultRef());
f.setAccessible(true); f.setAccessible(true);
resultType = (Type) f.get(servlet); resultType = (Type) f.get(servlet);
} }

View File

@@ -36,7 +36,7 @@ public class FilterWatchService extends AbstractWatchService {
protected Application application; protected Application application;
@RestMapping(name = "addFilter", auth = false, comment = "动态增加Filter") @RestMapping(name = "addFilter", auth = false, comment = "动态增加Filter")
public RetResult addFilter(@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar, public RetResult addFilter(@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameRegx = "\\.jar$") byte[] jar,
@RestParam(name = "server", comment = "Server节点名") final String serverName, @RestParam(name = "server", comment = "Server节点名") final String serverName,
@RestParam(name = "type", comment = "Filter类名") final String filterType) throws IOException { @RestParam(name = "type", comment = "Filter类名") final String filterType) throws IOException {
if (filterType == null) return new RetResult(RET_FILTER_TYPE_NOT_EXISTS, "Not found Filter Type (" + filterType + ")"); if (filterType == null) return new RetResult(RET_FILTER_TYPE_NOT_EXISTS, "Not found Filter Type (" + filterType + ")");

View File

@@ -171,7 +171,7 @@ public class ServiceWatchService extends AbstractWatchService {
@RestMapping(name = "loadService", auth = false, comment = "动态增加Service") @RestMapping(name = "loadService", auth = false, comment = "动态增加Service")
public RetResult loadService(@RestParam(name = "type", comment = "Service的类名") String type, public RetResult loadService(@RestParam(name = "type", comment = "Service的类名") String type,
@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) { @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameRegx = "\\.jar$") byte[] jar) {
//待开发 //待开发
return RetResult.success(); return RetResult.success();
} }

View File

@@ -51,7 +51,7 @@ public @interface HttpMapping {
* *
* @return int * @return int
*/ */
int cacheseconds() default 0; int cacheSeconds() default 0;
/** /**
* 是否只接受RPC请求 默认为false * 是否只接受RPC请求 默认为false
@@ -95,7 +95,7 @@ public @interface HttpMapping {
* @since 2.5.0 * @since 2.5.0
* @return String * @return String
*/ */
String resultref() default ""; String resultRef() default "";
/** /**
* 输出结果的数据类型集合,由于结果类型可能是泛型而注解的参数值不支持泛型,因此加入明细数据类型集合 * 输出结果的数据类型集合,由于结果类型可能是泛型而注解的参数值不支持泛型,因此加入明细数据类型集合

View File

@@ -61,9 +61,9 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
} }
} }
} }
if (entry.cacheseconds > 0) {//有缓存设置 if (entry.cacheSeconds > 0) {//有缓存设置
CacheEntry ce = entry.modeOneCache ? entry.oneCache : entry.cache.get(request.getRequestURI()); CacheEntry ce = entry.modeOneCache ? entry.oneCache : entry.cache.get(request.getRequestURI());
if (ce != null && ce.time + entry.cacheseconds * 1000 > System.currentTimeMillis()) { //缓存有效 if (ce != null && ce.time + entry.cacheSeconds * 1000 > System.currentTimeMillis()) { //缓存有效
response.setStatus(ce.status); response.setStatus(ce.status);
response.setContentType(ce.contentType); response.setContentType(ce.contentType);
response.skipHeader(); response.skipHeader();
@@ -276,12 +276,12 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
protected static final class ActionEntry { protected static final class ActionEntry {
ActionEntry(int moduleid, int actionid, String name, String[] methods, Method method, HttpServlet servlet) { ActionEntry(int moduleid, int actionid, String name, String[] methods, Method method, HttpServlet servlet) {
this(moduleid, actionid, name, methods, method, rpconly(method), auth(method), cacheseconds(method), servlet); this(moduleid, actionid, name, methods, method, rpconly(method), auth(method), cacheSeconds(method), servlet);
this.annotations = annotations(method); this.annotations = annotations(method);
} }
//供Rest类使用参数不能随便更改 //供Rest类使用参数不能随便更改
public ActionEntry(int moduleid, int actionid, String name, String[] methods, Method method, boolean rpconly, boolean auth, int cacheseconds, HttpServlet servlet) { public ActionEntry(int moduleid, int actionid, String name, String[] methods, Method method, boolean rpconly, boolean auth, int cacheSeconds, HttpServlet servlet) {
this.moduleid = moduleid; this.moduleid = moduleid;
this.actionid = actionid; this.actionid = actionid;
this.name = name; this.name = name;
@@ -290,11 +290,11 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
this.servlet = servlet; this.servlet = servlet;
this.rpconly = rpconly; this.rpconly = rpconly;
this.auth = auth; this.auth = auth;
this.cacheseconds = cacheseconds; this.cacheSeconds = cacheSeconds;
if (Utility.contains(name, '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\') || name.endsWith("/")) { //是否是正则表达式 if (Utility.contains(name, '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\') || name.endsWith("/")) { //是否是正则表达式
this.modeOneCache = false; this.modeOneCache = false;
this.cache = cacheseconds > 0 ? new ConcurrentHashMap<>() : null; this.cache = cacheSeconds > 0 ? new ConcurrentHashMap<>() : null;
this.cacheHandler = cacheseconds > 0 ? (HttpResponse response, byte[] content) -> { this.cacheHandler = cacheSeconds > 0 ? (HttpResponse response, byte[] content) -> {
int status = response.getStatus(); int status = response.getStatus();
if (status != 200) return; if (status != 200) return;
CacheEntry ce = new CacheEntry(response.getStatus(), response.getContentType(), content); CacheEntry ce = new CacheEntry(response.getStatus(), response.getContentType(), content);
@@ -303,7 +303,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
} else { //单一url } else { //单一url
this.modeOneCache = true; this.modeOneCache = true;
this.cache = null; this.cache = null;
this.cacheHandler = cacheseconds > 0 ? (HttpResponse response, byte[] content) -> { this.cacheHandler = cacheSeconds > 0 ? (HttpResponse response, byte[] content) -> {
int status = response.getStatus(); int status = response.getStatus();
if (status != 200) return; if (status != 200) return;
oneCache = new CacheEntry(response.getStatus(), response.getContentType(), content); oneCache = new CacheEntry(response.getStatus(), response.getContentType(), content);
@@ -321,9 +321,9 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
return mapping == null || mapping.rpconly(); return mapping == null || mapping.rpconly();
} }
protected static int cacheseconds(Method method) { protected static int cacheSeconds(Method method) {
HttpMapping mapping = method.getAnnotation(HttpMapping.class); HttpMapping mapping = method.getAnnotation(HttpMapping.class);
return mapping == null ? 0 : mapping.cacheseconds(); return mapping == null ? 0 : mapping.cacheSeconds();
} }
//Rest.class会用到此方法 //Rest.class会用到此方法
@@ -349,7 +349,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
final boolean modeOneCache; final boolean modeOneCache;
final int cacheseconds; final int cacheSeconds;
final boolean rpconly; final boolean rpconly;

View File

@@ -1788,7 +1788,7 @@ public final class Rest {
av0.visit("example", entry.example); av0.visit("example", entry.example);
av0.visit("rpconly", entry.rpconly); av0.visit("rpconly", entry.rpconly);
av0.visit("auth", entry.auth); av0.visit("auth", entry.auth);
av0.visit("cacheseconds", entry.cacheseconds); av0.visit("cacheSeconds", entry.cacheSeconds);
av0.visit("actionid", entry.actionid); av0.visit("actionid", entry.actionid);
av0.visit("comment", entry.comment); av0.visit("comment", entry.comment);
@@ -1815,14 +1815,14 @@ public final class Rest {
refid = "_typeref_" + typeRefs.size(); refid = "_typeref_" + typeRefs.size();
typeRefs.put(returnGenericNoFutureType, refid); typeRefs.put(returnGenericNoFutureType, refid);
} }
av0.visit("resultref", refid); av0.visit("resultRef", refid);
} }
av0.visitEnd(); av0.visitEnd();
mappingMap.put("url", url); mappingMap.put("url", url);
mappingMap.put("rpconly", entry.rpconly); mappingMap.put("rpconly", entry.rpconly);
mappingMap.put("auth", entry.auth); mappingMap.put("auth", entry.auth);
mappingMap.put("cacheseconds", entry.cacheseconds); mappingMap.put("cacheSeconds", entry.cacheSeconds);
mappingMap.put("actionid", entry.actionid); mappingMap.put("actionid", entry.actionid);
mappingMap.put("comment", entry.comment); mappingMap.put("comment", entry.comment);
mappingMap.put("methods", entry.methods); mappingMap.put("methods", entry.methods);
@@ -1928,8 +1928,8 @@ public final class Rest {
mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getMultiContext", "()" + multiContextDesc, false); mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getMultiContext", "()" + multiContextDesc, false);
mv.visitLdcInsn(mupload.maxLength()); mv.visitLdcInsn(mupload.maxLength());
mv.visitLdcInsn(mupload.fileNameReg()); mv.visitLdcInsn(mupload.fileNameRegx());
mv.visitLdcInsn(mupload.contentTypeReg()); mv.visitLdcInsn(mupload.contentTypeRegx());
mv.visitMethodInsn(INVOKEVIRTUAL, multiContextName, "partsFirstBytes", "(JLjava/lang/String;Ljava/lang/String;)[B", false); mv.visitMethodInsn(INVOKEVIRTUAL, multiContextName, "partsFirstBytes", "(JLjava/lang/String;Ljava/lang/String;)[B", false);
mv.visitVarInsn(ASTORE, maxLocals); mv.visitVarInsn(ASTORE, maxLocals);
uploadLocal = maxLocals; uploadLocal = maxLocals;
@@ -1939,8 +1939,8 @@ public final class Rest {
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, "_redkale_home", "Ljava/io/File;"); mv.visitFieldInsn(GETFIELD, newDynName, "_redkale_home", "Ljava/io/File;");
mv.visitLdcInsn(mupload.maxLength()); mv.visitLdcInsn(mupload.maxLength());
mv.visitLdcInsn(mupload.fileNameReg()); mv.visitLdcInsn(mupload.fileNameRegx());
mv.visitLdcInsn(mupload.contentTypeReg()); mv.visitLdcInsn(mupload.contentTypeRegx());
mv.visitMethodInsn(INVOKEVIRTUAL, multiContextName, "partsFirstFile", "(Ljava/io/File;JLjava/lang/String;Ljava/lang/String;)Ljava/io/File;", false); mv.visitMethodInsn(INVOKEVIRTUAL, multiContextName, "partsFirstFile", "(Ljava/io/File;JLjava/lang/String;Ljava/lang/String;)Ljava/io/File;", false);
mv.visitVarInsn(ASTORE, maxLocals); mv.visitVarInsn(ASTORE, maxLocals);
uploadLocal = maxLocals; uploadLocal = maxLocals;
@@ -1950,8 +1950,8 @@ public final class Rest {
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, "_redkale_home", "Ljava/io/File;"); mv.visitFieldInsn(GETFIELD, newDynName, "_redkale_home", "Ljava/io/File;");
mv.visitLdcInsn(mupload.maxLength()); mv.visitLdcInsn(mupload.maxLength());
mv.visitLdcInsn(mupload.fileNameReg()); mv.visitLdcInsn(mupload.fileNameRegx());
mv.visitLdcInsn(mupload.contentTypeReg()); mv.visitLdcInsn(mupload.contentTypeRegx());
mv.visitMethodInsn(INVOKEVIRTUAL, multiContextName, "partsFiles", "(Ljava/io/File;JLjava/lang/String;Ljava/lang/String;)[Ljava/io/File;", false); mv.visitMethodInsn(INVOKEVIRTUAL, multiContextName, "partsFiles", "(Ljava/io/File;JLjava/lang/String;Ljava/lang/String;)[Ljava/io/File;", false);
mv.visitVarInsn(ASTORE, maxLocals); mv.visitVarInsn(ASTORE, maxLocals);
uploadLocal = maxLocals; uploadLocal = maxLocals;
@@ -2867,7 +2867,7 @@ public final class Rest {
mv.visitInsn(ACONST_NULL); //method mv.visitInsn(ACONST_NULL); //method
mv.visitInsn(entry.rpconly ? ICONST_1 : ICONST_0); //rpconly mv.visitInsn(entry.rpconly ? ICONST_1 : ICONST_0); //rpconly
mv.visitInsn(entry.auth ? ICONST_1 : ICONST_0); //auth mv.visitInsn(entry.auth ? ICONST_1 : ICONST_0); //auth
MethodDebugVisitor.pushInt(mv, entry.cacheseconds); //cacheseconds MethodDebugVisitor.pushInt(mv, entry.cacheSeconds); //cacheSeconds
mv.visitTypeInsn(NEW, newDynName + "$" + entry.newActionClassName); mv.visitTypeInsn(NEW, newDynName + "$" + entry.newActionClassName);
mv.visitInsn(DUP); mv.visitInsn(DUP);
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);
@@ -3137,7 +3137,7 @@ public final class Rest {
this.auth = mapping.auth(); this.auth = mapping.auth();
this.rpconly = serrpconly || mapping.rpconly(); this.rpconly = serrpconly || mapping.rpconly();
this.actionid = mapping.actionid(); this.actionid = mapping.actionid();
this.cacheseconds = mapping.cacheseconds(); this.cacheSeconds = mapping.cacheSeconds();
this.comment = mapping.comment(); this.comment = mapping.comment();
boolean pound = false; boolean pound = false;
Parameter[] params = method.getParameters(); Parameter[] params = method.getParameters();
@@ -3177,7 +3177,7 @@ public final class Rest {
public final int actionid; public final int actionid;
public final int cacheseconds; public final int cacheSeconds;
public final boolean existsPound; //是否包含#的参数 public final boolean existsPound; //是否包含#的参数

View File

@@ -67,11 +67,11 @@ public @interface RestMapping {
int actionid() default 0; int actionid() default 0;
/** /**
* 结果缓存的秒数, 为0表示不缓存, 对应&#64;HttpMapping.cacheseconds * 结果缓存的秒数, 为0表示不缓存, 对应&#64;HttpMapping.cacheSeconds
* *
* @return int * @return int
*/ */
int cacheseconds() default 0; int cacheSeconds() default 0;
/** /**
* 允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法, 对应&#64;HttpMapping.methods * 允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法, 对应&#64;HttpMapping.methods

View File

@@ -37,14 +37,14 @@ public @interface RestUploadFile {
* *
* @return String * @return String
*/ */
String fileNameReg() default ""; String fileNameRegx() default "";
/** /**
* 可接收的ContentType正则表达式, 为空表示接收任何文件类型 <br> * 可接收的ContentType正则表达式, 为空表示接收任何文件类型 <br>
* *
* @return String * @return String
*/ */
String contentTypeReg() default ""; String contentTypeRegx() default "";
/** /**
* 备注描述, 对应&#64;HttpParam.comment * 备注描述, 对应&#64;HttpParam.comment

View File

@@ -229,6 +229,7 @@ public class RetResult<T> implements Serializable {
@Deprecated @Deprecated
public RetResult<T> attach(Map<String, String> attach) { public RetResult<T> attach(Map<String, String> attach) {
this.attach = attach; this.attach = attach;
System.err.println("RetResult.attach is deprecated");
return this; return this;
} }