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