INT-1829 added support for MessageHistory to outbound-channel-adapter
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beansProjectDescription>
|
||||
<version>1</version>
|
||||
<pluginVersion><![CDATA[2.5.2.201101121000-SR1]]></pluginVersion>
|
||||
<pluginVersion><![CDATA[2.6.0.201102250324-M2]]></pluginVersion>
|
||||
<configSuffixes>
|
||||
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||
</configSuffixes>
|
||||
@@ -9,6 +9,7 @@
|
||||
<configs>
|
||||
<config>src/test/java/org/springframework/integration/gateway/GatewayInterfaceTest-context.xml</config>
|
||||
<config>src/test/java/org/springframework/integration/gateway/InnerGatewayWithChainTests-context.xml</config>
|
||||
<config>src/test/java/org/springframework/integration/history/annotated-config.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
</configSets>
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.integration.endpoint;
|
||||
|
||||
import org.springframework.integration.channel.AbstractSubscribableChannel;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.integration.handler;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
@@ -28,37 +27,32 @@ import org.springframework.util.Assert;
|
||||
* A {@link MessageHandler} that invokes the specified method on the provided object.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class MethodInvokingMessageHandler extends MethodInvokingMessageProcessor<Object> implements MessageHandler, Ordered {
|
||||
|
||||
private volatile int order = Ordered.LOWEST_PRECEDENCE;
|
||||
public class MethodInvokingMessageHandler extends AbstractMessageHandler {
|
||||
|
||||
private volatile MethodInvokingMessageProcessor<Object> processor;
|
||||
|
||||
public MethodInvokingMessageHandler(Object object, Method method) {
|
||||
super(object, method);
|
||||
Assert.isTrue(method.getReturnType().equals(void.class),
|
||||
"MethodInvokingMessageHandler requires a void-returning method");
|
||||
processor = new MethodInvokingMessageProcessor<Object>(object, method);
|
||||
}
|
||||
|
||||
public MethodInvokingMessageHandler(Object object, String methodName) {
|
||||
super(object, methodName);
|
||||
processor = new MethodInvokingMessageProcessor<Object>(object, methodName);
|
||||
}
|
||||
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void handleMessage(Message<?> message) {
|
||||
Object result = this.processMessage(message);
|
||||
@Override
|
||||
protected void handleMessageInternal(Message<?> message) throws Exception {
|
||||
Object result = processor.processMessage(message);
|
||||
if (result != null) {
|
||||
throw new MessagingException(message, "the MethodInvokingMessageHandler method must "
|
||||
+ "have a void return, but '" + this + "' received a value: [" + result + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getComponentType() {
|
||||
return "outbound-channel-adapter";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.history;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@MessageEndpoint(value = "outputAdapter")
|
||||
public class AnnotatedAdapter implements ApplicationContextAware{
|
||||
private volatile ApplicationContext applicationContext;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public void handle(Message<?> message) {
|
||||
System.out.println("Message: " + message);
|
||||
applicationContext.publishEvent(new ApplicationEvent(message) {});
|
||||
}
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.history;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class AnotatedTests {
|
||||
|
||||
@Test
|
||||
public void testHistoryWithAnnotatedComponents() throws Exception{
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("annotated-config.xml", this.getClass());
|
||||
ApplicationListener<ApplicationEvent> listener = new ApplicationListener<ApplicationEvent>() {
|
||||
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
MessageHistory history = MessageHistory.read((Message<?>) event.getSource());
|
||||
Properties adapterHistory = history.get(1);
|
||||
assertEquals("myAdapter", adapterHistory.get("name"));
|
||||
assertEquals("outbound-channel-adapter", adapterHistory.get("type"));
|
||||
}
|
||||
};
|
||||
listener = spy(listener);
|
||||
ac.addApplicationListener(listener);
|
||||
|
||||
MessageChannel channel = ac.getBean("inputChannel", MessageChannel.class);
|
||||
EventDrivenConsumer consumer = ac.getBean("myAdapter", EventDrivenConsumer.class);
|
||||
MessageHandler handler = (MessageHandler) TestUtils.getPropertyValue(consumer, "handler");
|
||||
Field handlerField = consumer.getClass().getDeclaredField("handler");
|
||||
handlerField.setAccessible(true);
|
||||
handlerField.set(consumer, handler);
|
||||
channel.send(new GenericMessage<String>("hello"));
|
||||
verify(listener, times(1)).onApplicationEvent((ApplicationEvent) Mockito.any());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
|
||||
<context:component-scan base-package="org.springframework.integration.history"/>
|
||||
<int:message-history/>
|
||||
|
||||
<int:channel id="inputChannel"/>
|
||||
<int:outbound-channel-adapter id="myAdapter" channel="inputChannel" ref="outputAdapter" method="handle" />
|
||||
|
||||
<!-- <bean id="outputAdapter" class="org.springframework.integration.history.AnnotatedAdapter"/> -->
|
||||
</beans>
|
||||
Reference in New Issue
Block a user