|
@ -3,11 +3,15 @@ package com.yihu.hos.rest.common.http;
|
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
|
import com.yihu.hos.core.http.HTTPResponse;
|
|
|
import com.yihu.hos.core.http.HttpClientKit;
|
|
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
|
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
|
|
import org.apache.http.ssl.SSLContexts;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.core.io.support.EncodedResource;
|
|
|
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
|
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
import java.io.File;
|
|
|
import java.util.Map;
|
|
|
import java.util.Properties;
|
|
@ -17,6 +21,7 @@ public class EHRHttpHelper {
|
|
|
public static String defaultHttpUrl;
|
|
|
public static String clientId;
|
|
|
public static String clientKey;
|
|
|
private static SSLConnectionSocketFactory defaultSSL;
|
|
|
private static String defaultHttpUser;
|
|
|
private static String defaultHttpPassword;
|
|
|
|
|
@ -46,6 +51,16 @@ public class EHRHttpHelper {
|
|
|
HttpClientKit.addKeyStore(defaultHttpUrl, sslKeystore, sslPassword);
|
|
|
}
|
|
|
|
|
|
SSLContext sslContext = SSLContexts.custom()
|
|
|
.loadTrustMaterial(new File(sslKeystore), sslPassword.toCharArray(),
|
|
|
new TrustSelfSignedStrategy())
|
|
|
.build();
|
|
|
defaultSSL = new SSLConnectionSocketFactory(
|
|
|
sslContext,
|
|
|
new String[]{"TLSv1"},
|
|
|
null,
|
|
|
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
|
|
HttpClientKit.addKeyStoreSSL(defaultHttpUrl, defaultSSL);
|
|
|
} catch (Exception e) {
|
|
|
System.out.print(e.getMessage());
|
|
|
}
|
|
@ -107,21 +122,11 @@ public class EHRHttpHelper {
|
|
|
}
|
|
|
|
|
|
public static HTTPResponse postFile(String url, Map<String, String> formParams, String filePath, Map<String, String> header) {
|
|
|
if (url.startsWith("https")) {
|
|
|
return HttpClientKit.postFile(url, filePath, formParams);
|
|
|
} else {
|
|
|
//默认http不走ssl和用户密码
|
|
|
return HttpClientKit.postFile(url, filePath, formParams);
|
|
|
}
|
|
|
return HttpClientKit.postFile(url, filePath, formParams);
|
|
|
}
|
|
|
|
|
|
public static HTTPResponse postFile(String url, Map<String, String> formParams, File file, Map<String, String> header) {
|
|
|
if (url.startsWith("https")) {
|
|
|
return HttpClientKit.postFile(url, file.getAbsolutePath(), formParams);
|
|
|
} else {
|
|
|
//默认http不走ssl和用户密码
|
|
|
return HttpClientKit.postFile(url, file.getAbsolutePath(), formParams);
|
|
|
}
|
|
|
return HttpClientKit.postFile(url, file.getAbsolutePath(), formParams);
|
|
|
}
|
|
|
|
|
|
/**************************
|