use of org.springframework.amqp.core.MessageProperties 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();
}
use of org.springframework.amqp.core.MessageProperties 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