1

This is a Hashing processor where I want to hash a FileInputStream using the SHA-1 algorithm and then add the hash to the exchange header under "HashValue"

@Component

public class FileContentHashExpression implements Expression {

    @Override
    public <T> T evaluate(Exchange exchange, Class<T> type) {
        // TODO Check for String type and generic file message
        if (type != String.class){
            throw new IllegalArgumentException("This is String only expression");
        }
        try (FileInputStream fileInputStream = new FileInputStream(((File)exchange.getIn(GenericFileMessage.class).getGenericFile().getFile()))) {
            exchange.getIn().setHeader("HashValue", DigestUtils.sha1(fileInputStream));
            return (T) (DigestUtils.sha1(fileInputStream));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

1 Answers1

0

This is a unit test, so all you need to do is write a test that builds a Exchange with a null (or empty) input Message body and call the method. Test the conditions you expect.

Steve Huston
  • 1,432
  • 13
  • 20