|
@@ -14,12 +14,22 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import io.argoproj.workflow.ApiClient;
|
|
|
//import org.apache.http.client.HttpClient;
|
|
|
+import org.apache.commons.httpclient.protocol.Protocol;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.security.cert.CertificateException;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
+
|
|
|
import org.apache.commons.httpclient.*;
|
|
|
import org.apache.commons.httpclient.methods.GetMethod;
|
|
|
import org.apache.commons.httpclient.params.HttpMethodParams;
|
|
|
+
|
|
|
+import javax.net.ssl.HttpsURLConnection;
|
|
|
+import javax.net.ssl.SSLContext;
|
|
|
+import javax.net.ssl.TrustManager;
|
|
|
+import javax.net.ssl.X509TrustManager;
|
|
|
+
|
|
|
/**
|
|
|
* Argo 工具
|
|
|
* @author Zhang
|
|
@@ -212,7 +222,7 @@ public class ArgoUtils {
|
|
|
* @return 获取到的工作流
|
|
|
* @throws ApiException api访问异常
|
|
|
*/
|
|
|
- public static String getWorkflowlog(String namespace,String workflowname,String containertype){
|
|
|
+ public static String getWorkflowlog(String namespace,String workflowname,String containertype) throws Exception {
|
|
|
// WorkflowServiceApi apiInstance = new WorkflowServiceApi(apiClient);
|
|
|
// return apiInstance.workflowServiceGetWorkflow(namespace, workflowname, null, null);
|
|
|
|
|
@@ -246,7 +256,7 @@ public class ArgoUtils {
|
|
|
* @return 获取到的工作流
|
|
|
* @throws ApiException api访问异常
|
|
|
*/
|
|
|
- public static String getpodlog(String namespace,String workflowname,String containertype,String podname){
|
|
|
+ public static String getpodlog(String namespace,String workflowname,String containertype,String podname) throws Exception {
|
|
|
// WorkflowServiceApi apiInstance = new WorkflowServiceApi(apiClient);
|
|
|
// return apiInstance.workflowServiceGetWorkflow(namespace, workflowname, null, null);
|
|
|
|
|
@@ -287,13 +297,24 @@ public class ArgoUtils {
|
|
|
* @param charset
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String doGet(String url, String charset) {
|
|
|
+ public static String doGet(String url, String charset) throws Exception {
|
|
|
+
|
|
|
+ trustAllHosts();
|
|
|
//1.生成HttpClient对象并设置参数
|
|
|
+// HttpClientFactory httpClientFactory = new HttpClientFactory();
|
|
|
+// org.apache.http.client.HttpClient httpClient = httpClientFactory.getHttpsClient();
|
|
|
+
|
|
|
HttpClient httpClient = new HttpClient();
|
|
|
+
|
|
|
+// httpClient.setHostnameVerifier(DO_NOT_VERIFY)
|
|
|
+ Protocol myhttps = new Protocol("https", new MySSLProtocolSocketFactory(), 443);
|
|
|
+ Protocol.registerProtocol("https", myhttps);
|
|
|
+
|
|
|
//设置Http连接超时为10秒
|
|
|
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
|
|
|
//2.生成GetMethod对象并设置参数
|
|
|
GetMethod getMethod = new GetMethod(url);
|
|
|
+
|
|
|
//设置get请求超时为10秒
|
|
|
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 10000);
|
|
|
//设置请求重试处理,用的是默认的重试处理:请求三次
|
|
@@ -325,12 +346,40 @@ public class ArgoUtils {
|
|
|
} catch (IOException e) {
|
|
|
//发生网络异常
|
|
|
System.out.println("发生网络异常!");
|
|
|
+ e.printStackTrace();
|
|
|
} finally {
|
|
|
//6.释放连接
|
|
|
getMethod.releaseConnection();
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Trust every server - dont check for any certificate
|
|
|
+ */
|
|
|
+ private static void trustAllHosts() {
|
|
|
+ final String TAG = "trustAllHosts";
|
|
|
+ // Create a trust manager that does not validate certificate chains
|
|
|
+ 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 {
|
|
|
+// Log.i(TAG, "checkClientTrusted");
|
|
|
+ }
|
|
|
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
|
+// Log.i(TAG, "checkServerTrusted");
|
|
|
+ }
|
|
|
+ } };
|
|
|
+ // Install the all-trusting trust manager
|
|
|
+ try {
|
|
|
+ SSLContext sc = SSLContext.getInstance("TLS");
|
|
|
+ sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
|
|
+ HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|