优化命名规范

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
*
* @since 2.8.0
*/
public boolean required() default false;

View File

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

View File

@@ -36,7 +36,7 @@ public class FilterWatchService extends AbstractWatchService {
protected Application application;
@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 = "type", comment = "Filter类名") final String filterType) throws IOException {
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")
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();
}

View File

@@ -51,7 +51,7 @@ public @interface HttpMapping {
*
* @return int
*/
int cacheseconds() default 0;
int cacheSeconds() default 0;
/**
* 是否只接受RPC请求 默认为false
@@ -95,7 +95,7 @@ public @interface HttpMapping {
* @since 2.5.0
* @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());
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.setContentType(ce.contentType);
response.skipHeader();
@@ -276,12 +276,12 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
protected static final class ActionEntry {
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);
}
//供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.actionid = actionid;
this.name = name;
@@ -290,11 +290,11 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
this.servlet = servlet;
this.rpconly = rpconly;
this.auth = auth;
this.cacheseconds = cacheseconds;
this.cacheSeconds = cacheSeconds;
if (Utility.contains(name, '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\') || name.endsWith("/")) { //是否是正则表达式
this.modeOneCache = false;
this.cache = cacheseconds > 0 ? new ConcurrentHashMap<>() : null;
this.cacheHandler = cacheseconds > 0 ? (HttpResponse response, byte[] content) -> {
this.cache = cacheSeconds > 0 ? new ConcurrentHashMap<>() : null;
this.cacheHandler = cacheSeconds > 0 ? (HttpResponse response, byte[] content) -> {
int status = response.getStatus();
if (status != 200) return;
CacheEntry ce = new CacheEntry(response.getStatus(), response.getContentType(), content);
@@ -303,7 +303,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
} else { //单一url
this.modeOneCache = true;
this.cache = null;
this.cacheHandler = cacheseconds > 0 ? (HttpResponse response, byte[] content) -> {
this.cacheHandler = cacheSeconds > 0 ? (HttpResponse response, byte[] content) -> {
int status = response.getStatus();
if (status != 200) return;
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();
}
protected static int cacheseconds(Method method) {
protected static int cacheSeconds(Method method) {
HttpMapping mapping = method.getAnnotation(HttpMapping.class);
return mapping == null ? 0 : mapping.cacheseconds();
return mapping == null ? 0 : mapping.cacheSeconds();
}
//Rest.class会用到此方法
@@ -349,7 +349,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
final boolean modeOneCache;
final int cacheseconds;
final int cacheSeconds;
final boolean rpconly;

View File

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

View File

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

View File

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

View File

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