22
33import org .springframework .context .annotation .Bean ;
44import org .springframework .context .annotation .Configuration ;
5- import org .springframework .http .client .SimpleClientHttpRequestFactory ;
65import org .springframework .web .client .RestTemplate ;
76
8- import javax .net .ssl .*;
9- import java .security .KeyManagementException ;
10- import java .security .NoSuchAlgorithmException ;
11- import java .security .cert .X509Certificate ;
12-
137/**
14- * Configuration for RestTemplate to handle HTTP requests with SSL certificate handling
8+ * Configuration for RestTemplate to handle HTTP requests
159 */
1610@ Configuration
1711public class RestTemplateConfig {
1812
1913 @ Bean
20- public RestTemplate restTemplate () throws NoSuchAlgorithmException , KeyManagementException {
21- // Create a trust manager that trusts all certificates
22- TrustManager [] trustAllCerts = new TrustManager [] {
23- new X509TrustManager () {
24- public X509Certificate [] getAcceptedIssuers () {
25- return new X509Certificate [0 ];
26- }
27- public void checkClientTrusted (X509Certificate [] certs , String authType ) {
28- }
29- public void checkServerTrusted (X509Certificate [] certs , String authType ) {
30- }
31- }
32- };
33-
34- // Create SSL context that trusts all certificates
35- SSLContext sslContext = SSLContext .getInstance ("TLS" );
36- sslContext .init (null , trustAllCerts , new java .security .SecureRandom ());
37-
38- // Create SSL hostname verifier that accepts all hostnames
39- HostnameVerifier allHostsValid = (hostname , session ) -> true ;
40-
41- // Set default SSL context and hostname verifier
42- HttpsURLConnection .setDefaultSSLSocketFactory (sslContext .getSocketFactory ());
43- HttpsURLConnection .setDefaultHostnameVerifier (allHostsValid );
44-
45- // Create simple request factory with timeouts
46- SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory ();
47- factory .setConnectTimeout (10000 ); // 10 seconds
48- factory .setReadTimeout (30000 ); // 30 seconds
49-
50- return new RestTemplate (factory );
14+ public RestTemplate restTemplate () {
15+ // Use default RestTemplate configuration
16+ return new RestTemplate ();
5117 }
5218}
0 commit comments