Author: davsclaus
Date: Thu Apr 5 11:37:52 2012
New Revision: 1309781
URL: http://svn.apache.org/viewvc?rev=1309781&view=rev
Log:
CAMEL-5140: bean component - @Handler should take precedence in a bean that
implements Predicate
Added:
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanHandlerMethodPredicateTest.java
- copied unchanged from r1309779,
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanHandlerMethodPredicateTest.java
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/bean/MyHandlerPredicateBean.java
- copied unchanged from r1309779,
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/MyHandlerPredicateBean.java
Modified:
camel/branches/camel-2.9.x/ (props changed)
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1309779
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=1309781&r1=1309780&r2=1309781&view=diff
==============================================================================
---
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
(original)
+++
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Thu Apr 5 11:37:52 2012
@@ -89,17 +89,19 @@ public class BeanProcessor extends Servi
}
// do we have a custom adapter for this POJO to a Processor
- // should not be invoked if an explicit method has been set
- Processor processor = getProcessor();
- if (explicitMethodName == null && processor != null) {
- LOG.trace("Using a custom adapter as bean invocation: {}",
processor);
- try {
- processor.process(exchange);
- } catch (Throwable e) {
- exchange.setException(e);
+ // but only do this if allowed
+ if (allowProcessor(explicitMethodName, beanInfo)) {
+ Processor processor = getProcessor();
+ if (processor != null) {
+ LOG.trace("Using a custom adapter as bean invocation: {}",
processor);
+ try {
+ processor.process(exchange);
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
+ callback.done(true);
+ return true;
}
- callback.done(true);
- return true;
}
Message in = exchange.getIn();
@@ -253,4 +255,23 @@ public class BeanProcessor extends Servi
protected void doStop() throws Exception {
ServiceHelper.stopService(getProcessor());
}
+
+ private boolean allowProcessor(String explicitMethodName, BeanInfo info) {
+ if (explicitMethodName != null) {
+ // don't allow if explicit method name is given, as we then must
invoke this method
+ return false;
+ }
+
+ // don't allow if any of the methods has a @Handler annotation
+ // as the @Handler annotation takes precedence and is supposed to
trigger invocation
+ // of the given method
+ for (MethodInfo method : info.getMethods()) {
+ if (method.hasHandlerAnnotation()) {
+ return false;
+ }
+ }
+
+ // fallback and allow using the processor
+ return true;
+ }
}