You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/02/08 11:37:23 UTC
(camel) branch camel-4.14.x updated (74cc84013162 -> 079f510603a8)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch camel-4.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
from 74cc84013162 Uprade undertow
new 9f4b966ed1e9 CAMEL-22972: camel-as2 - AS2ClientConnection leaks HTTP connections on error paths (#21307)
new 079f510603a8 CAMEL-22973: camel-core - ClassCastException in Splitter with exchange pooling (#21308)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../component/as2/api/AS2ClientConnection.java | 61 ++++++++++++++--------
.../camel/processor/PooledExchangeSplitTest.java | 41 +++++++++------
.../org/apache/camel/support/DefaultExchange.java | 6 +--
.../org/apache/camel/support/MonotonicClock.java | 2 +
.../org/apache/camel/support/ResetableClock.java | 4 +-
5 files changed, 73 insertions(+), 41 deletions(-)
copy components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTextlineInOnlyPooledExchangeTest.java => core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeSplitTest.java (56%)
(camel) 02/02: CAMEL-22973: camel-core - ClassCastException in Splitter with exchange pooling (#21308)
Posted by da...@apache.org.
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
commit 079f510603a877e419e23c6c34335c2d0e704f8f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 8 12:35:00 2026 +0100
CAMEL-22973: camel-core - ClassCastException in Splitter with exchange pooling (#21308)
---
.../camel/processor/PooledExchangeSplitTest.java | 72 ++++++++++++++++++++++
.../org/apache/camel/support/DefaultExchange.java | 6 +-
.../org/apache/camel/support/MonotonicClock.java | 2 +
.../org/apache/camel/support/ResetableClock.java | 4 +-
4 files changed, 80 insertions(+), 4 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeSplitTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeSplitTest.java
new file mode 100644
index 000000000000..da724d73fb6e
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeSplitTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.processor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.engine.PooledExchangeFactory;
+import org.apache.camel.impl.engine.PooledProcessorExchangeFactory;
+import org.junit.jupiter.api.Test;
+
+class PooledExchangeSplitTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext camelContext = super.createCamelContext();
+ ExtendedCamelContext ecc = camelContext.getCamelContextExtension();
+
+ ecc.setExchangeFactory(new PooledExchangeFactory());
+
+ ecc.setProcessorExchangeFactory(new PooledProcessorExchangeFactory());
+ ecc.getExchangeFactory().setStatisticsEnabled(true);
+ ecc.getProcessorExchangeFactory().setStatisticsEnabled(true);
+
+ return camelContext;
+ }
+
+ @Test
+ public void testSplitter() throws Exception {
+ List<Integer> data = new ArrayList<>(Arrays.asList(1, 2, 3));
+
+ getMockEndpoint("mock:result").expectedMessageCount(3);
+
+ template.sendBody("direct:processData", data);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:processData")
+ .split(body()).streaming().parallelProcessing()
+ .to("mock:result");
+ }
+ };
+ }
+
+}
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
index cb4d4728fc34..c232ae712e02 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultExchange.java
@@ -36,17 +36,17 @@ public final class DefaultExchange extends AbstractExchange {
DefaultExchange(CamelContext context, EnumMap<ExchangePropertyKey, Object> internalProperties,
Map<String, Object> properties) {
super(context, internalProperties, properties);
- this.timeInfo = new MonotonicClock();
+ this.timeInfo = new ResetableClock();
}
public DefaultExchange(CamelContext context) {
super(context);
- this.timeInfo = new MonotonicClock();
+ this.timeInfo = new ResetableClock();
}
public DefaultExchange(CamelContext context, ExchangePattern pattern) {
super(context, pattern);
- this.timeInfo = new MonotonicClock();
+ this.timeInfo = new ResetableClock();
}
public DefaultExchange(Exchange parent) {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/MonotonicClock.java b/core/camel-support/src/main/java/org/apache/camel/support/MonotonicClock.java
index 46ab3772368c..01ab4f8beb89 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/MonotonicClock.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/MonotonicClock.java
@@ -22,6 +22,8 @@ import org.apache.camel.clock.Clock;
/**
* A clock that increases monotonically (i.e.: does not go back in time) for precise elapsed calculations.
+ *
+ * @see ResetableClock
*/
public final class MonotonicClock implements Clock {
private final long created;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ResetableClock.java b/core/camel-support/src/main/java/org/apache/camel/support/ResetableClock.java
index 00091ac8353c..c9b5609aa4d1 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ResetableClock.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ResetableClock.java
@@ -21,7 +21,9 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.clock.Clock;
/**
- * A clock that can be reset.
+ * A clock for precises elapsed calculations, that also can be reset.
+ *
+ * @see MonotonicClock
*/
public final class ResetableClock implements Clock {
private long created;
(camel) 01/02: CAMEL-22972: camel-as2 - AS2ClientConnection leaks HTTP connections on error paths (#21307)
Posted by da...@apache.org.
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
commit 9f4b966ed1e9cbcf3e08ab87e47d5462406a5b95
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Feb 8 12:34:46 2026 +0100
CAMEL-22972: camel-as2 - AS2ClientConnection leaks HTTP connections on error paths (#21307)
---
.../component/as2/api/AS2ClientConnection.java | 61 ++++++++++++++--------
1 file changed, 40 insertions(+), 21 deletions(-)
diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
index 7cbf23c6b97d..e1392c58fb00 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ClientConnection.java
@@ -30,6 +30,7 @@ import javax.net.ssl.SSLSocketFactory;
import org.apache.camel.component.as2.api.io.AS2BHttpClientConnection;
import org.apache.camel.component.as2.api.protocol.RequestAS2;
import org.apache.camel.component.as2.api.protocol.RequestMDN;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
import org.apache.hc.client5.http.HttpRoute;
@@ -187,31 +188,49 @@ public class AS2ClientConnection {
throws HttpException, IOException, InterruptedException, ExecutionException, TimeoutException {
HttpRoute route = new HttpRoute(targetHost);
-
request.setAuthority(new URIAuthority(targetHost));
-
LeaseRequest leaseRequest = connectionPoolManager.lease(UUID.randomUUID().toString(), route, null);
- ConnectionEndpoint endpoint = leaseRequest.get(Timeout.ofSeconds(RETRIEVE_CONNECTION_TIMEOUT_SECONDS));
- if (!endpoint.isConnected()) {
- connectionPoolManager.connect(endpoint, TimeValue.ofMilliseconds(connectionTimeoutMilliseconds), httpContext);
- }
- // Execute Request
- HttpRequestExecutor httpExecutor = new HttpRequestExecutor() {
- @Override
- public ClassicHttpResponse execute(ClassicHttpRequest request, HttpClientConnection conn, HttpContext context)
- throws IOException, HttpException {
- super.preProcess(request, httpProcessor, context);
- ClassicHttpResponse response = super.execute(request, conn, context);
- super.postProcess(response, httpProcessor, context);
- return response;
+ ConnectionEndpoint endpoint = null;
+ HttpResponse response = null;
+ try {
+ endpoint = leaseRequest.get(Timeout.ofSeconds(RETRIEVE_CONNECTION_TIMEOUT_SECONDS));
+ if (!endpoint.isConnected()) {
+ connectionPoolManager.connect(endpoint, TimeValue.ofMilliseconds(connectionTimeoutMilliseconds), httpContext);
}
- };
-
- HttpResponse response = endpoint.execute(UUID.randomUUID().toString(), request, httpExecutor, httpContext);
- connectionPoolManager.release(endpoint, null,
- connectionKeepAliveStrategy.getKeepAliveDuration(response, httpContext));
-
+ // Execute Request
+ HttpRequestExecutor httpExecutor = new HttpRequestExecutor() {
+ @Override
+ public ClassicHttpResponse execute(ClassicHttpRequest request, HttpClientConnection conn, HttpContext context)
+ throws IOException, HttpException {
+ super.preProcess(request, httpProcessor, context);
+ ClassicHttpResponse response = super.execute(request, conn, context);
+ super.postProcess(response, httpProcessor, context);
+ return response;
+ }
+ };
+ response = endpoint.execute(UUID.randomUUID().toString(), request, httpExecutor, httpContext);
+ } finally {
+ if (endpoint != null) {
+ TimeValue keepAlive = null;
+ if (response != null) {
+ // Normal happy path: release with computed keep-alive.
+ keepAlive = connectionKeepAliveStrategy.getKeepAliveDuration(response, httpContext);
+ }
+ if (keepAlive == null) {
+ // If we didn't get a response, something failed mid-flight:
+ // do NOT keep this connection around. Close it and release with zero keep-alive.
+ keepAlive = TimeValue.ZERO_MILLISECONDS;
+ }
+ try {
+ connectionPoolManager.release(endpoint, null, keepAlive);
+ } catch (Exception ignored) {
+ // ignore
+ } finally {
+ IOHelper.close(endpoint);
+ }
+ }
+ }
return response;
}