Removed MessageHandlerCreator, AbstractMessageHandlerCreator, and DefaultMessageHandlerCreator. Annotation post-processing no longer requires creation of a MessageHandler.
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
|
||||
/**
|
||||
* Base class for handler creators that generate a {@link MessageHandler}
|
||||
* adapter for the provided object and method.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractMessageHandlerCreator implements MessageHandlerCreator {
|
||||
|
||||
public final MessageHandler createHandler(Object object, Method method, Map<String, ?> attributes) {
|
||||
MessageHandler handler = this.doCreateHandler(object, method, attributes);
|
||||
if (attributes != null && handler instanceof AbstractMessageHandler) {
|
||||
Object order = attributes.get("order");
|
||||
if (order != null && order instanceof Integer) {
|
||||
((AbstractMessageHandler) handler).setOrder(((Integer) order).intValue());
|
||||
}
|
||||
}
|
||||
if (handler instanceof InitializingBean) {
|
||||
try {
|
||||
((InitializingBean) handler).afterPropertiesSet();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ConfigurationException("failed to initialize handler", e);
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
protected abstract MessageHandler doCreateHandler(Object object, Method method, Map<String, ?> attributes);
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.handler.DefaultMessageHandler;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
|
||||
/**
|
||||
* Default implementation of the handler creator strategy that creates a
|
||||
* {@link DefaultMessageHandler} for the provided object and method.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultMessageHandlerCreator extends AbstractMessageHandlerCreator {
|
||||
|
||||
public MessageHandler doCreateHandler(Object object, Method method, Map<String, ?> attributes) {
|
||||
DefaultMessageHandler handler = new DefaultMessageHandler();
|
||||
handler.setObject(object);
|
||||
handler.setMethod(method);
|
||||
handler.afterPropertiesSet();
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
|
||||
/**
|
||||
* Strategy interface for creating {@link MessageHandler MessageHandlers}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface MessageHandlerCreator {
|
||||
|
||||
MessageHandler createHandler(Object object, Method method, Map<String, ?> attributes);
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultMessageHandlerCreatorTests {
|
||||
|
||||
@Test
|
||||
public void testPayloadAsMethodParameterAndObjectAsReturnValue() throws Exception {
|
||||
DefaultMessageHandlerCreator creator = new DefaultMessageHandlerCreator();
|
||||
MessageHandler handler = creator.createHandler(new TestHandler(),
|
||||
TestHandler.class.getMethod("acceptPayloadAndReturnObject", String.class), null);
|
||||
Message<?> result = handler.handle(new StringMessage("testing"));
|
||||
assertEquals("testing-1", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadAsMethodParameterAndMessageAsReturnValue() throws Exception {
|
||||
DefaultMessageHandlerCreator creator = new DefaultMessageHandlerCreator();
|
||||
MessageHandler handler = creator.createHandler(new TestHandler(),
|
||||
TestHandler.class.getMethod("acceptPayloadAndReturnMessage", String.class), null);
|
||||
Message<?> result = handler.handle(new StringMessage("testing"));
|
||||
assertEquals("testing-2", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageAsMethodParameterAndObjectAsReturnValue() throws Exception {
|
||||
DefaultMessageHandlerCreator creator = new DefaultMessageHandlerCreator();
|
||||
MessageHandler handler = creator.createHandler(new TestHandler(),
|
||||
TestHandler.class.getMethod("acceptMessageAndReturnObject", Message.class), null);
|
||||
Message<?> result = handler.handle(new StringMessage("testing"));
|
||||
assertEquals("testing-3", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageAsMethodParameterAndMessageAsReturnValue() throws Exception {
|
||||
DefaultMessageHandlerCreator creator = new DefaultMessageHandlerCreator();
|
||||
MessageHandler handler = creator.createHandler(new TestHandler(),
|
||||
TestHandler.class.getMethod("acceptMessageAndReturnMessage", Message.class), null);
|
||||
Message<?> result = handler.handle(new StringMessage("testing"));
|
||||
assertEquals("testing-4", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSubclassAsMethodParameterAndMessageAsReturnValue() throws Exception {
|
||||
DefaultMessageHandlerCreator creator = new DefaultMessageHandlerCreator();
|
||||
MessageHandler handler = creator.createHandler(new TestHandler(),
|
||||
TestHandler.class.getMethod("acceptMessageSubclassAndReturnMessage", StringMessage.class), null);
|
||||
Message<?> result = handler.handle(new StringMessage("testing"));
|
||||
assertEquals("testing-5", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSubclassAsMethodParameterAndMessageSubclassAsReturnValue() throws Exception {
|
||||
DefaultMessageHandlerCreator creator = new DefaultMessageHandlerCreator();
|
||||
MessageHandler handler = creator.createHandler(new TestHandler(),
|
||||
TestHandler.class.getMethod("acceptMessageSubclassAndReturnMessageSubclass", StringMessage.class), null);
|
||||
Message<?> result = handler.handle(new StringMessage("testing"));
|
||||
assertEquals("testing-6", result.getPayload());
|
||||
}
|
||||
|
||||
|
||||
private static class TestHandler {
|
||||
|
||||
public String acceptPayloadAndReturnObject(String s) {
|
||||
return s + "-1";
|
||||
}
|
||||
|
||||
public Message<?> acceptPayloadAndReturnMessage(String s) {
|
||||
return new StringMessage(s + "-2");
|
||||
}
|
||||
|
||||
public String acceptMessageAndReturnObject(Message<?> m) {
|
||||
return m.getPayload() + "-3";
|
||||
}
|
||||
|
||||
public Message<?> acceptMessageAndReturnMessage(Message<?> m) {
|
||||
return new StringMessage(m.getPayload() + "-4");
|
||||
}
|
||||
|
||||
public Message<?> acceptMessageSubclassAndReturnMessage(StringMessage m) {
|
||||
return new StringMessage(m.getPayload() + "-5");
|
||||
}
|
||||
|
||||
public StringMessage acceptMessageSubclassAndReturnMessageSubclass(StringMessage m) {
|
||||
return new StringMessage(m.getPayload() + "-6");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user