解决机器人和频道高压力下错误问题
This commit is contained in:
@@ -43,27 +43,17 @@ public class ServerSetting {
|
|||||||
/** 根目录 */
|
/** 根目录 */
|
||||||
private static File root;
|
private static File root;
|
||||||
/** Filter映射表 */
|
/** Filter映射表 */
|
||||||
private static Map<String, Filter> filterMap;
|
private static Map<String, Filter> filterMap = new ConcurrentHashMap<>();
|
||||||
/** Action映射表 */
|
/** Action映射表 */
|
||||||
private static Map<String, Action> getActionMap;
|
private static Map<String, Class<? extends Action>> getActionMap = new ConcurrentHashMap<>();
|
||||||
private static Map<String, Action> postActionMap;
|
private static Map<String, Class<? extends Action>> postActionMap = new ConcurrentHashMap<>();
|
||||||
private static Map<String, Action> putActionMap;
|
private static Map<String, Class<? extends Action>> putActionMap = new ConcurrentHashMap<>();
|
||||||
private static Map<String, Action> deleteActionMap;
|
private static Map<String, Class<? extends Action>> deleteActionMap = new ConcurrentHashMap<>();
|
||||||
private static Map<String, Action> errorActionMap;
|
private static Map<String, Class<? extends Action>> errorActionMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static{
|
static{
|
||||||
filterMap = new ConcurrentHashMap<String, Filter>();
|
errorActionMap.put(StrUtil.SLASH, DefaultIndexAction.class);
|
||||||
|
errorActionMap.put(MAPPING_ERROR, UnknownErrorAction.class);
|
||||||
getActionMap = new ConcurrentHashMap<String, Action>();
|
|
||||||
postActionMap = new ConcurrentHashMap<String, Action>();
|
|
||||||
|
|
||||||
putActionMap = new ConcurrentHashMap<String, Action>();
|
|
||||||
|
|
||||||
deleteActionMap = new ConcurrentHashMap<String, Action>();
|
|
||||||
|
|
||||||
errorActionMap = new ConcurrentHashMap<String, Action>();
|
|
||||||
errorActionMap.put(StrUtil.SLASH, new DefaultIndexAction());
|
|
||||||
errorActionMap.put(MAPPING_ERROR, new UnknownErrorAction());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,7 +197,7 @@ public class ServerSetting {
|
|||||||
/**
|
/**
|
||||||
* @return 获取ActionMap
|
* @return 获取ActionMap
|
||||||
*/
|
*/
|
||||||
public static Map<String, Action> getActionMap(String method) {
|
public static Map<String, Class<? extends Action>> getActionMap(String method) {
|
||||||
if (method.equals("GET")) {
|
if (method.equals("GET")) {
|
||||||
return getActionMap;
|
return getActionMap;
|
||||||
} else if(method.equals("POST")) {
|
} else if(method.equals("POST")) {
|
||||||
@@ -221,7 +211,17 @@ public class ServerSetting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Action getErrorAction(String path) {
|
public static Action getErrorAction(String path) {
|
||||||
return errorActionMap.get(path);
|
Class<? extends Action> cls = errorActionMap.get(path);
|
||||||
|
if(cls != null) {
|
||||||
|
try {
|
||||||
|
return cls.newInstance();
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,33 +233,17 @@ public class ServerSetting {
|
|||||||
if(StrUtil.isBlank(path)){
|
if(StrUtil.isBlank(path)){
|
||||||
path = StrUtil.SLASH;
|
path = StrUtil.SLASH;
|
||||||
}
|
}
|
||||||
return getActionMap(method).get(path.trim());
|
Class<? extends Action> cls = getActionMap(method).get(path.trim());
|
||||||
}
|
if(cls != null) {
|
||||||
|
try {
|
||||||
/**
|
return cls.newInstance();
|
||||||
* 设置Action类,已有的Action类将被覆盖
|
} catch (InstantiationException e) {
|
||||||
* @param path 拦截路径(必须以"/"开头)
|
e.printStackTrace();
|
||||||
* @param action Action类
|
} catch (IllegalAccessException e) {
|
||||||
*/
|
e.printStackTrace();
|
||||||
public static void setAction(String path, Action action) {
|
}
|
||||||
if(StrUtil.isBlank(path)){
|
|
||||||
path = StrUtil.SLASH;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(null == action) {
|
|
||||||
Logger.warn("Added blank action, pass it.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//所有路径必须以 "/" 开头,如果没有则补全之
|
|
||||||
if(false == path.startsWith(StrUtil.SLASH)) {
|
|
||||||
path = StrUtil.SLASH + path;
|
|
||||||
}
|
|
||||||
String method = "GET";
|
|
||||||
HttpMethod methodAnnotation = action.getClass().getAnnotation(HttpMethod.class);
|
|
||||||
if (methodAnnotation != null) {
|
|
||||||
method = methodAnnotation.value();
|
|
||||||
}
|
}
|
||||||
ServerSetting.getActionMap(method).put(path, action);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,24 +253,24 @@ public class ServerSetting {
|
|||||||
* @param actionClass Action类
|
* @param actionClass Action类
|
||||||
*/
|
*/
|
||||||
public static void setAction(String path, Class<? extends Action> actionClass) {
|
public static void setAction(String path, Class<? extends Action> actionClass) {
|
||||||
setAction(path, (Action)Singleton.get(actionClass));
|
if(StrUtil.isBlank(path)){
|
||||||
}
|
path = StrUtil.SLASH;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
if(null == actionClass) {
|
||||||
* 增加Action类,已有的Action类将被覆盖<br>
|
Logger.warn("Added blank action, pass it.");
|
||||||
* 自动读取Route的注解来获得Path路径
|
return;
|
||||||
* @param action 带注解的Action对象
|
}
|
||||||
*/
|
//所有路径必须以 "/" 开头,如果没有则补全之
|
||||||
public static void setAction(Action action) {
|
if(false == path.startsWith(StrUtil.SLASH)) {
|
||||||
final Route route = action.getClass().getAnnotation(Route.class);
|
path = StrUtil.SLASH + path;
|
||||||
if(route != null){
|
}
|
||||||
final String path = route.value();
|
String method = "GET";
|
||||||
if(StrUtil.isNotBlank(path)){
|
HttpMethod methodAnnotation = actionClass.getAnnotation(HttpMethod.class);
|
||||||
setAction(path, action);
|
if (methodAnnotation != null) {
|
||||||
return;
|
method = methodAnnotation.value();
|
||||||
}
|
}
|
||||||
}
|
ServerSetting.getActionMap(method).put(path, actionClass);
|
||||||
throw new ServerSettingException("Can not find Route annotation,please add annotation to Action class!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -295,7 +279,15 @@ public class ServerSetting {
|
|||||||
* @param actionClass 带注解的Action类
|
* @param actionClass 带注解的Action类
|
||||||
*/
|
*/
|
||||||
public static void setAction(Class<? extends Action> actionClass) {
|
public static void setAction(Class<? extends Action> actionClass) {
|
||||||
setAction((Action)Singleton.get(actionClass));
|
final Route route = actionClass.getAnnotation(Route.class);
|
||||||
|
if(route != null){
|
||||||
|
final String path = route.value();
|
||||||
|
if(StrUtil.isNotBlank(path)){
|
||||||
|
setAction(path, actionClass);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ServerSettingException("Can not find Route annotation,please add annotation to Action class!");
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------- Action start
|
//----------------------------------------------------------------------------------------------- Action start
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user