Browse Source

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

xuxueli 5 years ago
parent
commit
90c19396c8

+ 1 - 1
doc/XXL-JOB官方文档.md View File

@@ -1675,7 +1675,7 @@ public ReturnT<String> execute(String param) {
1675 1675
 - 2、移除commons-exec,采用原生方式实现;
1676 1676
 - 3、执行器回调乱码问题修复;
1677 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 View File

@@ -5,11 +5,14 @@ import com.xxl.registry.client.util.json.BasicJson;
5 5
 import org.slf4j.Logger;
6 6
 import org.slf4j.LoggerFactory;
7 7
 
8
+import javax.net.ssl.*;
8 9
 import java.io.BufferedReader;
9 10
 import java.io.DataOutputStream;
10 11
 import java.io.InputStreamReader;
11 12
 import java.net.HttpURLConnection;
12 13
 import java.net.URL;
14
+import java.security.cert.CertificateException;
15
+import java.security.cert.X509Certificate;
13 16
 import java.util.Map;
14 17
 
15 18
 /**
@@ -19,6 +22,36 @@ public class XxlJobRemotingUtil {
19 22
     private static Logger logger = LoggerFactory.getLogger(XxlJobRemotingUtil.class);
20 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 56
      * post
24 57
      *
@@ -35,6 +68,13 @@ public class XxlJobRemotingUtil {
35 68
             URL realUrl = new URL(url);
36 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 78
             // connection setting
39 79
             connection.setRequestMethod("POST");
40 80
             connection.setDoOutput(true);