INT-28 Return value is now the default for MessagePublishingInterceptor.

This commit is contained in:
Mark Fisher
2009-09-29 19:02:33 +00:00
parent 0e8aa07748
commit b882bcf79e
2 changed files with 28 additions and 26 deletions

View File

@@ -110,30 +110,31 @@ public class MessagePublishingInterceptor implements MethodInterceptor {
private void publishMessage(Method method, EvaluationContext context) throws Exception {
String payloadExpressionString = this.expressionSource.getPayloadExpression(method);
if (payloadExpressionString != null) {
Expression expression = this.parser.parseExpression(payloadExpressionString);
Object result = expression.getValue(context);
if (result != null) {
MessageBuilder<?> builder = (result instanceof Message<?>)
? MessageBuilder.fromMessage((Message<?>) result)
: MessageBuilder.withPayload(result);
Map<String, Object> headers = this.evaluateHeaders(method, context);
if (headers != null) {
builder.copyHeaders(headers);
}
Message<?> message = builder.build();
String channelName = this.expressionSource.getChannelName(method);
MessageChannel channel = null;
if (channelName != null) {
Assert.state(this.channelResolver != null, "ChannelResolver is required to resolve channel names.");
channel = this.channelResolver.resolveChannelName(channelName);
}
if (channel != null) {
this.channelTemplate.send(message, channel);
}
else {
this.channelTemplate.send(message);
}
if (!StringUtils.hasText(payloadExpressionString)) {
payloadExpressionString = "#" + this.expressionSource.getReturnValueName(method);
}
Expression expression = this.parser.parseExpression(payloadExpressionString);
Object result = expression.getValue(context);
if (result != null) {
MessageBuilder<?> builder = (result instanceof Message<?>)
? MessageBuilder.fromMessage((Message<?>) result)
: MessageBuilder.withPayload(result);
Map<String, Object> headers = this.evaluateHeaders(method, context);
if (headers != null) {
builder.copyHeaders(headers);
}
Message<?> message = builder.build();
String channelName = this.expressionSource.getChannelName(method);
MessageChannel channel = null;
if (channelName != null) {
Assert.state(this.channelResolver != null, "ChannelResolver is required to resolve channel names.");
channel = this.channelResolver.resolveChannelName(channelName);
}
if (channel != null) {
this.channelTemplate.send(message, channel);
}
else {
this.channelTemplate.send(message);
}
}
}

View File

@@ -35,9 +35,10 @@ public @interface Publisher {
/**
* String representation of a Spel Expression to evaluate when creating the
* Message payload. Required.
* Message payload. The default will be empty, thereby causing the return
* value to be used as the payload.
*/
String value();
String value() default "";
/**
* String representations of Spel Expressions to evaluate for adding any