ServiceActivatorEndpoint no longer provides a MessageHandler-accepting constructor. It does now provide a version that takes an Object and 'methodName' as well as a version that takes an Object and expects a default handler method name.

This commit is contained in:
Mark Fisher
2008-09-05 02:22:52 +00:00
parent e22bf81927
commit eb6f0848a4
4 changed files with 66 additions and 51 deletions

View File

@@ -17,9 +17,9 @@
package org.springframework.integration.endpoint;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessageMappingMethodInvoker;
import org.springframework.integration.util.MethodInvoker;
import org.springframework.util.Assert;
@@ -28,40 +28,43 @@ import org.springframework.util.Assert;
*/
public class ServiceActivatorEndpoint extends AbstractInOutEndpoint implements InitializingBean {
private final MethodInvoker invoker;
public static final String DEFAULT_LISTENER_METHOD = "handle";
private final MessageHandler handler;
private final MethodInvoker invoker;
public ServiceActivatorEndpoint(MethodInvoker invoker) {
Assert.notNull(invoker, "invoker must not be null");
this.invoker = invoker;
this.handler = null;
}
public ServiceActivatorEndpoint(MessageHandler handler) {
Assert.notNull(handler, "handler must not be null");
this.handler = handler;
this.invoker = null;
public ServiceActivatorEndpoint(Object object) {
this(object, DEFAULT_LISTENER_METHOD);
}
public ServiceActivatorEndpoint(Object object, String methodName) {
this(new MessageMappingMethodInvoker(object, methodName));
}
public void afterPropertiesSet() throws Exception {
if (this.invoker != null && (this.invoker instanceof InitializingBean)) {
if (this.invoker instanceof InitializingBean) {
((InitializingBean) this.invoker).afterPropertiesSet();
}
}
@Override
protected Object handle(Message<?> message) {
if (this.invoker != null) {
try {
return this.invoker.invokeMethod(message);
} catch (Exception e) {
throw new MessageHandlingException(message, "failure occurred in endpoint '" + this.getName() + "'", e);
}
try {
return this.invoker.invokeMethod(message);
}
catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new MessageHandlingException(message, "failure occurred in endpoint '" + this.getName() + "'", e);
}
return this.handler.handle(message);
}
}

View File

@@ -162,10 +162,16 @@ public class MessageMappingMethodInvoker implements MethodInvoker, InitializingB
return result;
}
catch (InvocationTargetException e) {
if (e.getCause() != null && e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new MessageHandlingException(message, "Handler method '"
+ this.methodName + "' threw an Exception.", e.getTargetException());
+ this.methodName + "' threw an Exception.", e.getCause());
}
catch (Throwable e) {
catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new MessageHandlingException(message, "Failed to invoke handler method '"
+ this.methodName + "' with arguments: " + ObjectUtils.nullSafeToString(args), e);
}