Search in sources :

Example 1 with MessageType

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;
}
Also used : MapperException(dvoraka.avservice.common.exception.MapperException) MessageType(dvoraka.avservice.common.data.MessageType)

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

Aggregations

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