diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultOutboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultOutboundChannelAdapterParser.java
index 39adc69cb1..43fc0feed4 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultOutboundChannelAdapterParser.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultOutboundChannelAdapterParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2011 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.
@@ -16,17 +16,17 @@
package org.springframework.integration.config.xml;
-import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.integration.config.ExpressionFactoryBean;
-import org.springframework.integration.handler.ExpressionEvaluatingMessageHandler;
-import org.springframework.integration.handler.MethodInvokingMessageHandler;
import org.w3c.dom.Element;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
+import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.integration.config.ExpressionFactoryBean;
+import org.springframework.integration.handler.ExpressionEvaluatingMessageHandler;
+import org.springframework.integration.handler.MethodInvokingMessageHandler;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -41,6 +41,7 @@ public class DefaultOutboundChannelAdapterParser extends AbstractOutboundChannel
protected String parseAndRegisterConsumer(Element element, ParserContext parserContext) {
BeanComponentDefinition innerConsumerDefinition = IntegrationNamespaceUtils.parseInnerHandlerDefinition(element, parserContext);
+
String consumerRef = element.getAttribute(IntegrationNamespaceUtils.REF_ATTRIBUTE);
String methodName = element.getAttribute(IntegrationNamespaceUtils.METHOD_ATTRIBUTE);
String consumerExpressionString = element.getAttribute(IntegrationNamespaceUtils.EXPRESSION_ATTRIBUTE);
@@ -57,13 +58,11 @@ public class DefaultOutboundChannelAdapterParser extends AbstractOutboundChannel
if (hasMethod & isExpression) {
parserContext.getReaderContext().error(
- "The 'method' attribute can't be used with 'expression' attribute.", element);
+ "The 'method' attribute cannot be used with the 'expression' attribute.", element);
}
-
if (hasMethod | isExpression) {
BeanDefinitionBuilder consumerBuilder = null;
-
if (hasMethod) {
consumerBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingMessageHandler.class);
if (isRef) {
@@ -82,19 +81,16 @@ public class DefaultOutboundChannelAdapterParser extends AbstractOutboundChannel
}
consumerBuilder.addPropertyValue("componentType", "outbound-channel-adapter");
-
String order = element.getAttribute(IntegrationNamespaceUtils.ORDER);
if (StringUtils.hasText(order)) {
consumerBuilder.addPropertyValue(IntegrationNamespaceUtils.ORDER, order);
}
-
consumerRef = BeanDefinitionReaderUtils.registerWithGeneratedName(consumerBuilder.getBeanDefinition(), parserContext.getRegistry());
}
else if (isInnerConsumer) {
consumerRef = innerConsumerDefinition.getBeanName();
}
-
- Assert.hasText(consumerRef, "Can not determine consumer for 'outbound-channel-adapter'");
+ Assert.hasText(consumerRef, "cannot determine consumer for 'outbound-channel-adapter'");
return consumerRef;
}
@@ -102,4 +98,5 @@ public class DefaultOutboundChannelAdapterParser extends AbstractOutboundChannel
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
throw new UnsupportedOperationException();
}
+
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionEvaluatingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionEvaluatingMessageHandler.java
index ed737be749..0a4e1422c4 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionEvaluatingMessageHandler.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ExpressionEvaluatingMessageHandler.java
@@ -1 +1 @@
-/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.handler;
import org.springframework.expression.Expression;
import org.springframework.integration.Message;
/**
* A {@link org.springframework.integration.core.MessageHandler} that evaluates provided {@link Expression}
* with void return.
*
* @author Artem Bilan
* @see MethodInvokingMessageHandler
* @since 2.1
*/
public class ExpressionEvaluatingMessageHandler extends AbstractMessageHandler {
private volatile ExpressionEvaluatingMessageProcessor processor;
private volatile String componentType;
public ExpressionEvaluatingMessageHandler(Expression expression) {
processor = new ExpressionEvaluatingMessageProcessor(expression, Void.class);
}
@Override
protected void onInit() throws Exception {
processor.setBeanFactory(getBeanFactory());
}
public void setComponentType(String componentType) {
this.componentType = componentType;
}
@Override
public String getComponentType() {
return this.componentType;
}
@Override
protected void handleMessageInternal(Message> message) throws Exception {
processor.processMessage(message);
}
}
\ No newline at end of file
+/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.handler;
import org.springframework.expression.Expression;
import org.springframework.integration.Message;
import org.springframework.util.Assert;
/**
* A {@link org.springframework.integration.core.MessageHandler} that evaluates the provided
* {@link Expression} expecting a void return.
*
* @author Artem Bilan
* @see MethodInvokingMessageHandler
* @since 2.1
*/
public class ExpressionEvaluatingMessageHandler extends AbstractMessageHandler {
private volatile ExpressionEvaluatingMessageProcessor processor;
private volatile String componentType;
public ExpressionEvaluatingMessageHandler(Expression expression) {
Assert.notNull(expression, "Expression must not be null");
this.processor = new ExpressionEvaluatingMessageProcessor(expression, Void.class);
}
public void setComponentType(String componentType) {
this.componentType = componentType;
}
@Override
public String getComponentType() {
return this.componentType;
}
@Override
protected void onInit() throws Exception {
this.processor.setBeanFactory(getBeanFactory());
}
@Override
protected void handleMessageInternal(Message> message) throws Exception {
this.processor.processMessage(message);
}
}
\ No newline at end of file
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java b/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java
index 84bcd6af66..152397f468 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java
@@ -94,20 +94,19 @@ public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware
}
public Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType) {
- // TODO maybe tentative decision... Echoes with org.springframework.expression.common.ExpressionUtils.convertTypedValue()
+ // Echoes org.springframework.expression.common.ExpressionUtils.convertTypedValue()
if ((targetType.getType() == Void.class || targetType.getType() == Void.TYPE) && value == null) {
return null;
}
if (conversionService.canConvert(sourceType, targetType)) {
return conversionService.convert(value, sourceType, targetType);
}
-
if (!String.class.isAssignableFrom(sourceType.getType())) {
PropertyEditor editor = delegate.findCustomEditor(sourceType.getType(), null);
if (editor==null) {
editor = delegate.getDefaultEditor(sourceType.getType());
}
- if (editor != null){ // INT-1441
+ if (editor != null) { // INT-1441
editor.setValue(value);
String text = editor.getAsText();
if (String.class.isAssignableFrom(targetType.getClass())) {
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java
index 6e8746fc2a..534bfd3811 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2011 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.
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
@@ -32,7 +31,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.DirectChannel;
-import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/ExpressionEvaluatingMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/ExpressionEvaluatingMessageHandlerTests.java
index 7b6b098251..4c639266df 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/message/ExpressionEvaluatingMessageHandlerTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/message/ExpressionEvaluatingMessageHandlerTests.java
@@ -1 +1 @@
-/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.message;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.handler.ExpressionEvaluatingMessageHandler;
import java.util.HashMap;
import static org.junit.Assert.assertEquals;
/**
* @author Artem Bilan
* @since 2.1
*/
public class ExpressionEvaluatingMessageHandlerTests {
private ExpressionParser parser;
@Before
public void setup() {
parser = new SpelExpressionParser();
}
@Test
public void validExpression() {
Expression expression = parser.parseExpression("T(System).out.println(payload)");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
handler.handleMessage(new GenericMessage("test"));
}
@Test
public void validExpressionWithNoArgs() {
Expression expression = parser.parseExpression("T(System).out.println()");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
handler.handleMessage(new GenericMessage("test"));
}
@Test
public void validExpressionWithSomeArgs() {
Expression expression = parser.parseExpression("T(System).out.write(payload.bytes, 0, headers.offset)");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
HashMap headers = new HashMap();
headers.put("offset", 4);
handler.handleMessage(new GenericMessage("testtest", headers));
}
@Test(expected = MessagingException.class)
public void expressionWithReturnValue() {
Message> message = new GenericMessage(.1f);
try {
Expression expression = parser.parseExpression("T(System).out.printf('$%4.2f', payload)");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
handler.handleMessage(message);
}
catch (MessagingException e) {
assertEquals(e.getFailedMessage(), message);
throw e;
}
}
}
\ No newline at end of file
+/*
* Copyright 2002-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.message;
import org.junit.Before;
import org.junit.Test;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.handler.ExpressionEvaluatingMessageHandler;
import java.util.HashMap;
import static org.junit.Assert.assertEquals;
/**
* @author Artem Bilan
* @since 2.1
*/
public class ExpressionEvaluatingMessageHandlerTests {
private ExpressionParser parser;
@Before
public void setup() {
parser = new SpelExpressionParser();
}
@Test
public void validExpression() {
Expression expression = parser.parseExpression("T(System).out.println(payload)");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
handler.handleMessage(new GenericMessage("test"));
}
@Test
public void validExpressionWithNoArgs() {
Expression expression = parser.parseExpression("T(System).out.println()");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
handler.handleMessage(new GenericMessage("test"));
}
@Test
public void validExpressionWithSomeArgs() {
Expression expression = parser.parseExpression("T(System).out.write(payload.bytes, 0, headers.offset)");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
HashMap headers = new HashMap();
headers.put("offset", 4);
handler.handleMessage(new GenericMessage("testtest", headers));
}
@Test(expected = MessagingException.class)
public void expressionWithReturnValue() {
Message> message = new GenericMessage(.1f);
try {
Expression expression = parser.parseExpression("T(System).out.printf('$%4.2f', payload)");
MessageHandler handler = new ExpressionEvaluatingMessageHandler(expression);
handler.handleMessage(message);
}
catch (MessagingException e) {
assertEquals(e.getFailedMessage(), message);
throw e;
}
}
}
\ No newline at end of file