Commit ebdee75f authored by 郑建's avatar 郑建

线上配置

parent 74494e41
...@@ -18,6 +18,7 @@ import org.apache.http.impl.client.HttpClients; ...@@ -18,6 +18,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.ssl.SSLContexts; import org.apache.http.ssl.SSLContexts;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
...@@ -41,6 +42,9 @@ import java.security.cert.X509Certificate; ...@@ -41,6 +42,9 @@ import java.security.cert.X509Certificate;
@Configuration @Configuration
public class HttpClientConfig { public class HttpClientConfig {
@Value("${niwodai.online}")
private Boolean isOnLine;
@Bean(name = "httpClient") @Bean(name = "httpClient")
public CloseableHttpClient httpClient() throws NoSuchAlgorithmException, KeyManagementException { public CloseableHttpClient httpClient() throws NoSuchAlgorithmException, KeyManagementException {
/** /**
...@@ -124,10 +128,10 @@ public class HttpClientConfig { ...@@ -124,10 +128,10 @@ public class HttpClientConfig {
} }
}; };
String classesPath = "/niwodai"; String classesPath = "/niwodai";
KeyStore keyStore = KeyStore.getInstance("PKCS12"); KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(HttpClientConfig.class.getResourceAsStream(classesPath + "/qg-keystore.jks"), "password".toCharArray()); keyStore.load(HttpClientConfig.class.getResourceAsStream(classesPath + "/qg-keystore" + (isOnLine?"":"-test") +".jks"), "password".toCharArray());
KeyStore trustStore = KeyStore.getInstance("JKS"); KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(HttpClientConfig.class.getResourceAsStream(classesPath + "/qg-truststore.jks"), "password".toCharArray()); trustStore.load(HttpClientConfig.class.getResourceAsStream(classesPath + "/qg-truststore" + (isOnLine?"":"-test") +".jks"), "password".toCharArray());
SSLContext sslcontext = SSLContexts.custom() SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy())
.loadKeyMaterial(keyStore, "password".toCharArray()) .loadKeyMaterial(keyStore, "password".toCharArray())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment