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 ZipCodeQueryService { | |
22 | ||
23 | private final RestTemplate restTemplate; | |
24 | ||
25 | public ZipCodeQueryService(RestTemplateBuilder restTemplateBuilder) { | |
26 | restTemplate = restTemplateBuilder.build(); | |
27 | } | |
28 | ||
29 | public static final String ENDPOINT = "http://api.zippopotam.us/us/{zipcode}"; | |
30 | ||
31 | public String getJSON(String zipcode) throws HttpClientErrorException { | |
32 | log.info("zipcode={}", zipcode); | |
33 | HttpHeaders headers = new HttpHeaders(); | |
34 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setAccept → KILLED |
headers.setAccept(List.of(MediaType.APPLICATION_JSON)); |
35 |
1
1. getJSON : removed call to org/springframework/http/HttpHeaders::setContentType → KILLED |
headers.setContentType(MediaType.APPLICATION_JSON); |
36 | ||
37 | Map<String, String> uriVariables = Map.of("zipcode", zipcode); | |
38 | ||
39 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
40 | ||
41 | ResponseEntity<String> re = restTemplate.exchange(ENDPOINT, HttpMethod.GET, entity, String.class, | |
42 | uriVariables); | |
43 |
1
1. getJSON : replaced return value with "" for edu/ucsb/cs156/spring/backenddemo/services/ZipCodeQueryService::getJSON → KILLED |
return re.getBody(); |
44 | } | |
45 | } | |
Mutations | ||
34 |
1.1 |
|
35 |
1.1 |
|
43 |
1.1 |