erea

spring boot http client ssl 체크 패스하기 본문

dev/spring boot

spring boot http client ssl 체크 패스하기

erea 2018. 6. 25. 00:17

내부 테스트서버나 로컬에서 ssl 통신을 할때 유용하다.


httpClientConfig.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<p>@Configuration
public class HttpClientConfig {
 
    @Bean
    public RestTemplate restTemplate()
            throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
        TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
 
        SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
                .loadTrustMaterial(null, acceptingTrustStrategy)
                .build();
 
        SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
 
        CloseableHttpClient httpClient = HttpClients.custom()
                .setSSLSocketFactory(csf)
                .build();
 
        HttpComponentsClientHttpRequestFactory requestFactory =
                new HttpComponentsClientHttpRequestFactory();
 
        requestFactory.setHttpClient(httpClient);
        RestTemplate restTemplate = new RestTemplate(requestFactory);
        return restTemplate;
    }
}
</p>


생성후 본문에

1
2
3
4
@Autowire
HttpClientConfig httpClientConfig<
URI uri = URI.create(Url+ "/api/articles");
String responseString = httpClientConfig.getForObject(uri, String.class);

'dev > spring boot' 카테고리의 다른 글

spring boot ssl  (1) 2019.01.02
Spring boot devtools hot swapping by intelij  (0) 2018.07.05
Setter DI vs. Constructor DI in Spring  (0) 2018.06.25
spring boot 2.0 hibernate 5 mysql auto increment  (0) 2018.06.25
spring boot  (0) 2018.06.24
Comments