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