INT-3369: Syslog Converter asMap Option

JIRA: https://jira.spring.io/browse/INT-3369

INT-3369: add option asMap in DefaultMessageConverter
* add test

GH-1250
This commit is contained in:
David Liu
2014-08-08 10:06:59 +08:00
committed by Gary Russell
parent 9766c8b4e7
commit e3644d8792
4 changed files with 60 additions and 6 deletions

View File

@@ -31,11 +31,11 @@ import org.springframework.integration.transformer.SyslogToMapTransformer;
import org.springframework.messaging.Message;
/**
* Default {@link MessageConverter}; delegates to a {@link SyslogToMapTransformer}
* to convert the payload to a map of values and also provides some of the map
* contents as message headers.
* See @link {@link SyslogHeaders} for the headers that are mapped.
* Default {@link MessageConverter}; delegates to a {@link SyslogToMapTransformer} to
* convert the payload to a map of values and also provides some of the map contents as
* message headers. See @link {@link SyslogHeaders} for the headers that are mapped.
* @author Gary Russell
* @author David Liu
* @since 3.0
*
*/
@@ -50,6 +50,15 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
private volatile boolean asMap = true;
/**
* Set false will leave the payload as the original complete syslog.
* @param asMap
*/
public void setAsMap(boolean asMap) {
this.asMap = asMap;
}
@Override
public final void setBeanFactory(BeanFactory beanFactory) {
@@ -71,7 +80,7 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa
out.put(SyslogHeaders.PREFIX + entry.getKey(), entry.getValue());
}
}
return this.messageBuilderFactory.withPayload(map)
return this.messageBuilderFactory.withPayload(this.asMap ? map : message.getPayload())
.copyHeaders(out)
.build();
}