-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleOrdersClient.java
54 lines (44 loc) · 1.64 KB
/
ExampleOrdersClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package stability;
import java.io.IOException;
import java.net.http.*;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import stability.config.CircuitBreakerConfig;
import stability.config.ExponentialBackoffConfig;
public class ExampleOrdersClient implements OrdersFetcher {
private final String uri;
private static final HttpClient httpClient = HttpClient.newHttpClient();
private static final ObjectMapper objectMapper = new ObjectMapper();
public ExampleOrdersClient(String uri) {
this.uri = uri;
}
@Override
public List<Order> fetchOrders() throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(uri))
.GET()
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Parse the JSON response to a List<Order>
return objectMapper.readValue(response.body(), new TypeReference<List<Order>>() {});
}
@Override
public List<Order> fetchOrdersWithFallback(List<Order> orders) {
return List.of();
}
@Override
public List<Order> fetchOrdersWithRetries(int maxRetries, ExponentialBackoffConfig backoffConfig) {
return List.of();
}
@Override
public List<Order> fetchOrdersWithTimeout(Duration timeout) {
return List.of();
}
@Override
public List<Order> fetchOrdersWithCircuitBreaker(CircuitBreakerConfig circuitBreakerConfig) {
return List.of();
}
}