Skip to content

Commit 8dfe922

Browse files
cursoragentram.dafale
andcommitted
Configure SSL handling for RestTemplate and add development SSL settings
Co-authored-by: ram.dafale <[email protected]>
1 parent 00d0d7f commit 8dfe922

File tree

9 files changed

+75
-8
lines changed

9 files changed

+75
-8
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@
8484
<artifactId>spring-boot-starter-test</artifactId>
8585
<scope>test</scope>
8686
</dependency>
87+
88+
<!-- Apache HttpClient for better SSL handling -->
89+
<dependency>
90+
<groupId>org.apache.httpcomponents</groupId>
91+
<artifactId>httpclient</artifactId>
92+
<version>4.5.13</version>
93+
</dependency>
8794
</dependencies>
8895

8996
<build>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.tennis;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
6+
7+
/**
8+
* Main Spring Boot application class for Tennis Match Prediction Service
9+
*/
10+
@SpringBootApplication
11+
@EnableScheduling
12+
public class TennisMatchPredictionApplication {
13+
14+
public static void main(String[] args) {
15+
// Disable SSL certificate validation for development
16+
System.setProperty("com.sun.net.ssl.checkRevocation", "false");
17+
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
18+
19+
SpringApplication.run(TennisMatchPredictionApplication.class, args);
20+
}
21+
}
Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
11
package com.tennis.config;
22

3+
import org.apache.http.conn.ssl.NoopHostnameVerifier;
4+
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
5+
import org.apache.http.impl.client.CloseableHttpClient;
6+
import org.apache.http.impl.client.HttpClients;
7+
import org.apache.http.ssl.TrustStrategy;
38
import org.springframework.context.annotation.Bean;
49
import org.springframework.context.annotation.Configuration;
5-
import org.springframework.http.client.SimpleClientHttpRequestFactory;
10+
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
611
import org.springframework.web.client.RestTemplate;
712

13+
import javax.net.ssl.SSLContext;
14+
import java.security.cert.X509Certificate;
15+
816
/**
9-
* Configuration for RestTemplate to handle HTTP requests
17+
* Configuration for RestTemplate to handle HTTP requests with SSL certificate handling
1018
*/
1119
@Configuration
1220
public class RestTemplateConfig {
1321

1422
@Bean
15-
public RestTemplate restTemplate() {
16-
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
17-
factory.setConnectTimeout(10000); // 10 seconds
18-
factory.setReadTimeout(30000); // 30 seconds
23+
public RestTemplate restTemplate() throws Exception {
24+
// Create trust strategy that trusts all certificates
25+
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
26+
27+
// Create SSL context with trust all strategy
28+
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
29+
.loadTrustMaterial(null, acceptingTrustStrategy)
30+
.build();
31+
32+
// Create SSL connection socket factory
33+
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(
34+
sslContext,
35+
new String[] { "TLSv1.2" },
36+
null,
37+
NoopHostnameVerifier.INSTANCE);
38+
39+
// Create HTTP client with SSL configuration
40+
CloseableHttpClient httpClient = HttpClients.custom()
41+
.setSSLSocketFactory(csf)
42+
.build();
43+
44+
// Create request factory with custom HTTP client
45+
HttpComponentsClientHttpRequestFactory requestFactory =
46+
new HttpComponentsClientHttpRequestFactory(httpClient);
47+
requestFactory.setConnectTimeout(10000); // 10 seconds
48+
requestFactory.setReadTimeout(30000); // 30 seconds
1949

20-
return new RestTemplate(factory);
50+
return new RestTemplate(requestFactory);
2151
}
2252
}

src/main/resources/application.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ logging.level.org.springframework.web=DEBUG
3131
tennis.api.base-url=flashscore4.p.rapidapi.com
3232
tennis.api.key=a4957eda31msh7e6d3990d2a573ap13d4c0jsn64bf47d8f40c
3333

34+
# SSL Configuration for development (disable certificate validation)
35+
tennis.api.ssl.trust-all=true
36+
tennis.api.ssl.verify-hostname=false
37+
3438
# Application specific properties
3539
tennis.prediction.model.threshold=0.6
3640
tennis.prediction.update-interval=30000

target/classes/application.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ logging.level.org.springframework.web=DEBUG
3131
tennis.api.base-url=flashscore4.p.rapidapi.com
3232
tennis.api.key=a4957eda31msh7e6d3990d2a573ap13d4c0jsn64bf47d8f40c
3333

34+
# SSL Configuration for development (disable certificate validation)
35+
tennis.api.ssl.trust-all=true
36+
tennis.api.ssl.verify-hostname=false
37+
3438
# Application specific properties
3539
tennis.prediction.model.threshold=0.6
3640
tennis.prediction.update-interval=30000
1.05 KB
Binary file not shown.
-983 Bytes
Binary file not shown.

target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
com/tennis/config/RestTemplateConfig.class
21
com/tennis/entity/MatchPrediction.class
32
com/tennis/controller/TennisPredictionController.class
3+
com/tennis/TennisMatchPredictionApplication.class
44
com/tennis/TennisPredictionApplication.class
55
com/tennis/repository/MatchRepository.class
66
com/tennis/entity/HeadToHead.class

target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/workspace/src/main/java/com/tennis/TennisMatchPredictionApplication.java
12
/workspace/src/main/java/com/tennis/entity/HeadToHead.java
23
/workspace/src/main/java/com/tennis/controller/TennisPredictionController.java
34
/workspace/src/main/java/com/tennis/service/PredictionService.java

0 commit comments

Comments
 (0)