use of dvoraka.avservice.common.data.MessageType 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.data.MessageType in project av-service by dvoraka.
the class AvMessageMapper method transform.
/**
* Transforms AMQP message to AV message.
*
* @param msg the AMQP message
* @return the AV message
* @throws MapperException if mapping failed
*/
public AvMessage transform(Message msg) throws MapperException {
log.debug("Transform: " + msg);
requireNonNull(msg, "Message must not be null!");
MessageProperties props = msg.getMessageProperties();
Map<String, Object> headers = props.getHeaders();
checkMandatoryFields(props);
// virus info
String virusInfo = getHeaderValue(headers, VIRUS_INFO_KEY);
// owner
String owner = getHeaderValue(headers, OWNER_KEY);
// filename
String filename = getHeaderValue(headers, FILENAME_KEY);
// message type
MessageType messageType = getMessageType(props);
// correlation ID
String corrId = getCorrelationId(props);
return new DefaultAvMessage.Builder(props.getMessageId()).correlationId(corrId).type(messageType).data(msg.getBody()).owner(owner).filename(filename).virusInfo(virusInfo).build();
}
Aggregations