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();
}
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations