use of org.axe.annotation.mvc.Request in project Axe by DongyuCai.
the class ControllerHelper method init.
@Override
public void init() {
synchronized (this) {
ACTION_LIST = new LinkedList<>();
ACTION_MAP = new HashMap<>();
//获取所有的 Controller 类
Set<Class<?>> controllerClassSet = ClassHelper.getControllerClassSet();
if (CollectionUtil.isNotEmpty(controllerClassSet)) {
for (Class<?> controllerClass : controllerClassSet) {
String basePath = controllerClass.getAnnotation(Controller.class).basePath();
Method[] methods = controllerClass.getDeclaredMethods();
if (ArrayUtil.isNotEmpty(methods)) {
for (Method method : methods) {
//判断方法是否带有 Action 注解
if (method.isAnnotationPresent(Request.class)) {
Request action = method.getAnnotation(Request.class);
String mappingPath = basePath + "/" + action.value();
String requestMethod = action.method().REQUEST_METHOD;
//检查mappingPath是否合规
if (!RequestUtil.checkMappingPath(mappingPath)) {
throw new RuntimeException("invalid @Request.value [" + mappingPath + "] of action: " + method);
}
//检查actionMethod是否合规
try {
RequestUtil.checkActionMethod(method);
} catch (Exception e) {
throw new RuntimeException("invalid Controler method : " + e.getMessage());
}
//格式化
mappingPath = RequestUtil.formatUrl(mappingPath);
String[] nodeNames = mappingPath.split("/");
String nodeName = "";
String[] subNodeNameLineAry = {};
if (nodeNames.length > 0) {
nodeName = nodeNames[0];
subNodeNameLineAry = new String[nodeNames.length - 1];
for (int i = 0; i < subNodeNameLineAry.length; i++) {
subNodeNameLineAry[i] = nodeNames[i + 1];
}
}
generateActionMap(nodeName, ACTION_MAP, controllerClass, method, subNodeNameLineAry, requestMethod, mappingPath);
}
}
}
}
}
}
}
use of org.axe.annotation.mvc.Request in project Axe by DongyuCai.
the class Handler method init.
private void init() {
if (this.actionMethod.isAnnotationPresent(Request.class)) {
Request request = this.actionMethod.getAnnotation(Request.class);
this.contentType = request.contentType().CONTENT_TYPE;
this.characterEncoding = request.characterEncoding().CHARACTER_ENCODING;
Annotation[][] parameterAnnotations = this.actionMethod.getParameterAnnotations();
Class<?>[] parameterTypes = this.actionMethod.getParameterTypes();
if (parameterTypes != null) {
if (parameterTypes.length == parameterAnnotations.length) {
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> paramType = parameterTypes[i];
Annotation[] annotations = parameterAnnotations[i];
if (actionParamList == null) {
actionParamList = new ArrayList<>();
}
ActionParam actionParam = new ActionParam();
actionParam.setAnnotations(annotations);
actionParam.setParamType(paramType);
actionParamList.add(actionParam);
}
} else {
throw new RuntimeException("create Hanlder failed ,wrong parameterTypes.length[" + parameterTypes.length + "] and " + "parameterAnnotations.length[" + parameterAnnotations.length + "]: " + this.actionMethod.toGenericString());
}
}
}
}
use of org.axe.annotation.mvc.Request in project Axe by DongyuCai.
the class HomeController method home.
@Request(value = "", method = RequestMethod.GET)
public void home(@RequestParam("token") String token, HttpServletRequest request, HttpServletResponse response) {
String contextPath = request.getContextPath();
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE html>");
html.append("<html>");
html.append("<head>");
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
html.append("<title>axe homepage</title>");
html.append("<script type=\"text/javascript\">");
html.append("var refreshInt = setInterval(\"refresh()\",1000*60);");
html.append("function refresh(){");
html.append("window.location = \"" + contextPath + "/axe?token=" + token + "\";");
html.append("}");
html.append("</script>");
html.append("</head>");
html.append("<body>");
html.append("<table width=\"100%\">");
html.append("<tr><td align=\"right\">");
if (ConfigHelper.getAxeSignIn()) {
html.append("<a style=\"font-size: 15px;color: #AE0000\" href=\"" + contextPath + "/axe/sign-out?token=" + token + "\"><b>退出</b></a>");
}
html.append(" <a style=\"font-size: 15px;color: #AE0000\" href=\"" + contextPath + "/axe?token=" + token + "\"><b>首页</b></a>");
html.append("</td></tr>");
html.append("<tr><td align=\"center\"><font size=\"28\">欢迎使用 Axe!</font></td></tr>");
html.append("");
html.append("<!--系统运行 概览-->");
html.append("<tr><td><table cellspacing=\"0px\"><tr><td style=\"background-color: #AE0000\">");
html.append(" <font color=\"white\"><b>系统运行-概览</b></font> ");
html.append("</td></tr></table></td></tr>");
html.append("");
html.append("<tr><td height=\"2px\" style=\"background-color:#AE0000\"></td></tr>");
html.append("<tr><td>");
html.append("<table width=\"100%\">");
html.append("<tr style=\"background-color: #F0F0F0;\">");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\"><b>启动时间</b></td>");
html.append("<td align=\"left\"><b>运行时长</b></td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
Date startupTime = FrameworkStatusHelper.getStartupTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
html.append("<td align=\"left\">" + sdf.format(startupTime) + "</td>");
long runTimeSec = (System.currentTimeMillis() - startupTime.getTime()) / 1000;
String runTime = "";
if (runTimeSec < 60) {
runTime = runTimeSec + "秒";
} else {
long runTimeMin = runTimeSec / 60;
if (runTimeMin < 60) {
runTimeSec = runTimeSec - (runTimeMin * 60);
runTime = runTimeMin + "分" + runTimeSec + "秒";
} else {
long runTimeHour = runTimeMin / 60;
if (runTimeHour < 24) {
runTimeMin = runTimeMin - runTimeHour * 60;
runTimeSec = runTimeSec - ((runTimeHour * 60) + runTimeMin) * 60;
runTime = runTimeHour + "时" + runTimeMin + "分" + runTimeSec + "秒";
} else {
long runTimeDay = runTimeHour / 24;
runTimeHour = runTimeHour - (runTimeDay * 24);
runTimeMin = runTimeMin - ((runTimeDay * 24) + runTimeHour) * 60;
runTimeSec = runTimeSec - ((((runTimeDay * 24) + runTimeHour) * 60) + runTimeMin) * 60;
runTime = runTimeDay + "天" + runTimeHour + "时" + runTimeMin + "分" + runTimeSec + "秒";
}
}
}
html.append("<td align=\"left\">" + runTime + "</td>");
html.append("</tr>");
html.append("</table>");
html.append("</td></tr><tr><td> </td></tr>");
html.append("");
html.append("<!--系统参数-->");
html.append("<tr><td><table cellspacing=\"0px\"><tr><td style=\"background-color: #AE0000\">");
html.append(" <font color=\"white\"><b>系统参数 axe.properties</b></font> ");
html.append("</td><td> </td><td style=\"background-color: #007500;cursor: pointer;\" onclick=\"window.location='" + contextPath + "/axe/axe.properties?token=" + token + "'\">");
html.append(" <font color=\"white\"><b>编辑</b></font> ");
html.append("</td><td> </td><td style=\"background-color: #007500;cursor: pointer;\" onclick=\"window.location='" + contextPath + "/axe/refresh-config?token=" + token + "'\">");
html.append(" <font color=\"white\"><b>重载 axe.properties 配置</b></font> ");
html.append("</td></tr></table></td></tr>");
html.append("");
html.append("<tr><td height=\"2px\" style=\"background-color:#AE0000\"></td></tr>");
html.append("<tr><td>");
html.append("<table width=\"100%\">");
html.append("<tr style=\"background-color: #F0F0F0;\">");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\"><b>参数-键</b></td>");
html.append("<td align=\"left\"><b>参数-值</b></td>");
html.append("<td align=\"left\"><b>参数描述</b></td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">axe.home</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAxeHome() + "</td>");
html.append("<td align=\"left\">是否开启/axe的访问</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">axe.email</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAxeEmail() + "</td>");
html.append("<td align=\"left\">系统异常、密码找回邮件通知地址</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">axe.signin</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAxeSignIn() + "</td>");
html.append("<td align=\"left\">是否开启/axe的登录访问</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">axe.classhelper.keep</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAxeClassHelperKeep() + "</td>");
html.append("<td align=\"left\">启动后是否释放ClassHelper的内存(释放后ClassHelper不可再用)</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">jdbc.driver</td>");
html.append("<td align=\"left\">" + ConfigHelper.getJdbcDriver() + "</td>");
html.append("<td align=\"left\">jdbc-driver</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">jdbc.url</td>");
html.append("<td align=\"left\">" + ConfigHelper.getJdbcUrl() + "</td>");
html.append("<td align=\"left\">jdbc-url</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">jdbc.username</td>");
html.append("<td align=\"left\">" + ConfigHelper.getJdbcUsername() + "</td>");
html.append("<td align=\"left\">jdbc-username</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">jdbc.password</td>");
html.append("<td align=\"left\">" + ConfigHelper.getJdbcPassword() + "</td>");
html.append("<td align=\"left\">jdbc-password</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">jdbc.datasource</td>");
html.append("<td align=\"left\">" + ConfigHelper.getJdbcDatasource() + "</td>");
html.append("<td align=\"left\">指定DataSource数据源实现类</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">app.base_package</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAppBasePackage() + "</td>");
html.append("<td align=\"left\">指定框架扫描的包路径</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">app.jsp_path</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAppJspPath() + "</td>");
html.append("<td align=\"left\">指定jsp存放路径</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">app.asset_path</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAppAssetPath() + "</td>");
html.append("<td align=\"left\">指定静态文件(html、js、css、图片等)存放路径</td>");
html.append("</tr>");
html.append("<tr>");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\">app.upload_limit</td>");
html.append("<td align=\"left\">" + ConfigHelper.getAppUploadLimit() + "</td>");
html.append("<td align=\"left\">文件上传限制单次文件大小,单位M,默认0不限制</td>");
html.append("</tr>");
html.append("</table>");
html.append("</td></tr><tr><td> </td></tr>");
html.append("");
html.append("<!--MVC 概览-->");
html.append("<tr><td><table cellspacing=\"0px\"><tr><td style=\"background-color: #AE0000\">");
html.append(" <font color=\"white\"><b>MVC-概览</b></font> ");
html.append("</td></tr></table></td></tr>");
html.append("");
html.append("<tr><td height=\"2px\" style=\"background-color:#AE0000\"></td></tr>");
html.append("<tr><td>");
html.append("<table width=\"100%\">");
html.append("<tr>");
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/filter?token=" + token + "\">Filter</a> x" + FilterHelper.getSortedFilterList().size() + "</td>");
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/interceptor?token=" + token + "\">Interceptor</a> x" + InterceptorHelper.getInterceptorMap().size() + "</td>");
String controllerSize = "?";
String serviceSize = "?";
String tnsPointCount = "?";
String daoSize = "?";
if (ConfigHelper.getAxeClassHelperKeep()) {
controllerSize = ClassHelper.getControllerClassSet().size() + "";
Set<Class<?>> serviceClassSet = ClassHelper.getServiceClassSet();
serviceSize = serviceClassSet.size() + "";
int count = 0;
for (Class<?> serviceClass : serviceClassSet) {
List<Method> methods = ReflectionUtil.getMethodByAnnotation(serviceClass, Tns.class);
if (CollectionUtil.isNotEmpty(methods)) {
count = count + methods.size();
}
}
tnsPointCount = count + "";
daoSize = ClassHelper.getClassSetByAnnotation(Dao.class).size() + "";
}
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/controller?token=" + token + "\">Controller</a> x" + controllerSize + "</td>");
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/action?token=" + token + "\">Action</a> x" + ControllerHelper.getActionList().size() + "</td>");
html.append("<td align=\"center\">Service x" + serviceSize + "</td>");
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/tns?token=" + token + "\">Tns point </a> x" + tnsPointCount + "</td>");
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/dao?token=" + token + "\">Dao</a> x" + daoSize + "</td>");
html.append("<td align=\"center\">Table</a> x" + TableHelper.getEntityClassMap().size() + "</td>");
html.append("<td align=\"center\"><a href=\"" + contextPath + "/axe/dataSource?token=" + token + "\">DataSource</a> x" + DataSourceHelper.getDataSourceAll().size() + "</td>");
html.append("</tr>");
html.append("</table>");
html.append("</td></tr><tr><td> </td></tr>");
html.append("");
html.append("</table>");
html.append("</body>");
html.append("</html>");
printHtml(response, html.toString());
}
use of org.axe.annotation.mvc.Request in project Axe by DongyuCai.
the class HomeController method refreshConfig.
@Request(value = "/refresh-config", method = RequestMethod.GET)
public void refreshConfig(@RequestParam("token") String token, HttpServletRequest request, HttpServletResponse response) {
String contextPath = request.getContextPath();
ServletContext servletContext = request.getServletContext();
try {
HelperLoader.refresHelpers(servletContext);
} catch (Exception e) {
throw new RestException(e.getMessage());
}
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE html>");
html.append("<html>");
html.append("<head>");
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
html.append("<title>axe save properties</title>");
html.append("<script type=\"text/javascript\">");
html.append("var number = 10;");
html.append("");
html.append("var int=self.setInterval(\"toHome()\",1000);");
html.append("");
html.append("function toHome(){");
html.append("number = number-1;");
html.append("document.getElementById(\"number\").innerHTML = number;");
html.append("if(number <= 0){");
html.append("window.clearInterval(int);");
html.append("window.location = \"" + contextPath + "/axe?token=" + token + "\";");
html.append("}");
html.append("}");
html.append("");
html.append("</script>");
html.append("</head>");
html.append("<body>");
html.append("<table width=\"100%\">");
html.append("<tr><td align=\"right\">");
if (ConfigHelper.getAxeSignIn()) {
html.append("<a style=\"font-size: 15px;color: #AE0000\" href=\"" + contextPath + "/axe/sign-out?token=" + token + "\"><b>退出</b></a>");
}
html.append(" <a style=\"font-size: 15px;color: #AE0000\" href=\"" + contextPath + "/axe?token=" + token + "\"><b>首页</b></a>");
html.append("</td></tr>");
html.append("<tr><td align=\"center\"><span id=\"number\">10</span>秒后自动跳转<a href=\"" + contextPath + "/axe?token=" + token + "\">/axe首页</a></td></tr>");
html.append("<tr><td align=\"center\"><font size=\"28\"><b>刷新配置成功!</b></font></td></tr>");
html.append("</table>");
html.append("</body>");
html.append("</html>");
printHtml(response, html.toString());
}
use of org.axe.annotation.mvc.Request in project Axe by DongyuCai.
the class HomeController method controller.
@Request(value = "/controller", method = RequestMethod.GET)
public void controller(@RequestParam("token") String token, HttpServletRequest request, HttpServletResponse response) {
String contextPath = request.getContextPath();
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE html>");
html.append("<html>");
html.append("<head>");
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
html.append("<title>axe controller</title>");
html.append("</head>");
html.append("<body>");
html.append("<table width=\"100%\">");
html.append("<tr><td align=\"right\">");
if (ConfigHelper.getAxeSignIn()) {
html.append("<a style=\"font-size: 15px;color: #AE0000\" href=\"" + contextPath + "/axe/sign-out?token=" + token + "\"><b>退出</b></a>");
}
html.append(" <a style=\"font-size: 15px;color: #AE0000\" href=\"" + contextPath + "/axe?token=" + token + "\"><b>首页</b></a>");
html.append("</td></tr>");
Set<Class<?>> controllerCLassSet = ClassHelper.getControllerClassSet();
html.append("<tr><td align=\"center\"><font size=\"28\">Controller set x" + controllerCLassSet.size() + "</font></td></tr>");
html.append("");
html.append("<tr><td><table cellspacing=\"0px\"><tr><td style=\"background-color: #AE0000\">");
html.append(" <font color=\"white\"><b>Controller</b></font> ");
html.append("</td></tr></table></td></tr>");
html.append("");
html.append("<tr><td height=\"2px\" style=\"background-color: #AE0000\"></td></tr>");
html.append("<tr><td>");
html.append("<table width=\"100%\">");
html.append("<tr style=\"background-color: #F0F0F0;\">");
html.append("<td align=\"left\"> </td>");
html.append("<td align=\"left\"><b>Title</b></td>");
html.append("<td align=\"left\"><b>BasePath</b></td>");
html.append("<td align=\"left\"><b>Class</b></td>");
html.append("<td align=\"left\"><b>Action</b></td>");
html.append("</tr>");
Map<String, List<Class<?>>> controllerClassMap = new HashMap<>();
for (Class<?> controllerClass : controllerCLassSet) {
Controller controller = controllerClass.getAnnotation(Controller.class);
String basePath = controller.basePath();
List<Class<?>> controllerClassList = new ArrayList<>();
if (controllerClassMap.containsKey(basePath)) {
controllerClassList = controllerClassMap.get(basePath);
} else {
controllerClassMap.put(basePath, controllerClassList);
}
controllerClassList.add(controllerClass);
}
List<String> basePathList = StringUtil.sortStringSet(controllerClassMap.keySet());
int id = 1;
for (String basePath : basePathList) {
List<Class<?>> controllerClassList = controllerClassMap.get(basePath);
for (Class<?> controllerClass : controllerClassList) {
int actionCount = 0;
Method[] methodAry = controllerClass.getDeclaredMethods();
for (Method method : methodAry) {
if (method.isAnnotationPresent(Request.class)) {
actionCount++;
}
}
Controller controller = controllerClass.getAnnotation(Controller.class);
html.append("<tr>");
html.append("<td align=\"left\">" + (id++) + "</td>");
html.append("<td align=\"left\">" + controller.title() + "</td>");
html.append("<td align=\"left\">" + basePath + "</td>");
html.append("<td align=\"left\">" + controllerClass.getName() + "</td>");
String basePathHashCode = null;
int code = basePath.hashCode();
if (code < 0) {
basePathHashCode = "_" + Math.abs(code);
} else {
basePathHashCode = String.valueOf(code);
}
html.append("<td align=\"left\">x<a href=\"" + contextPath + "/axe/controller-" + basePathHashCode + "/action?token=" + token + "\">" + actionCount + "</a></td>");
html.append("</tr>");
}
}
html.append("</table>");
html.append("</td></tr>");
html.append("</table>");
html.append("</body>");
html.append("</html>");
printHtml(response, html.toString());
}
Aggregations