Search in sources :

Example 1 with MapperException

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

Example 2 with MapperException

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

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