Search in sources :

Example 6 with AvMessage

use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.

the class SimpleChecker method receiveMessage.

@Override
public AvMessage receiveMessage(String correlationId) throws MessageNotFoundException {
    List<AvMessage> savedMessages = new ArrayList<>(QUEUE_CAPACITY);
    AvMessage message;
    while (true) {
        try {
            message = queue.poll(MAX_TIMEOUT, TimeUnit.MILLISECONDS);
            if (message == null) {
                throw new MessageNotFoundException();
            }
            if (message.getCorrelationId().equals(correlationId)) {
                returnMessagesToQueue(savedMessages);
                savedMessages.clear();
                return message;
            } else {
                savedMessages.add(message);
            }
        } catch (InterruptedException e) {
            log.warn("Waiting interrupted!", e);
            Thread.currentThread().interrupt();
        }
    }
}
Also used : MessageNotFoundException(dvoraka.avservice.common.exception.MessageNotFoundException) ArrayList(java.util.ArrayList) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 7 with AvMessage

use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.

the class AmqpComponent method onMessage.

@Override
public void onMessage(Message message) {
    requireNonNull(message, "Message must not be null!");
    AvMessage avMessage;
    try {
        avMessage = (AvMessage) messageConverter.fromMessage(message);
        messageInfoService.save(avMessage, AvMessageSource.AMQP_COMPONENT_IN, serviceId);
    } catch (MessageConversionException e) {
        log.warn("Conversion error!", e);
        return;
    }
    notifyListeners(listeners, avMessage);
}
Also used : MessageConversionException(org.springframework.amqp.support.converter.MessageConversionException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 8 with AvMessage

use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.

the class AvMessageMapper method transform.

/**
     * Transforms AV message to AMQP message.
     *
     * @param msg the AV message
     * @return the AMQP message
     * @throws MapperException if mapping failed
     */
public Message transform(AvMessage msg) throws MapperException {
    log.debug("AVTransform: " + msg);
    requireNonNull(msg, "Message must not be null!");
    // mandatory fields
    if (msg.getId() == null) {
        throw new MapperException("Message ID must not be null");
    } else if (msg.getType() == null) {
        throw new MapperException("Message type must not be null");
    }
    MessageProperties props = new MessageProperties();
    props.setMessageId(msg.getId());
    props.setType(msg.getType().toString());
    // correlation ID
    if (msg.getCorrelationId() != null) {
        props.setCorrelationId(msg.getCorrelationId());
    }
    // virus info
    props.setHeader(VIRUS_INFO_KEY, msg.getVirusInfo());
    // owner
    props.setHeader(OWNER_KEY, msg.getOwner());
    // filename
    props.setHeader(FILENAME_KEY, msg.getFilename());
    return new Message(msg.getData(), props);
}
Also used : Message(org.springframework.amqp.core.Message) AvMessage(dvoraka.avservice.common.data.AvMessage) DefaultAvMessage(dvoraka.avservice.common.data.DefaultAvMessage) MessageProperties(org.springframework.amqp.core.MessageProperties) MapperException(dvoraka.avservice.common.exception.MapperException)

Example 9 with AvMessage

use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.

the class JmsComponent method onMessage.

@Override
public void onMessage(Message message) {
    requireNonNull(message, "Message must not be null!");
    AvMessage avMessage;
    try {
        avMessage = (AvMessage) messageConverter.fromMessage(message);
        messageInfoService.save(avMessage, AvMessageSource.JMS_COMPONENT_IN, serviceId);
    } catch (JMSException | MessageConversionException e) {
        log.warn("Conversion error!", e);
        return;
    }
    notifyListeners(listeners, avMessage);
}
Also used : MessageConversionException(org.springframework.jms.support.converter.MessageConversionException) JMSException(javax.jms.JMSException) AvMessage(dvoraka.avservice.common.data.AvMessage)

Example 10 with AvMessage

use of dvoraka.avservice.common.data.AvMessage in project av-service by dvoraka.

the class FileController method deleteFile.

@DeleteMapping("/{filename}")
public ResponseEntity<Void> deleteFile(@PathVariable String filename, Principal principal) {
    log.debug("Delete file: {}, principal: {}", filename, principal);
    AvMessage fileRequest = new DefaultAvMessage.Builder(Utils.genUuidString()).filename(filename).owner(principal.getName()).type(MessageType.FILE_DELETE).build();
    restService.deleteFile(fileRequest);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AvMessage(dvoraka.avservice.common.data.AvMessage) DefaultAvMessage(dvoraka.avservice.common.data.DefaultAvMessage) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Aggregations

AvMessage (dvoraka.avservice.common.data.AvMessage)10 DefaultAvMessage (dvoraka.avservice.common.data.DefaultAvMessage)3 MessageNotFoundException (dvoraka.avservice.common.exception.MessageNotFoundException)3 ResponseEntity (org.springframework.http.ResponseEntity)2 MapperException (dvoraka.avservice.common.exception.MapperException)1 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 JMSException (javax.jms.JMSException)1 Message (org.springframework.amqp.core.Message)1 MessageProperties (org.springframework.amqp.core.MessageProperties)1 MessageConversionException (org.springframework.amqp.support.converter.MessageConversionException)1 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1