Przeglądaj źródła

执行器回调地址https兼容支持;

xuxueli 5 lat temu
rodzic
commit
aa951eeec0

+ 1 - 1
doc/XXL-JOB官方文档.md Wyświetl plik

1675
 - 2、移除commons-exec,采用原生方式实现;
1675
 - 2、移除commons-exec,采用原生方式实现;
1676
 - 3、执行器回调乱码问题修复;
1676
 - 3、执行器回调乱码问题修复;
1677
 - 4、调度中心dispatcher servlet加载顺序优化;
1677
 - 4、调度中心dispatcher servlet加载顺序优化;
1678
-- 5、[迭代中]任务操作API服务调整为restful方式,降低接入成本
1678
+- 5、执行器回调地址https兼容支持
1679
 
1679
 
1680
 
1680
 
1681
 
1681
 

+ 40 - 0
xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobRemotingUtil.java Wyświetl plik

5
 import org.slf4j.Logger;
5
 import org.slf4j.Logger;
6
 import org.slf4j.LoggerFactory;
6
 import org.slf4j.LoggerFactory;
7
 
7
 
8
+import javax.net.ssl.*;
8
 import java.io.BufferedReader;
9
 import java.io.BufferedReader;
9
 import java.io.DataOutputStream;
10
 import java.io.DataOutputStream;
10
 import java.io.InputStreamReader;
11
 import java.io.InputStreamReader;
11
 import java.net.HttpURLConnection;
12
 import java.net.HttpURLConnection;
12
 import java.net.URL;
13
 import java.net.URL;
14
+import java.security.cert.CertificateException;
15
+import java.security.cert.X509Certificate;
13
 import java.util.Map;
16
 import java.util.Map;
14
 
17
 
15
 /**
18
 /**
19
     private static Logger logger = LoggerFactory.getLogger(XxlJobRemotingUtil.class);
22
     private static Logger logger = LoggerFactory.getLogger(XxlJobRemotingUtil.class);
20
     public static String XXL_RPC_ACCESS_TOKEN = "XXL-RPC-ACCESS-TOKEN";
23
     public static String XXL_RPC_ACCESS_TOKEN = "XXL-RPC-ACCESS-TOKEN";
21
 
24
 
25
+
26
+    // trust-https start
27
+    private static void trustAllHosts(HttpsURLConnection connection) {
28
+        try {
29
+            SSLContext sc = SSLContext.getInstance("TLS");
30
+            sc.init(null, trustAllCerts, new java.security.SecureRandom());
31
+            SSLSocketFactory newFactory = sc.getSocketFactory();
32
+
33
+            connection.setSSLSocketFactory(newFactory);
34
+        } catch (Exception e) {
35
+            logger.error(e.getMessage(), e);
36
+        }
37
+        connection.setHostnameVerifier(new HostnameVerifier() {
38
+            public boolean verify(String hostname, SSLSession session) {
39
+                return true;
40
+            }
41
+        });
42
+    }
43
+    private static final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
44
+        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
45
+            return new java.security.cert.X509Certificate[]{};
46
+        }
47
+        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
48
+        }
49
+        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
50
+        }
51
+    }};
52
+    // trust-https end
53
+
54
+
22
     /**
55
     /**
23
      * post
56
      * post
24
      *
57
      *
35
             URL realUrl = new URL(url);
68
             URL realUrl = new URL(url);
36
             connection = (HttpURLConnection) realUrl.openConnection();
69
             connection = (HttpURLConnection) realUrl.openConnection();
37
 
70
 
71
+            // trust-https
72
+            boolean useHttps = url.startsWith("https");
73
+            if (useHttps) {
74
+                HttpsURLConnection https = (HttpsURLConnection) connection;
75
+                trustAllHosts(https);
76
+            }
77
+
38
             // connection setting
78
             // connection setting
39
             connection.setRequestMethod("POST");
79
             connection.setRequestMethod("POST");
40
             connection.setDoOutput(true);
80
             connection.setDoOutput(true);