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