Search in sources :

Example 1 with MessageProperties

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();
}
Also used : DefaultAvMessage(dvoraka.avservice.common.data.DefaultAvMessage) MessageProperties(org.springframework.amqp.core.MessageProperties) MessageType(dvoraka.avservice.common.data.MessageType)

Example 2 with MessageProperties

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

Aggregations

DefaultAvMessage (dvoraka.avservice.common.data.DefaultAvMessage)2 MessageProperties (org.springframework.amqp.core.MessageProperties)2 AvMessage (dvoraka.avservice.common.data.AvMessage)1 MessageType (dvoraka.avservice.common.data.MessageType)1 MapperException (dvoraka.avservice.common.exception.MapperException)1 Message (org.springframework.amqp.core.Message)1