use of dvoraka.avservice.common.exception.MapperException in project av-service by dvoraka.
the class AvMessageMapper method getMessageType.
private MessageType getMessageType(MessageProperties msgProps) throws MapperException {
String messageTypeStr = msgProps.getType().toUpperCase();
MessageType messageType;
try {
messageType = MessageType.valueOf(messageTypeStr);
} catch (IllegalArgumentException e) {
log.warn("Message type error!", e);
throw new MapperException("Unknown message type");
}
return messageType;
}
use of dvoraka.avservice.common.exception.MapperException 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);
}
Aggregations