|
@@ -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);
|