Browse Source

后台代码开发20211128

MSY 3 years ago
parent
commit
1b1eafd5ad

+ 2 - 0
src/main/java/com/jkcredit/invoice/SysInvoiceApplication.java

@@ -4,9 +4,11 @@ import com.jkcredit.invoice.credit.SimpleCORSFilter;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+@Import({TomcatConfig.class})
 @EnableAsync
 @EnableScheduling
 @SpringBootApplication

+ 52 - 0
src/main/java/com/jkcredit/invoice/TomcatConfig.java

@@ -0,0 +1,52 @@
+package com.jkcredit.invoice;
+
+import org.apache.catalina.connector.Connector;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description: 增加端口监听
+ * @Class: TomcatConfig
+ * @Author: mashengyi
+ * @Date: 2021/11/28 15:56
+ * @Version: 1.0
+ */
+@Configuration
+public class TomcatConfig {
+
+    @Value("${server.additionalPorts}")
+    private String additionalPorts;
+
+    @Bean
+    public TomcatServletWebServerFactory servletContainer() {
+        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
+        Connector[] additionalConnectors = this.additionalConnector();
+        if (additionalConnectors != null && additionalConnectors.length > 0) {
+            tomcat.addAdditionalTomcatConnectors(additionalConnectors);
+        }
+        return tomcat;
+    }
+
+    private Connector[] additionalConnector() {
+        if (StringUtils.isBlank(this.additionalPorts)) {
+            return null;
+        }
+        // 端口按,分割
+        String[] ports = this.additionalPorts.split(",");
+        List<Connector> result = new ArrayList<>();
+        for (String port : ports) {
+            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
+            connector.setScheme("http");
+            connector.setPort(Integer.parseInt(port));
+            result.add(connector);
+        }
+        return result.toArray(new Connector[] {});
+    }
+
+}

+ 17 - 1
src/main/java/com/jkcredit/invoice/credit/SimpleCORSFilter.java

@@ -343,10 +343,26 @@ public class SimpleCORSFilter implements Filter {
         try {
 
 
-            if(!request.getQueryString().equals("api=credit.sec.data")){
+            if(null != request && null != request.getQueryString() && !request.getQueryString().equals("api=credit.sec.data")){
                 return ResponseCode.UNKNOWN_ERROR;
             };
 
+            if(null != request && null != request.getQueryString() && !request.getRequestURI().equals("/gateway")){
+                return ResponseCode.UNKNOWN_ERROR;
+            }
+
+
+            if(null != request && null == request.getQueryString() && !request.getRequestURI().equals("/api/rest")){
+                return ResponseCode.UNKNOWN_ERROR;
+            }
+
+            if(null == request ){
+                return ResponseCode.UNKNOWN_ERROR;
+            }
+
+            if(null != request  && null == request.getQueryString() && null == request.getRequestURI()  ){
+                return ResponseCode.UNKNOWN_ERROR;
+            }
 
             String jsonObject1 = getOpenApiRequestData(request);
             api = getApi(jsonObject1);

+ 1 - 0
src/main/resources/application.yml

@@ -1,6 +1,7 @@
 
 server:
   port: 18080
+  additionalPorts: 9999,58080
   tomcat:
     accesslog:
       enabled: true