From 7f1488b570643413f2f3b73e41614fb6d6fed436 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Tue, 12 Jul 2022 16:16:17 +0800 Subject: [PATCH] =?UTF-8?q?web=E6=9C=8D=E5=8A=A1=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../neutrino/core/context/ApplicationConfig.java | 15 ++++++++++++++- .../core/type/extension/SetMatcherGroup.java | 12 ++++++++++++ .../neutrino/core/web/WebApplicationServer.java | 9 +++++++-- .../src/main/resources/application.yml | 7 ++++++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationConfig.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationConfig.java index b817d3f5..a55e5ff8 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationConfig.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/context/ApplicationConfig.java @@ -26,6 +26,8 @@ import fun.asgc.neutrino.core.annotation.Configuration; import fun.asgc.neutrino.core.annotation.Value; import lombok.Data; +import java.util.Set; + /** * * @author: aoshiguchen @@ -48,9 +50,20 @@ public class ApplicationConfig { @Data public static class Http { private Boolean enable; - @Value("${port:9999}") + @Value("${port:8080}") private Integer port; @Value("context-path") private String contextPath; + @Value("${max-content-length-desc:64KB}") + private String maxContentLengthDesc; + @Value("max-content-length") + private Long maxContentLength; + @Value("static-resource") + private StaticResource staticResource; + } + + @Data + public static class StaticResource{ + private Set locations; } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/type/extension/SetMatcherGroup.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/type/extension/SetMatcherGroup.java index 0b379bde..e4c2a715 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/type/extension/SetMatcherGroup.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/type/extension/SetMatcherGroup.java @@ -25,6 +25,7 @@ import fun.asgc.neutrino.core.type.AbstractMatcherGroup; import fun.asgc.neutrino.core.type.TypeMatchInfo; import fun.asgc.neutrino.core.type.TypeMatcher; +import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -53,6 +54,17 @@ public class SetMatcherGroup extends AbstractMatcherGroup { return matchInfo; } }); + add(new TypeMatcher() { + @Override + public TypeMatchInfo match(Class clazz, Class targetClass) { + TypeMatchInfo matchInfo = new TypeMatchInfo(clazz, targetClass, this); + if (Set.class == targetClass && Collection.class.isAssignableFrom(clazz)) { + matchInfo.setTypeDistance(getDistanceMin() + 1); + matchInfo.setTypeConverter(((value, targetType) -> ((Collection)value).stream().collect(Collectors.toSet()))); + } + return matchInfo; + } + }); } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/WebApplicationServer.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/WebApplicationServer.java index 12869ec7..0e0327a0 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/WebApplicationServer.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/WebApplicationServer.java @@ -25,6 +25,8 @@ import fun.asgc.neutrino.core.annotation.Autowired; import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.context.ApplicationConfig; import fun.asgc.neutrino.core.context.ApplicationRunner; +import fun.asgc.neutrino.core.util.NumberUtil; +import fun.asgc.neutrino.core.util.StringUtil; import lombok.extern.slf4j.Slf4j; /** @@ -37,9 +39,12 @@ import lombok.extern.slf4j.Slf4j; public class WebApplicationServer implements ApplicationRunner { @Autowired private ApplicationConfig rootApplicationConfig; - @Override public void run(String[] args) { - log.debug("web服务启动..."); + ApplicationConfig.Http http = rootApplicationConfig.getHttp(); + if (StringUtil.notEmpty(http.getMaxContentLengthDesc()) && null == http.getMaxContentLength()) { + http.setMaxContentLength(NumberUtil.descriptionToSize(http.getMaxContentLengthDesc(), 64 * 1024)); + } + } } diff --git a/neutrino-proxy-server/src/main/resources/application.yml b/neutrino-proxy-server/src/main/resources/application.yml index 956f6d17..b1ee876c 100644 --- a/neutrino-proxy-server/src/main/resources/application.yml +++ b/neutrino-proxy-server/src/main/resources/application.yml @@ -3,8 +3,13 @@ neutrino: name: neutrino-proxy-server http: enable: true - port: + port: 8080 context-path: / + max-content-length-desc: 128K + static-resource: + locations: + - "classpath:/static/" + - "classpath:/template/" proxy: protocol: