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

master
xuxueli 5 years ago
parent e751acaf2b
commit 90c19396c8
  1. 2
      doc/XXL-JOB官方文档.md
  2. 40
      xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobRemotingUtil.java

@ -1675,7 +1675,7 @@ public ReturnT<String> execute(String param) {
- 2、移除commons-exec,采用原生方式实现; - 2、移除commons-exec,采用原生方式实现;
- 3、执行器回调乱码问题修复; - 3、执行器回调乱码问题修复;
- 4、调度中心dispatcher servlet加载顺序优化; - 4、调度中心dispatcher servlet加载顺序优化;
- 5、[迭代中]任务操作API服务调整为restful方式,降低接入成本 - 5、执行器回调地址https兼容支持

@ -5,11 +5,14 @@ import com.xxl.registry.client.util.json.BasicJson;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.net.ssl.*;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map; import java.util.Map;
/** /**
@ -19,6 +22,36 @@ public class XxlJobRemotingUtil {
private static Logger logger = LoggerFactory.getLogger(XxlJobRemotingUtil.class); private static Logger logger = LoggerFactory.getLogger(XxlJobRemotingUtil.class);
public static String XXL_RPC_ACCESS_TOKEN = "XXL-RPC-ACCESS-TOKEN"; public static String XXL_RPC_ACCESS_TOKEN = "XXL-RPC-ACCESS-TOKEN";
// trust-https start
private static void trustAllHosts(HttpsURLConnection connection) {
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory newFactory = sc.getSocketFactory();
connection.setSSLSocketFactory(newFactory);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
connection.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
private static final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
}};
// trust-https end
/** /**
* post * post
* *
@ -35,6 +68,13 @@ public class XxlJobRemotingUtil {
URL realUrl = new URL(url); URL realUrl = new URL(url);
connection = (HttpURLConnection) realUrl.openConnection(); connection = (HttpURLConnection) realUrl.openConnection();
// trust-https
boolean useHttps = url.startsWith("https");
if (useHttps) {
HttpsURLConnection https = (HttpsURLConnection) connection;
trustAllHosts(https);
}
// connection setting // connection setting
connection.setRequestMethod("POST"); connection.setRequestMethod("POST");
connection.setDoOutput(true); connection.setDoOutput(true);

Loading…
Cancel
Save