Search in sources :

Example 1 with ClamavException

use of xyz.capybara.clamav.ClamavException in project ArachneCentralAPI by OHDSI.

the class AntivirusServiceImpl method processRequest.

@EventListener
@Async(value = "antivirusScanExecutor")
public void processRequest(AntivirusJobEvent event) {
    final AntivirusJob antivirusJob = event.getAntivirusJob();
    final AntivirusJobFileType fileType = antivirusJob.getAntivirusJobFileType();
    final Long fileId = antivirusJob.getFileId();
    logger.debug(PROCESSING_SCAN_REQUEST, fileId, fileType);
    String description = null;
    AntivirusStatus status;
    try {
        final ScanResult scan = retryTemplate.execute((RetryCallback<ScanResult, Exception>) retryContext -> {
            logger.debug(PROCESSING_SCAN_ATTEMPT, fileId, fileType);
            return scan(antivirusJob.getContent());
        });
        if (scan instanceof ScanResult.OK) {
            status = AntivirusStatus.OK;
        } else {
            status = AntivirusStatus.INFECTED;
            description = scan.toString();
        }
    } catch (Exception e) {
        logger.error("Error scanning file: {}", e.getMessage());
        if (e instanceof ClamavException) {
            final Throwable cause = e.getCause();
            description = cause.getMessage();
        } else {
            description = e.getMessage();
        }
        status = AntivirusStatus.NOT_SCANNED;
    }
    logger.debug(PROCESSING_SCAN_RESULT, fileId, fileType, status);
    publishResponse(fileType, fileId, status, description);
}
Also used : Async(org.springframework.scheduling.annotation.Async) LoggerFactory(org.slf4j.LoggerFactory) AntivirusJobResponse(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse) Autowired(org.springframework.beans.factory.annotation.Autowired) ScanResult(xyz.capybara.clamav.commands.scan.result.ScanResult) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) AntivirusJobStudyFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobStudyFileResponseEvent) Value(org.springframework.beans.factory.annotation.Value) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ClamavException(xyz.capybara.clamav.ClamavException) AntivirusJobPaperProtocolFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperProtocolFileResponseEvent) Logger(org.slf4j.Logger) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) AntivirusJobAnalysisFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobAnalysisFileResponseEvent) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) AntivirusJobPaperPaperFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperPaperFileResponseEvent) AntivirusJobResponseEventBase(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponseEventBase) ClamavClient(xyz.capybara.clamav.ClamavClient) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) RetryCallback(org.springframework.retry.RetryCallback) RetryTemplate(org.springframework.retry.support.RetryTemplate) InputStream(java.io.InputStream) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) ScanResult(xyz.capybara.clamav.commands.scan.result.ScanResult) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) ClamavException(xyz.capybara.clamav.ClamavException) IOException(java.io.IOException) ClamavException(xyz.capybara.clamav.ClamavException) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

AntivirusStatus (com.odysseusinc.arachne.portal.model.AntivirusStatus)1 AntivirusJob (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob)1 AntivirusJobAnalysisFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobAnalysisFileResponseEvent)1 AntivirusJobEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent)1 AntivirusJobFileType (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType)1 AntivirusJobPaperPaperFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperPaperFileResponseEvent)1 AntivirusJobPaperProtocolFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperProtocolFileResponseEvent)1 AntivirusJobResponse (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse)1 AntivirusJobResponseEventBase (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponseEventBase)1 AntivirusJobStudyFileResponseEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobStudyFileResponseEvent)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Value (org.springframework.beans.factory.annotation.Value)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 EventListener (org.springframework.context.event.EventListener)1 RetryCallback (org.springframework.retry.RetryCallback)1