SUPPORT-8689: fix(5) add logs and information
This commit is contained in:
parent
18afc154fd
commit
791eee72d3
1 changed files with 6 additions and 32 deletions
|
|
@ -1,13 +1,10 @@
|
|||
package ervu.client.okopf;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -28,36 +25,13 @@ public class EsnsiOkopfClient {
|
|||
private static final Logger logger = LoggerFactory.getLogger(EsnsiOkopfClient.class);
|
||||
|
||||
@Value("${esnsi.okopf.url}")
|
||||
private String uri;
|
||||
private String url;
|
||||
|
||||
@Retryable(maxAttemptsExpression = "${esnsi.okopf.retry.max.attempts.load:3}", backoff =
|
||||
@Backoff(delayExpression = "${esnsi.okop.retry.delay.load:1000}"))
|
||||
public String getJsonOkopFormData() {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(uri))
|
||||
.GET()
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<InputStream> response = client.send(request,
|
||||
HttpResponse.BodyHandlers.ofInputStream()
|
||||
);
|
||||
if (response.statusCode() >= 200 && response.statusCode() <= 202) {
|
||||
return unzipFile(response.body());
|
||||
}
|
||||
logger.warn("The returned status {} is incorrect. Json file has not be unzip",
|
||||
response.statusCode()
|
||||
);
|
||||
}
|
||||
catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(
|
||||
"Failed to send HTTP request or process the response for okopf file.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String unzipFile(InputStream inputStream) {
|
||||
try (ZipArchiveInputStream archiveStream = new ZipArchiveInputStream(inputStream);
|
||||
try (BufferedInputStream in = new BufferedInputStream(new URL(url).openStream());
|
||||
ZipArchiveInputStream archiveStream = new ZipArchiveInputStream(in);
|
||||
BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(archiveStream, StandardCharsets.UTF_8))) {
|
||||
if (Objects.nonNull(archiveStream.getNextEntry())) {
|
||||
|
|
@ -66,7 +40,7 @@ public class EsnsiOkopfClient {
|
|||
logger.warn("Esnsi okopf client received an empty archive in response.");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException("Failed to unzip the okopf file", e);
|
||||
logger.error("Failed to send HTTP request or process the response for okopf file.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue