MessageHandlingException and MessageDeliveryException now require the failed/undelivered Message as a constructor argument.

This commit is contained in:
Mark Fisher
2008-04-09 00:18:56 +00:00
parent f6756da3c8
commit fec6dec258
153 changed files with 458 additions and 476 deletions

View File

@@ -50,7 +50,7 @@ public abstract class AbstractRemotingTargetAdapter implements MessageHandler {
return this.handlerProxy.handle(message);
}
catch (RemoteAccessException e) {
throw new MessageHandlingException("unable to handle message remotely", e);
throw new MessageHandlingException(message, "unable to handle message remotely", e);
}
}

View File

@@ -20,7 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.RequestReplyTemplate;
import org.springframework.integration.handler.MessageHandler;
@@ -100,7 +100,7 @@ public class MessageHandlingSourceAdapter implements SourceAdapter, MessageHandl
public final void afterPropertiesSet() throws Exception {
if (this.channel == null) {
throw new MessagingConfigurationException("The 'channel' property of '" + this.getClass().getName()
throw new ConfigurationException("The 'channel' property of '" + this.getClass().getName()
+ "' must not be null.");
}
synchronized (this.lifecycleMonitor) {
@@ -134,7 +134,7 @@ public class MessageHandlingSourceAdapter implements SourceAdapter, MessageHandl
this.afterPropertiesSet();
}
catch (Exception e) {
throw new MessagingConfigurationException("unable to initialize " + this.getClass().getName(), e);
throw new ConfigurationException("unable to initialize " + this.getClass().getName(), e);
}
}
if (!this.expectReply) {

View File

@@ -31,8 +31,8 @@ public class MessageMappingException extends MessageHandlingException {
super(failedMessage, description);
}
public MessageMappingException(String description, Throwable cause) {
super(description, cause);
public MessageMappingException(Message<?> failedMessage, String description, Throwable cause) {
super(failedMessage, description, cause);
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.util.StringUtils;
/**
@@ -57,7 +57,7 @@ public abstract class AbstractRequestReplySourceAdapterParser extends AbstractSi
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
String channelRef = element.getAttribute("channel");
if (!StringUtils.hasText(channelRef)) {
throw new MessagingConfigurationException("a 'channel' reference is required");
throw new ConfigurationException("a 'channel' reference is required");
}
builder.addPropertyReference("channel", channelRef);
builder.addPropertyValue("expectReply", element.getAttribute("expect-reply").equals("true"));

View File

@@ -27,6 +27,7 @@ import org.springframework.integration.message.AbstractMessageMapper;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
import org.springframework.util.FileCopyUtils;
@@ -66,7 +67,7 @@ public abstract class AbstractFileMapper<T> extends AbstractMessageMapper<T, Fil
return file;
}
catch (Exception e) {
throw new MessageHandlingException("failure occurred mapping file to message", e);
throw new MessageHandlingException(message, "failure occurred mapping file to message", e);
}
}
@@ -86,11 +87,11 @@ public abstract class AbstractFileMapper<T> extends AbstractMessageMapper<T, Fil
return message;
}
catch (Exception e) {
String errorMessage = "failure occurred mapping file to message";
String description = "failure occurred mapping file to message";
if (logger.isWarnEnabled()) {
logger.warn(errorMessage, e);
logger.warn(description, e);
}
throw new MessageHandlingException(errorMessage, e);
throw new MessagingException(description, e);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -24,7 +24,7 @@ import java.util.Collection;
import java.util.List;
import org.springframework.integration.adapter.PollableSource;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
/**
@@ -66,7 +66,7 @@ public class FileSource implements PollableSource<File> {
files = this.directory.listFiles();
}
if (files == null) {
throw new MessageHandlingException("Problem occurred while polling for files. " +
throw new MessagingException("Problem occurred while polling for files. " +
"Is '" + directory.getAbsolutePath() + "' a directory?");
}
List<File> results = new ArrayList<File>();

View File

@@ -33,7 +33,7 @@ import org.springframework.integration.adapter.PollableSource;
import org.springframework.integration.adapter.PollingSourceAdapter;
import org.springframework.integration.adapter.file.ByteArrayFileMapper;
import org.springframework.integration.adapter.file.TextFileMapper;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -129,10 +129,10 @@ public class FtpSourceAdapter extends PollingSourceAdapter<File> implements Poll
LinkedList<File> localFileList = new LinkedList<File>();
this.client.connect(this.host, this.port);
if (!StringUtils.hasText(this.username)) {
throw new MessageHandlingException("username is required");
throw new MessagingException("username is required");
}
if (!this.client.login(this.username, this.password)) {
throw new MessageHandlingException("Login failed. Please check the username and password.");
throw new MessagingException("Login failed. Please check the username and password.");
}
if (logger.isDebugEnabled()) {
logger.debug("login successful");
@@ -140,7 +140,7 @@ public class FtpSourceAdapter extends PollingSourceAdapter<File> implements Poll
this.client.setFileType(FTP.IMAGE_FILE_TYPE);
if (!this.remoteWorkingDirectory.equals(this.client.printWorkingDirectory())
&& !this.client.changeWorkingDirectory(this.remoteWorkingDirectory)) {
throw new MessageHandlingException("Could not change directory to '" +
throw new MessagingException("Could not change directory to '" +
remoteWorkingDirectory + "'. Please check the path.");
}
if (logger.isDebugEnabled()) {
@@ -176,9 +176,9 @@ public class FtpSourceAdapter extends PollingSourceAdapter<File> implements Poll
}
}
catch (IOException ioe) {
throw new MessageHandlingException("Error when disconnecting from ftp.", ioe);
throw new MessagingException("Error when disconnecting from ftp.", ioe);
}
throw new MessageHandlingException("Error while polling for messages.", e);
throw new MessagingException("Error while polling for messages.", e);
}
}

View File

@@ -25,7 +25,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.integration.adapter.MessageHandlingSourceAdapter;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.web.HttpRequestHandler;
@@ -85,7 +85,7 @@ public class HttpInvokerSourceAdapter extends MessageHandlingSourceAdapter imple
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (this.exporter == null) {
throw new MessageHandlingException("adapter has not been initialized");
throw new MessagingException("adapter has not been initialized");
}
this.exporter.handleRequest(request, response);
}

View File

@@ -23,7 +23,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
import org.springframework.integration.scheduling.Subscription;
@@ -53,10 +53,10 @@ public class HttpInvokerTargetAdapterParser extends AbstractSingleBeanDefinition
String channel = element.getAttribute("channel");
String url = element.getAttribute("url");
if (!StringUtils.hasText(channel)) {
throw new MessagingConfigurationException("The 'channel' attribute is required.");
throw new ConfigurationException("The 'channel' attribute is required.");
}
if (!StringUtils.hasText(url)) {
throw new MessagingConfigurationException("The 'url' attribute is required.");
throw new ConfigurationException("The 'url' attribute is required.");
}
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(url);
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);

View File

@@ -20,7 +20,7 @@ import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.MessageHeaderMapper;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.converter.MessageConverter;
@@ -105,7 +105,7 @@ public abstract class AbstractJmsTemplateBasedAdapter implements InitializingBea
}
if (this.jmsTemplate == null) {
if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) {
throw new MessagingConfigurationException("Either a 'jmsTemplate' or " +
throw new ConfigurationException("Either a 'jmsTemplate' or " +
"*both* 'connectionFactory' and 'destination' (or 'destination-name') are required.");
}
this.jmsTemplate = this.createDefaultJmsTemplate();

View File

@@ -18,10 +18,10 @@ package org.springframework.integration.adapter.jms;
import javax.jms.MessageListener;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessagingException;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.util.Assert;
@@ -54,7 +54,7 @@ public class ChannelPublishingJmsListener implements MessageListener {
public void onMessage(javax.jms.Message jmsMessage) {
if (this.channel == null) {
throw new MessagingConfigurationException("'channel' must not be null");
throw new ConfigurationException("'channel' must not be null");
}
try {
Message<?> messageToSend = (Message<?>) this.converter.fromMessage(jmsMessage);
@@ -66,7 +66,7 @@ public class ChannelPublishingJmsListener implements MessageListener {
}
}
catch (Exception e) {
throw new MessageDeliveryException("failed to convert JMS Message", e);
throw new MessagingException("failed to convert and send JMS Message", e);
}
}

View File

@@ -25,8 +25,8 @@ import javax.jms.Destination;
import javax.jms.JMSException;
import org.springframework.integration.adapter.MessageHeaderMapper;
import org.springframework.integration.adapter.MessageMappingException;
import org.springframework.integration.message.MessageHeader;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.StringUtils;
/**
@@ -69,7 +69,7 @@ public class DefaultJmsHeaderMapper implements MessageHeaderMapper<javax.jms.Mes
}
}
catch (JMSException e) {
throw new MessageMappingException("failed to map from MessageHeader", e);
throw new MessagingException("failed to map from MessageHeader", e);
}
}
@@ -97,7 +97,7 @@ public class DefaultJmsHeaderMapper implements MessageHeaderMapper<javax.jms.Mes
}
}
catch (JMSException e) {
throw new MessageMappingException("failed to map to MessageHeader", e);
throw new MessagingException("failed to map to MessageHeader", e);
}
}

View File

@@ -22,7 +22,7 @@ import javax.jms.Session;
import org.springframework.integration.adapter.MessageHeaderMapper;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.SimpleMessageConverter;
@@ -59,7 +59,7 @@ public class HeaderMappingMessageConverter implements MessageConverter {
public javax.jms.Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
if (!(object instanceof Message<?>)) {
throw new MessageHandlingException("expected a '" + Message.class.getName() +
throw new MessagingException("expected a '" + Message.class.getName() +
"', but received '" + object.getClass() + "'");
}
Message<?> message = (Message<?>) object;

View File

@@ -23,7 +23,7 @@ import javax.jms.Session;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.Lifecycle;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.AbstractSourceAdapter;
import org.springframework.jms.listener.AbstractJmsListeningContainer;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
@@ -113,7 +113,7 @@ public class JmsMessageDrivenSourceAdapter extends AbstractSourceAdapter<Object>
private void initDefaultContainer() {
if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) {
throw new MessagingConfigurationException("If a 'container' reference is not provided, then "
throw new ConfigurationException("If a 'container' reference is not provided, then "
+ "'connectionFactory' and 'destination' (or 'destinationName') are required.");
}
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -20,9 +20,9 @@ import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.integration.adapter.MessageMappingException;
import org.springframework.integration.message.AbstractMessageMapper;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.mail.MailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMailMessage;
@@ -71,7 +71,7 @@ public class ByteArrayMailMessageMapper extends AbstractMessageMapper<byte[], Ma
return new MimeMailMessage(helper);
}
catch (MessagingException e) {
throw new MessageHandlingException("failed to create MimeMessage", e);
throw new MessageMappingException(message, "failed to create MimeMessage", e);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -24,7 +24,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.mail.MailTargetAdapter;
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
import org.springframework.integration.scheduling.Subscription;
@@ -59,7 +59,7 @@ public class MailTargetAdapterParser extends AbstractSingleBeanDefinitionParser
String headerGeneratorRef = element.getAttribute("header-generator");
if (StringUtils.hasText(mailSenderRef)) {
if (StringUtils.hasText(host) || StringUtils.hasText(username) || StringUtils.hasText(password)) {
throw new MessagingConfigurationException("The 'host', 'username', and 'password' properties " +
throw new ConfigurationException("The 'host', 'username', and 'password' properties " +
"should not be provided when using a 'mail-sender' reference.");
}
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(mailSenderRef));
@@ -76,7 +76,7 @@ public class MailTargetAdapterParser extends AbstractSingleBeanDefinitionParser
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(mailSender);
}
else {
throw new MessagingConfigurationException("Either a 'mail-sender' reference or 'host' property is required.");
throw new ConfigurationException("Either a 'mail-sender' reference or 'host' property is required.");
}
if (StringUtils.hasText(headerGeneratorRef)) {
adapterDef.getPropertyValues().addPropertyValue(

View File

@@ -19,7 +19,7 @@ package org.springframework.integration.adapter.rmi;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.MessageHandlingSourceAdapter;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.handler.MessageHandler;
@@ -68,7 +68,7 @@ public class RmiSourceAdapter extends MessageHandlingSourceAdapter {
public void initialize() throws RemoteException {
String channelName = this.getChannel().getName();
if (channelName == null) {
throw new MessagingConfigurationException("RmiSourceAdapter's MessageChannel must have a 'name'");
throw new ConfigurationException("RmiSourceAdapter's MessageChannel must have a 'name'");
}
RmiServiceExporter exporter = new RmiServiceExporter();
if (this.registryHost != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -23,7 +23,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.rmi.RmiSourceAdapter;
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
@@ -55,7 +55,7 @@ public class RmiTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
String localChannel = element.getAttribute("local-channel");
String remoteChannel = element.getAttribute("remote-channel");
if (!(StringUtils.hasText(host) && StringUtils.hasText(localChannel) && StringUtils.hasText(remoteChannel))) {
throw new MessagingConfigurationException(
throw new ConfigurationException(
"The 'host', 'local-channel', and 'remote-channel' attributes are all required");
}
String portAttribute = element.getAttribute("port");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -24,7 +24,7 @@ import java.util.Collection;
import java.util.List;
import org.springframework.integration.adapter.PollableSource;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessagingException;
/**
* A pollable source for receiving bytes from an {@link InputStream}.
@@ -94,7 +94,7 @@ public class ByteStreamSource implements PollableSource<byte[]> {
}
}
catch (IOException e) {
throw new MessageDeliveryException("IO failure occurred in adapter", e);
throw new MessagingException("IO failure occurred in adapter", e);
}
}
return results;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -21,7 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import org.springframework.integration.adapter.AbstractTargetAdapter;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
/**
* A target adapter that writes a byte array to an {@link OutputStream}.
@@ -63,14 +63,14 @@ public class ByteStreamTargetAdapter extends AbstractTargetAdapter {
this.stream.write((byte[]) object);
}
else {
throw new MessageHandlingException(this.getClass().getSimpleName() +
throw new MessagingException(this.getClass().getSimpleName() +
" only supports byte array and String-based messages");
}
this.stream.flush();
return true;
}
catch (IOException e) {
throw new MessageHandlingException("IO failure occurred in adapter", e);
throw new MessagingException("IO failure occurred in adapter", e);
}
}

View File

@@ -24,7 +24,7 @@ import java.util.Collection;
import java.util.List;
import org.springframework.integration.adapter.PollableSource;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
/**
@@ -76,7 +76,7 @@ public class CharacterStreamSource implements PollableSource<String> {
results.add(line);
}
catch (IOException e) {
throw new MessageDeliveryException("IO failure occurred in adapter", e);
throw new MessagingException("IO failure occurred in adapter", e);
}
}
return results;

View File

@@ -23,9 +23,9 @@ import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.AbstractTargetAdapter;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
import org.springframework.util.Assert;
/**
@@ -103,7 +103,7 @@ public class CharacterStreamTargetAdapter extends AbstractTargetAdapter {
return new CharacterStreamTargetAdapter(new OutputStreamWriter(stream, charsetName));
}
catch (UnsupportedEncodingException e) {
throw new MessagingConfigurationException("unsupported encoding: " + charsetName, e);
throw new ConfigurationException("unsupported encoding: " + charsetName, e);
}
}
@@ -140,7 +140,7 @@ public class CharacterStreamTargetAdapter extends AbstractTargetAdapter {
return true;
}
catch (IOException e) {
throw new MessageHandlingException("IO failure occurred in adapter", e);
throw new MessagingException("IO failure occurred in adapter", e);
}
}