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