This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch bc in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4035517fd4dfcb67b35f84b8804f26571ef1f6b3 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Dec 11 19:46:00 2025 +0100 CAMEL-22775: camel-bean - Fix to not cache on instance level for Exchange. --- .../apache/camel/component/bean/BeanComponent.java | 10 ++++ .../org/apache/camel/component/bean/BeanInfo.java | 7 ++- .../apache/camel/component/bean/BeanInfoTest.java | 10 ++++ .../component/bean/BeanInfoCacheExchangeTest.java | 55 ++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java index 38c162350d23..ef8e66a403ba 100644 --- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java +++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java @@ -97,6 +97,16 @@ public class BeanComponent extends DefaultComponent { } } + /** + * Number of beans currently in the bean cache + */ + public int getCurrentBeanCacheSize() { + if (beanInfoCache != null) { + return beanInfoCache.size(); + } + return 0; + } + @Override protected void doShutdown() throws Exception { if (LOG.isDebugEnabled() && beanInfoCache instanceof LRUCache<BeanInfoCacheKey, BeanInfo> cache) { diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java index 94e860e4753e..cd8010aa75b1 100644 --- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java +++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java @@ -461,6 +461,10 @@ public class BeanInfo { = parametersAnnotations[i].toArray(new Annotation[0]); Expression expression = createParameterUnmarshalExpression(method, parameterType, parameterAnnotations); hasCustomAnnotation |= expression != null; + if (expression == null) { + expression = strategy.getDefaultParameterTypeExpression(parameterType); + } + // whether this parameter is vararg which must be last parameter boolean varargs = method.isVarArgs() && i == size - 1; @@ -1028,8 +1032,7 @@ public class BeanInfo { return answer; } } - // no annotations then try the default parameter mappings - return strategy.getDefaultParameterTypeExpression(parameterType); + return null; } private Expression createParameterUnmarshalExpressionForAnnotation( diff --git a/components/camel-bean/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java b/components/camel-bean/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java index 66e0a8e50f94..d3c6b65de845 100644 --- a/components/camel-bean/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java +++ b/components/camel-bean/src/test/java/org/apache/camel/component/bean/BeanInfoTest.java @@ -29,6 +29,7 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType; import org.apache.camel.CamelContext; import org.apache.camel.Handler; import org.apache.camel.spi.Registry; +import org.apache.camel.support.DefaultExchange; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -117,6 +118,15 @@ public class BeanInfoTest { assertTrue(info.isReturnTypeVoid()); } + @Test + public void testExchangeClass() { + BeanInfo info = new BeanInfo(context, DefaultExchange.class); + assertFalse(info.hasAnyMethodHandlerAnnotation()); + + BeanInfo info2 = new BeanInfo(context, DefaultExchange.class); + assertFalse(info2.hasAnyMethodHandlerAnnotation()); + } + private Object buildProxyObject() { try { return new ByteBuddy() diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoCacheExchangeTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoCacheExchangeTest.java new file mode 100644 index 000000000000..5236939b3d7f --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoCacheExchangeTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.bean; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BeanInfoCacheExchangeTest extends ContextTestSupport { + + @Test + public void testBeanInfoCacheExchange() throws Exception { + BeanComponent bean = context.getComponent("bean", BeanComponent.class); + + Assertions.assertEquals(0, bean.getCurrentBeanCacheSize()); + + getMockEndpoint("mock:result").expectedBodiesReceived("123", "123", "123"); + template.sendBody("direct:start", "Hello World"); + template.sendBody("direct:start", "Bye World"); + template.sendBody("direct:start", "Hi Moon"); + assertMockEndpointsSatisfied(); + + // only cache the exchange class (and not instances) + Assertions.assertEquals(1, bean.getCurrentBeanCacheSize()); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:start") + .setProperty("myKey", constant("123")) + .setBody(simple("${exchange.getProperty(\"myKey\")}")) + .to("mock:result"); + } + }; + } + +}
