diff --git a/pom.xml b/pom.xml
index 48075d58772aa83fa0347bf015aece22ec14bf3b..e0d3b26d66d02c27c759f0d2720253003fecd782 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.noear
solon-parent
- 2.4.5
+ 3.0.3
4.0.0
@@ -40,16 +40,21 @@
org.noear
- solon.boot.undertow
+ solon-view-freemarker
org.noear
- solon.logging.logback
+ solon-boot-undertow
+
+
+
+ org.noear
+ solon-logging-logback
org.noear
- solon.scheduling.simple
+ solon-scheduling-simple
diff --git a/src/main/java/com/cym/NginxWebUI.java b/src/main/java/com/cym/NginxWebUI.java
index bb18694dc5dd54adcf4526ae985f10548d62b9cb..0925225847341a43720c0a9020b0c7f47348b97f 100644
--- a/src/main/java/com/cym/NginxWebUI.java
+++ b/src/main/java/com/cym/NginxWebUI.java
@@ -46,22 +46,7 @@ public class NginxWebUI {
logger.error(e.getMessage(), e);
}
- Solon.start(NginxWebUI.class, args, app -> {
- app.onError(e -> logger.error(e.getMessage(), e));
-
- app.before(c -> {
- String path = c.path();
- while (path.contains("//")) {
- path = path.replace("//", "/");
- }
- c.pathNew(path);
- });
-
- app.onEvent(freemarker.template.Configuration.class, cfg -> {
- cfg.setSetting("classic_compatible", "true");
- cfg.setSetting("number_format", "0.##");
- });
- });
+ Solon.start(NginxWebUI.class, args);
}
public static void killSelf(String[] args) {
diff --git a/src/main/java/com/cym/config/AppFilter.java b/src/main/java/com/cym/config/AppFilter.java
index 8f65f1936bff64c569aab7728defcf2df5729641..3f600101b60ac08331a818b11d422bf0421831b3 100644
--- a/src/main/java/com/cym/config/AppFilter.java
+++ b/src/main/java/com/cym/config/AppFilter.java
@@ -1,17 +1,11 @@
package com.cym.config;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -19,10 +13,13 @@ import java.util.Set;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
+import org.noear.solon.core.exception.StatusException;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;
import org.noear.solon.core.handle.UploadedFile;
+import org.noear.solon.core.util.KeyValues;
+import org.noear.solon.core.util.MultiMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,12 +35,10 @@ import com.cym.utils.MessageUtils;
import com.cym.utils.PropertiesUtils;
import cn.hutool.core.codec.Base64;
-import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
-import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
@Component
@@ -68,7 +63,22 @@ public class AppFilter implements Filter {
@Override
public void doFilter(Context ctx, FilterChain chain) throws Throwable {
+ //todo: 原异常处理改为正常的上抛了
+ try {
+ doFilterDo(ctx, chain);
+ } catch (StatusException e) {
+ //4xx 相关状态异常
+ ctx.status(e.getCode());
+
+ if (404 != e.getCode()) {
+ logger.error(e.getMessage(), e);
+ }
+ } catch (Throwable e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ private void doFilterDo(Context ctx, FilterChain chain) throws Throwable {
String path = ctx.path().toLowerCase();
// 全局过滤器
@@ -174,7 +184,8 @@ public class AppFilter implements Filter {
} else {
// 普通请求
Admin admin = new BaseController().getAdmin();
- String body = buldBody(ctx.paramsMap(), remote, admin);
+ //todo: ctx.paramsMap() 已取消,复用 ctx.paramMap()
+ String body = buldBody(ctx.paramMap(), remote, admin);
httpResponse = HttpRequest.post(url).body(body).execute();
}
@@ -277,18 +288,16 @@ public class AppFilter implements Filter {
}
- private String buldBody(Map> parameterMap, Remote remote, Admin admin) throws UnsupportedEncodingException {
+ private String buldBody(MultiMap parameterMap, Remote remote, Admin admin) throws UnsupportedEncodingException {
List body = new ArrayList<>();
body.add("creditKey=" + remote.getCreditKey());
if (admin != null) {
body.add("adminName=" + admin.getName());
}
- for (Iterator itr = parameterMap.entrySet().iterator(); itr.hasNext();) {
- Map.Entry me = (Map.Entry) itr.next();
-
- for (String value : (List) me.getValue()) {
- body.add(me.getKey() + "=" + URLEncoder.encode(value, "UTF-8"));
+ for (KeyValues kv : parameterMap) {
+ for (String value : kv.getValues()) {
+ body.add(kv.getKey() + "=" + URLEncoder.encode(value, "UTF-8"));
}
}
diff --git a/src/main/java/com/cym/config/ViewConfig.java b/src/main/java/com/cym/config/ViewConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..e30a29b2d55b00d6b1b80086f021488b399b31b2
--- /dev/null
+++ b/src/main/java/com/cym/config/ViewConfig.java
@@ -0,0 +1,20 @@
+package com.cym.config;
+
+import org.noear.solon.annotation.Bean;
+import org.noear.solon.annotation.Configuration;
+import org.noear.solon.view.freemarker.FreemarkerRender;
+
+@Configuration
+public class ViewConfig {
+ @Bean
+ public void init(FreemarkerRender render) throws Exception {
+ //todo: 从 “app.onEvent(freemarker.template.Configuration.class, cfg->{})“ 迁移过来
+ render.getProvider().setSetting("classic_compatible", "true");
+ render.getProvider().setSetting("number_format", "0.##");
+
+ if (render.getProviderOfDebug() != null) {
+ render.getProviderOfDebug().setSetting("classic_compatible", "true");
+ render.getProviderOfDebug().setSetting("number_format", "0.##");
+ }
+ }
+}
diff --git a/src/main/java/com/cym/controller/adminPage/LogController.java b/src/main/java/com/cym/controller/adminPage/LogController.java
index 70bed72eed790e2876b77d59b861dd88ec85bce5..a64d2190e8756e4547442c951b554412b13d1acd 100644
--- a/src/main/java/com/cym/controller/adminPage/LogController.java
+++ b/src/main/java/com/cym/controller/adminPage/LogController.java
@@ -2,13 +2,10 @@ package com.cym.controller.adminPage;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
-import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.ModelAndView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -84,17 +81,10 @@ public class LogController extends BaseController {
}
@Mapping("down")
- public void down(ModelAndView modelAndView, String id) throws IOException {
+ public File down(String id) throws IOException {
Log log = sqlHelper.findById(id, Log.class);
- File file = new File(log.getPath());
-
- Context.current().contentType("application/octet-stream");
- String headerKey = "Content-Disposition";
- String headerValue = "attachment; filename=" + URLUtil.encode(file.getName());
- Context.current().header(headerKey, headerValue);
-
- InputStream inputStream = Files.newInputStream(file.toPath());
- Context.current().output(inputStream);
+ //todo: 简化下载处理
+ return new File(log.getPath());
}
@Mapping("tailCmd")
diff --git a/src/test/java/com/cym/TestUtils.java b/src/test/java/com/cym/TestUtils.java
index 5e06fff0cd3ec998872e5bbcb844a82abdb2f4e5..52d7a86633b7e5b402fcc164ccfe14107fcb2ab5 100644
--- a/src/test/java/com/cym/TestUtils.java
+++ b/src/test/java/com/cym/TestUtils.java
@@ -1,18 +1,10 @@
package com.cym;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import jdk.nashorn.internal.ir.annotations.Ignore;
+import org.junit.jupiter.api.Test;
import org.noear.solon.test.HttpTester;
-import org.noear.solon.test.SolonJUnit4ClassRunner;
import org.noear.solon.test.SolonTest;
-@RunWith(SolonJUnit4ClassRunner.class)
@SolonTest(NginxWebUI.class)
public class TestUtils extends HttpTester {
@Test