INT-2900 Remove Extraneous Debug Log

When referencing a <gateway/> from a <service-activator/>, a debug
log is written with a full stack trace.

This is because all methods on the proxy are considered candidates,
but one method (addAdvice) has multiple parameters and can't be
used to process a message.

Add code to detect a proxy that has no target object; if the Proxy
only has one interface, then use that as the targetClass.
This commit is contained in:
Gary Russell
2013-01-24 13:55:49 -05:00
committed by Mark Fisher
parent d765add255
commit 5edebb303e
2 changed files with 46 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicReference;
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.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
@@ -74,6 +74,7 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
* @author Gunnar Hillert
* @author Soby Chacko
* @author Gary Russell
*
* @since 2.0
*/
@@ -133,6 +134,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
return processInternal(parameters);
}
@Override
public String toString() {
return this.displayString;
}
@@ -361,6 +363,20 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
Class<?> targetClass = targetObject.getClass();
if (AopUtils.isAopProxy(targetObject)) {
targetClass = AopUtils.getTargetClass(targetObject);
if (targetClass == targetObject.getClass()) {
try {
// Maybe a proxy with no target - e.g. gateway
Class<?>[] interfaces = ((Advised) targetObject).getProxiedInterfaces();
if (interfaces != null && interfaces.length == 1) {
targetClass = interfaces[0];
}
}
catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Exception trying to extract interface", e);
}
}
}
}
else if (org.springframework.util.ClassUtils.isCglibProxyClass(targetClass)) {
Class<?> superClass = targetObject.getClass().getSuperclass();
@@ -449,6 +465,7 @@ public class MessagingMethodInvokerHelper<T> extends AbstractExpressionEvaluator
return this.targetParameterType;
}
@Override
public String toString() {
return this.method.toString();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -16,6 +16,11 @@
package org.springframework.integration.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Properties;
@@ -27,23 +32,22 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.junit.rules.ExpectedException;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
import org.springframework.integration.gateway.RequestReplyExchanger;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.springframework.integration.util.MessagingMethodInvokerHelper;
/**
* @author Mark Fisher
* @author Marius Bogoevici
* @author Oleg Zhurakousky
* @author Dave Syer
* @author Gary Russell
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class MethodInvokingMessageProcessorTests {
@@ -84,6 +88,7 @@ public class MethodInvokingMessageProcessorTests {
}
class B extends A {
@Override
public Message<String> myMethod(Message<String> msg) {
return MessageBuilder.fromMessage(msg).setHeader("B", "B").build();
}
@@ -107,12 +112,14 @@ public class MethodInvokingMessageProcessorTests {
}
class B extends A {
@Override
public Message<String> myMethod(Message<String> msg) {
return MessageBuilder.fromMessage(msg).setHeader("B", "B").build();
}
}
class C extends B {
@Override
public Message<String> myMethod(Message<String> msg) {
return MessageBuilder.fromMessage(msg).setHeader("C", "C").build();
}
@@ -135,6 +142,7 @@ public class MethodInvokingMessageProcessorTests {
}
class C extends B {
@Override
public Message<String> myMethod(Message<String> msg) {
return MessageBuilder.fromMessage(msg).setHeader("C", "C").build();
}
@@ -322,6 +330,20 @@ public class MethodInvokingMessageProcessorTests {
assertEquals("true", bean.lastArg);
}
@Test
public void gatewayTest() throws Exception {
GatewayProxyFactoryBean gwFactoryBean = new GatewayProxyFactoryBean();
gwFactoryBean.afterPropertiesSet();
Object target = gwFactoryBean.getObject();
// just instantiate a helper with a simple target; we're going to invoke getTargetClass with reflection
MessagingMethodInvokerHelper helper = new MessagingMethodInvokerHelper(new TestErrorService(), "error", true);
Method method = MessagingMethodInvokerHelper.class.getDeclaredMethod("getTargetClass", Object.class);
method.setAccessible(true);
Object result = method.invoke(helper, target);
assertSame(RequestReplyExchanger.class, result);
}
private static class ExceptionCauseMatcher extends TypeSafeMatcher<Exception> {
private Throwable cause;