Skip to content

Commit

Permalink
added timeout to http call
Browse files Browse the repository at this point in the history
  • Loading branch information
yvasyliev committed Jan 3, 2024
1 parent 0599fca commit bdc7564
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.Spliterator;
Expand Down Expand Up @@ -46,6 +47,9 @@ public class SubredditNewSupplier implements ThrowingSupplier<List<Post>> {
@Autowired
private HttpClient httpClient;

@Value("5")
private long timeout;

@Override
@NonNull
public List<Post> getWithException() throws Exception {
Expand Down Expand Up @@ -83,6 +87,7 @@ private JsonNode fetchNewPosts() throws Exception {
.header("Authorization", authorization)
.header("User-Agent", userAgent)
.GET()
.timeout(Duration.ofMinutes(timeout))
.build();
var jsonBody = httpClient.send(request, HttpResponse.BodyHandlers.ofString()).body();
return objectMapper.readTree(jsonBody);
Expand Down

0 comments on commit bdc7564

Please sign in to comment.