diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 1680b2e3..fe92d68a 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1675,7 +1675,7 @@ public ReturnT execute(String param) { - 2、移除commons-exec,采用原生方式实现; - 3、执行器回调乱码问题修复; - 4、调度中心dispatcher servlet加载顺序优化; -- 5、[迭代中]任务操作API服务调整为restful方式,降低接入成本; +- 5、执行器回调地址https兼容支持; diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobRemotingUtil.java b/xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobRemotingUtil.java index 6828a302..f853c947 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobRemotingUtil.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobRemotingUtil.java @@ -5,11 +5,14 @@ import com.xxl.registry.client.util.json.BasicJson; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.net.ssl.*; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import java.util.Map; /** @@ -19,6 +22,36 @@ public class XxlJobRemotingUtil { private static Logger logger = LoggerFactory.getLogger(XxlJobRemotingUtil.class); 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 * @@ -35,6 +68,13 @@ public class XxlJobRemotingUtil { URL realUrl = new URL(url); connection = (HttpURLConnection) realUrl.openConnection(); + // trust-https + boolean useHttps = url.startsWith("https"); + if (useHttps) { + HttpsURLConnection https = (HttpsURLConnection) connection; + trustAllHosts(https); + } + // connection setting connection.setRequestMethod("POST"); connection.setDoOutput(true);