INT-1905 Add try/catch Block; Use Same Technique for Chain Handlers
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
@@ -42,6 +44,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Josh Long
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class ConsumerEndpointFactoryBean
|
||||
implements FactoryBean<AbstractEndpoint>, BeanFactoryAware, BeanNameAware, BeanClassLoaderAware, InitializingBean, SmartLifecycle {
|
||||
@@ -70,6 +73,7 @@ public class ConsumerEndpointFactoryBean
|
||||
|
||||
private final Object handlerMonitor = new Object();
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
public void setHandler(MessageHandler handler) {
|
||||
Assert.notNull(handler, "handler must not be null");
|
||||
@@ -109,16 +113,23 @@ public class ConsumerEndpointFactoryBean
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (!this.beanName.startsWith("org.springframework")) {
|
||||
MessageHandler targetHandler = this.handler;
|
||||
if (AopUtils.isAopProxy(targetHandler)) {
|
||||
Object target = ((Advised) targetHandler).getTargetSource().getTarget();
|
||||
if (target instanceof MessageHandler) {
|
||||
targetHandler = (MessageHandler) target;
|
||||
try {
|
||||
if (!this.beanName.startsWith("org.springframework")) {
|
||||
MessageHandler targetHandler = this.handler;
|
||||
if (AopUtils.isAopProxy(targetHandler)) {
|
||||
Object target = ((Advised) targetHandler).getTargetSource().getTarget();
|
||||
if (target instanceof MessageHandler) {
|
||||
targetHandler = (MessageHandler) target;
|
||||
}
|
||||
}
|
||||
if (targetHandler instanceof IntegrationObjectSupport) {
|
||||
((IntegrationObjectSupport) targetHandler).setComponentName(this.beanName);
|
||||
}
|
||||
}
|
||||
if (targetHandler instanceof IntegrationObjectSupport) {
|
||||
((IntegrationObjectSupport) targetHandler).setComponentName(this.beanName);
|
||||
} catch (Exception e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not set component name for handler "
|
||||
+ this.handler + " for " + this.beanName + " :" + e.getMessage());
|
||||
}
|
||||
}
|
||||
this.initializeEndpoint();
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.integration.handler;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.Message;
|
||||
@@ -173,8 +175,22 @@ public class MessageHandlerChain extends AbstractMessageHandler implements Messa
|
||||
int i = 0;
|
||||
if (this.handlers != null) {
|
||||
for (MessageHandler messageHandler : this.handlers) {
|
||||
if (messageHandler instanceof IntegrationObjectSupport) {
|
||||
((IntegrationObjectSupport) messageHandler).setComponentName(componentName + ".handler#" + i);
|
||||
try {
|
||||
MessageHandler targetHandler = messageHandler;
|
||||
if (AopUtils.isAopProxy(targetHandler)) {
|
||||
Object target = ((Advised) targetHandler).getTargetSource().getTarget();
|
||||
if (target instanceof MessageHandler) {
|
||||
targetHandler = (MessageHandler) target;
|
||||
}
|
||||
}
|
||||
if (targetHandler instanceof IntegrationObjectSupport) {
|
||||
((IntegrationObjectSupport) targetHandler).setComponentName(componentName + ".handler#" + i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not set component name for handler "
|
||||
+ messageHandler + " for " + componentName + " :" + e.getMessage());
|
||||
}
|
||||
}
|
||||
i++; // increment, regardless of whether we assigned a component name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user