2
2
3
3
import org .springframework .context .annotation .Bean ;
4
4
import org .springframework .context .annotation .Configuration ;
5
- import org .springframework .http .client .SimpleClientHttpRequestFactory ;
6
5
import org .springframework .web .client .RestTemplate ;
7
6
8
- import javax .net .ssl .*;
9
- import java .security .KeyManagementException ;
10
- import java .security .NoSuchAlgorithmException ;
11
- import java .security .cert .X509Certificate ;
12
-
13
7
/**
14
- * Configuration for RestTemplate to handle HTTP requests with SSL certificate handling
8
+ * Configuration for RestTemplate to handle HTTP requests
15
9
*/
16
10
@ Configuration
17
11
public class RestTemplateConfig {
18
12
19
13
@ 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 ();
51
17
}
52
18
}
0 commit comments