You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2008/02/09 04:03:57 UTC
svn commit: r620074 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/component/bean/BeanProcessor.java
test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
Author: hadrian
Date: Fri Feb 8 19:03:56 2008
New Revision: 620074
URL: http://svn.apache.org/viewvc?rev=620074&view=rev
Log:
CAMEL-279. Do not silently override METHOD_NAME.
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=620074&r1=620073&r2=620074&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java Fri Feb 8 19:03:56 2008
@@ -90,18 +90,24 @@
return;
}
+ boolean isExplicitMethod = false;
+ String prevMethod = null;
MethodInvocation invocation;
if (methodObject != null) {
invocation = beanInfo.createInvocation(methodObject, bean, exchange);
} else {
// we just override the bean's invocation method name here
if (ObjectHelper.isNotNullAndNonEmpty(method)) {
+ prevMethod = in.getHeader(METHOD_NAME, String.class);
in.setHeader(METHOD_NAME, method);
+ isExplicitMethod = true;
}
invocation = beanInfo.createInvocation(bean, exchange);
}
if (invocation == null) {
- throw new IllegalStateException("No method invocation could be created, no maching method could be found on: " + bean);
+ throw new IllegalStateException(
+ "No method invocation could be created, " +
+ "no maching method could be found on: " + bean);
}
try {
Object value = invocation.proceed();
@@ -110,18 +116,21 @@
}
} catch (InvocationTargetException e) {
// lets unwrap the exception
- Throwable cause = e.getTargetException();
+ Throwable cause = e.getCause();
if (cause instanceof Exception) {
throw (Exception) cause;
- }
- else {
- // TODO deal with errors!
+ } else {
+ // do not handle errors!
throw e;
}
} catch (Exception e) {
throw e;
} catch (Throwable throwable) {
throw new Exception(throwable);
+ } finally {
+ if (isExplicitMethod) {
+ in.setHeader(METHOD_NAME, prevMethod);
+ }
}
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java?rev=620074&r1=620073&r2=620074&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java Fri Feb 8 19:03:56 2008
@@ -20,7 +20,6 @@
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.util.jndi.JndiContext;
@@ -31,7 +30,7 @@
@Override
protected void setUp() throws Exception {
- beanMock = EasyMock.createMock(MyBean.class);
+ beanMock = EasyMock.createStrictMock(MyBean.class);
super.setUp();
}
@@ -48,17 +47,24 @@
@Override
public void configure() throws Exception {
from("direct:start")
- .to("bean:myBean?methodName=b")
- .bean(beanMock, "a")
+ .to("bean:myBean?methodName=a")
+ .bean(beanMock, "b")
.beanRef("myBean", "c");
+ from("direct:start2")
+ .to("bean:myBean?methodName=a")
+ .to("bean:myBean")
+ .bean(beanMock, "b")
+ .bean(beanMock)
+ .beanRef("myBean", "c")
+ .beanRef("myBean");
}
};
}
public void testNormalInvocation() throws Throwable {
- beanMock.a();
- beanMock.b();
- beanMock.c();
+ beanMock.a();
+ beanMock.b();
+ beanMock.c();
EasyMock.replay(beanMock);
Exchange result = template.send("direct:start", new DefaultExchange(context));
if (result.getException() != null) {
@@ -67,12 +73,24 @@
EasyMock.verify(beanMock);
}
+ public void testNoMethodSpecified() throws Throwable {
+ beanMock.a();
+ EasyMock.replay(beanMock);
+ Exchange result = template.send("direct:start2", new DefaultExchange(context));
+ assertNotNull(result.getException());
+ assertEquals(result.getException().getClass(), IllegalStateException.class);
+ EasyMock.verify(beanMock);
+ }
+
public void testMethodHeaderSet() throws Exception {
beanMock.a();
+ beanMock.d();
beanMock.b();
+ beanMock.d();
beanMock.c();
+ beanMock.d();
EasyMock.replay(beanMock);
- template.sendBodyAndHeader("direct:start", "test", BeanProcessor.METHOD_NAME, "d");
+ template.sendBodyAndHeader("direct:start2", "test", BeanProcessor.METHOD_NAME, "d");
EasyMock.verify(beanMock);
}