This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.14.x by this push:
new 25873a80214c CAMEL-22775: camel-bean - Fix to not cache on instance
level for Exchange. (#20363)
25873a80214c is described below
commit 25873a80214cd1d7afe06a242207b4b7d3f71701
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Dec 12 07:42:43 2025 +0100
CAMEL-22775: camel-bean - Fix to not cache on instance level for Exchange.
(#20363)
---
.../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 8127b34aee89..b1d6ab85f162 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;
@@ -1027,8 +1031,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 ef5808fbb81e..423ad137be50 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
@@ -27,6 +27,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;
@@ -108,6 +109,15 @@ public class BeanInfoTest {
assertTrue(info.hasAnyMethodHandlerAnnotation());
}
+ @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");
+ }
+ };
+ }
+
+}