SUPPORT-8507: refactoring
This commit is contained in:
parent
c620d6a0ad
commit
d09a96e24d
2 changed files with 15 additions and 18 deletions
|
|
@ -3,7 +3,7 @@ package ru.micord.ervu.av.response;
|
|||
/**
|
||||
* @author r.latypov
|
||||
*/
|
||||
public record AvScanResponse(String id, String location, Error error, String status) {
|
||||
public record AvFileSendResponse(String id, String location, Error error, String status) {
|
||||
public static final String STATUS_ERROR = "error";
|
||||
|
||||
public record Error(String code, String message) {
|
||||
|
|
@ -39,7 +39,7 @@ import ru.micord.ervu.av.exception.InvalidHttpFileUrlException;
|
|||
import ru.micord.ervu.av.kafka.dto.InMessage;
|
||||
import ru.micord.ervu.av.kafka.dto.OutErrorMessage;
|
||||
import ru.micord.ervu.av.response.AvResponse;
|
||||
import ru.micord.ervu.av.response.AvScanResponse;
|
||||
import ru.micord.ervu.av.response.AvFileSendResponse;
|
||||
|
||||
/**
|
||||
* @author r.latypov
|
||||
|
|
@ -75,20 +75,17 @@ public class FileUploadService {
|
|||
String downloadUrl = fileUrl.fileUrl();
|
||||
downloadFile(downloadUrl, filePath);
|
||||
|
||||
// todo активировать код в комментариях и отладить запросы к антивирусу SUPPORT-8507
|
||||
/*
|
||||
AvResponse avResponse = checkFile(filePath);
|
||||
|
||||
boolean clean = Arrays.stream(avResponse.verdicts())
|
||||
.anyMatch(verdict -> verdict.equalsIgnoreCase(AvResponse.Scan.VERDICT_CLEAN));
|
||||
boolean infected = Arrays.stream(avResponse.verdicts())
|
||||
.anyMatch(verdict -> verdict.equalsIgnoreCase("infected"));
|
||||
*/
|
||||
boolean infected = false;
|
||||
if (infected) {
|
||||
/*
|
||||
.anyMatch(verdict -> verdict.equalsIgnoreCase(AvResponse.Scan.VERDICT_INFECTED));
|
||||
|
||||
if (infected || !clean) {
|
||||
sendMessage(outErrorTopic.name(),
|
||||
new OutErrorMessage("file is infected", avResponse, inMessage)
|
||||
);
|
||||
*/
|
||||
}
|
||||
else {
|
||||
String uploadUrl = httpFileServerOutAddress + "/" + fileUrl.fileName();
|
||||
|
|
@ -183,9 +180,9 @@ public class FileUploadService {
|
|||
int postStatusCode = postResponse.getStatusLine().getStatusCode();
|
||||
String postResponseJson = EntityUtils.toString(postResponse.getEntity());
|
||||
|
||||
AvScanResponse avScanResponse = null;
|
||||
AvFileSendResponse avFileSendResponse;
|
||||
try {
|
||||
avScanResponse = new Gson().fromJson(postResponseJson, AvScanResponse.class);
|
||||
avFileSendResponse = new Gson().fromJson(postResponseJson, AvFileSendResponse.class);
|
||||
}
|
||||
catch (JsonSyntaxException e) {
|
||||
throw new FileUploadException("error json: " + postResponseJson, e);
|
||||
|
|
@ -195,24 +192,24 @@ public class FileUploadService {
|
|||
StringBuilder stringBuilder = new StringBuilder(
|
||||
"http status code " + postStatusCode + " for " + avRestAddress + " post request.");
|
||||
|
||||
String status = avScanResponse.status();
|
||||
String status = avFileSendResponse.status();
|
||||
if (status != null) {
|
||||
stringBuilder.append(" Status: ").append(status).append(".");
|
||||
}
|
||||
if (avScanResponse.error() != null) {
|
||||
stringBuilder.append(" Error code: ").append(avScanResponse.error().code())
|
||||
.append(". Error message: ").append(avScanResponse.error().message()).append(". ");
|
||||
if (avFileSendResponse.error() != null) {
|
||||
stringBuilder.append(" Error code: ").append(avFileSendResponse.error().code())
|
||||
.append(". Error message: ").append(avFileSendResponse.error().message()).append(". ");
|
||||
}
|
||||
throw new FileUploadException(stringBuilder.toString());
|
||||
}
|
||||
|
||||
String id = avScanResponse.id();
|
||||
String id = avFileSendResponse.id();
|
||||
String reportRequestUri = avRestAddress + "/" + id;
|
||||
HttpGet get = new HttpGet(reportRequestUri);
|
||||
|
||||
int countdown = 10;
|
||||
long timeout = 1L;
|
||||
AvResponse avResponse = null;
|
||||
AvResponse avResponse;
|
||||
|
||||
do {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue