InboundMessageMapper and OutboundMessageMapper strategy methods can now throw any Exception.
This commit is contained in:
@@ -135,7 +135,15 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint implemen
|
||||
Assert.state(this.replyChannel != null && (this.replyChannel instanceof PollableChannel),
|
||||
"receive is not supported, because no pollable reply channel has been configured");
|
||||
Message<?> message = this.channelTemplate.receive((PollableChannel) this.replyChannel);
|
||||
return this.fromMessage(message);
|
||||
try {
|
||||
return this.fromMessage(message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
else throw new MessagingException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object sendAndReceive(Object object) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.gateway;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.InboundMessageMapper;
|
||||
import org.springframework.integration.message.OutboundMessageMapper;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -55,12 +56,28 @@ public class SimpleMessagingGateway extends AbstractMessagingGateway {
|
||||
|
||||
@Override
|
||||
protected Object fromMessage(Message<?> message) {
|
||||
return this.outboundMapper.fromMessage(message);
|
||||
try {
|
||||
return this.outboundMapper.fromMessage(message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
throw new MessagingException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Message<?> toMessage(Object object) {
|
||||
return this.inboundMapper.toMessage(object);
|
||||
try {
|
||||
return this.inboundMapper.toMessage(object);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
throw new MessagingException("failed to create Message", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,8 +100,9 @@ public class MessageMappingMethodInvoker {
|
||||
return null;
|
||||
}
|
||||
Method method = this.methodResolver.resolveHandlerMethod(message);
|
||||
Object[] args = this.createArgumentArrayFromMessage(method, message);
|
||||
Object[] args = null;
|
||||
try {
|
||||
args = this.createArgumentArrayFromMessage(method, message);
|
||||
return this.doInvokeMethod(method, args, message);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
@@ -146,7 +147,7 @@ public class MessageMappingMethodInvoker {
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object[] createArgumentArrayFromMessage(Method method, Message<?> message) {
|
||||
private Object[] createArgumentArrayFromMessage(Method method, Message<?> message) throws Exception {
|
||||
Object args[] = null;
|
||||
Object mappingResult = this.methodsExpectingMessage.contains(method)
|
||||
? message : this.resolveParameters(method, message);
|
||||
@@ -160,7 +161,7 @@ public class MessageMappingMethodInvoker {
|
||||
return args;
|
||||
}
|
||||
|
||||
private Object[] resolveParameters(Method method, Message<?> message) {
|
||||
private Object[] resolveParameters(Method method, Message<?> message) throws Exception {
|
||||
OutboundMessageMapper<Object[]> mapper = this.messageMappers.get(method);
|
||||
if (mapper == null) {
|
||||
mapper = new MethodParameterMessageMapper(method);
|
||||
|
||||
@@ -25,6 +25,6 @@ import org.springframework.integration.core.Message;
|
||||
*/
|
||||
public interface InboundMessageMapper<T> {
|
||||
|
||||
Message<?> toMessage(T object);
|
||||
Message<?> toMessage(T object) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@ import org.springframework.integration.core.Message;
|
||||
*/
|
||||
public interface OutboundMessageMapper<T> {
|
||||
|
||||
T fromMessage(Message<?> message);
|
||||
T fromMessage(Message<?> message) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user