From 39c19c8c4a7bc1ca78dab0272c63896b143639f0 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 7 Dec 2009 11:41:35 +0000 Subject: [PATCH] INT-903 AbstractPayloadTransformer now treats return values of type Message as the result rather than considering that the payload of a new Message. --- .../transformer/AbstractPayloadTransformer.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/transformer/AbstractPayloadTransformer.java b/org.springframework.integration/src/main/java/org/springframework/integration/transformer/AbstractPayloadTransformer.java index 64fdd8fa62..03399441c0 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/transformer/AbstractPayloadTransformer.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/transformer/AbstractPayloadTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,17 +21,21 @@ import org.springframework.integration.message.MessageBuilder; /** * A base class for {@link Transformer} implementations that modify - * the payload of a {@link Message}. + * the payload of a {@link Message}. If the return value is itself + * a Message, it will be used as the result. Otherwise, the return + * value will be used as the payload of the result Message. * * @author Mark Fisher */ public abstract class AbstractPayloadTransformer implements Transformer { + @SuppressWarnings("unchecked") public final Message transform(Message message) { try { - @SuppressWarnings("unchecked") U result = this.transformPayload((T) message.getPayload()); - return MessageBuilder.withPayload(result).copyHeaders(message.getHeaders()).build(); + return (result instanceof Message) + ? MessageBuilder.fromMessage((Message) result).build() + : MessageBuilder.withPayload(result).copyHeaders(message.getHeaders()).build(); } catch (MessageTransformationException e) { throw e;