1 | package edu.ucsb.cs156.spring.backenddemo.services; | |
2 | ||
3 | import org.springframework.web.client.RestTemplate; | |
4 | ||
5 | import lombok.extern.slf4j.Slf4j; | |
6 | ||
7 | import java.util.List; | |
8 | import java.util.Map; | |
9 | ||
10 | import org.springframework.boot.web.client.RestTemplateBuilder; | |
11 | import org.springframework.http.HttpEntity; | |
12 | import org.springframework.http.HttpHeaders; | |
13 | import org.springframework.http.HttpMethod; | |
14 | import org.springframework.http.MediaType; | |
15 | import org.springframework.http.ResponseEntity; | |
16 | import org.springframework.stereotype.Service; | |
17 | import org.springframework.web.client.HttpClientErrorException; | |
18 | ||
19 | @Slf4j | |
20 | @Service | |
21 | public class PublicHolidayQueryService { | |
22 | ||
23 | ||
24 | private final RestTemplate restTemplate; | |
25 | ||
26 | public PublicHolidayQueryService(RestTemplateBuilder restTemplateBuilder) { | |
27 | restTemplate = restTemplateBuilder.build(); | |
28 | } | |
29 | ||
30 | public static final String ENDPOINT = "https://date.nager.at/api/v2/publicholidays/{year}/{countryCode}"; | |
31 | ||
32 | public String getJSON(String year, String countryCode) throws HttpClientErrorException { | |
33 | log.info("year={}, countryCode={}", year, countryCode); | |
34 | HttpHeaders headers = new HttpHeaders(); | |
35 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(List.of(MediaType.APPLICATION_JSON)); |
36 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
37 | ||
38 | HttpEntity<String> entity = new HttpEntity<>(headers); | |
39 | ||
40 | Map<String, String> uriVariables = Map.of("year", year, "countryCode", countryCode); | |
41 | ||
42 | ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class, | |
43 | uriVariables); | |
44 |
1
1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/PublicHolidayQueryService::getJSON → KILLED |
return re.getBody(); |
45 | } | |
46 | } | |
Mutations | ||
35 |
1.1 |
|
36 |
1.1 |
|
44 |
1.1 |