|
11 | 11 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; |
12 | 12 | import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; |
13 | 13 | import org.apache.hc.core5.http.ContentType; |
| 14 | +import org.apache.hc.core5.http.HttpRequest; |
14 | 15 | import org.apache.hc.core5.http.HttpStatus; |
15 | 16 | import org.apache.hc.core5.http.io.entity.EntityUtils; |
16 | 17 | import org.apache.hc.core5.http.io.entity.HttpEntities; |
|
19 | 20 | import java.io.IOException; |
20 | 21 | import java.net.URI; |
21 | 22 | import java.net.URISyntaxException; |
22 | | -import org.apache.hc.core5.http.HttpRequest; |
23 | 23 | import java.nio.charset.StandardCharsets; |
24 | 24 | import java.util.Arrays; |
25 | 25 | import java.util.Collections; |
@@ -87,19 +87,21 @@ public SplitHttpResponse get(URI uri, FetchOptions options, Map<String, List<Str |
87 | 87 | } |
88 | 88 |
|
89 | 89 | String statusMessage = ""; |
90 | | - if (response.getCode() < HttpStatus.SC_OK || response.getCode() >= HttpStatus.SC_MULTIPLE_CHOICES) { |
91 | | - _log.warn(String.format("Response status was: %s. Reason: %s", response.getCode(), |
92 | | - response.getReasonPhrase())); |
| 90 | + int code = response.getCode(); |
| 91 | + String body = ""; |
| 92 | + if (code < HttpStatus.SC_OK || code >= HttpStatus.SC_MULTIPLE_CHOICES) { |
93 | 93 | statusMessage = response.getReasonPhrase(); |
| 94 | + _log.warn(String.format("Response status was: %s. Reason: %s", code, statusMessage)); |
| 95 | + } else { |
| 96 | + body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); |
94 | 97 | } |
95 | 98 |
|
96 | | - return new SplitHttpResponse(response.getCode(), |
| 99 | + return new SplitHttpResponse(code, |
97 | 100 | statusMessage, |
98 | | - EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8), |
| 101 | + body, |
99 | 102 | Arrays.stream(response.getHeaders()).map( |
100 | | - h -> new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue()))) |
| 103 | + h -> new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue()))) |
101 | 104 | .collect(Collectors.toList())); |
102 | | - // response.getHeaders()); |
103 | 105 | } catch (Exception e) { |
104 | 106 | throw new IllegalStateException(String.format("Problem in http get operation: %s", e), e); |
105 | 107 | } finally { |
|
0 commit comments