You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/09/12 17:29:02 UTC
[camel-spring-boot] branch CAMEL-19851/timeout-native-support updated (0ca627e4c09 -> acfaa2106a7)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a change to branch CAMEL-19851/timeout-native-support
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
discard 0ca627e4c09 CAMEL-19851: camel-http - Allow to configure timeouts natively
new acfaa2106a7 CAMEL-19851: camel-http - Allow to configure timeouts natively
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (0ca627e4c09)
\
N -- N -- N refs/heads/CAMEL-19851/timeout-native-support (acfaa2106a7)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 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:
.../src/test/resources/application.properties | 17 -----------------
1 file changed, 17 deletions(-)
delete mode 100644 components-starter/camel-http-starter/src/test/resources/application.properties
[camel-spring-boot] 01/01: CAMEL-19851: camel-http - Allow to configure timeouts natively
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch CAMEL-19851/timeout-native-support
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit acfaa2106a7b8d308a857bc26aa7ee95be0e987d
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Tue Sep 12 19:26:11 2023 +0200
CAMEL-19851: camel-http - Allow to configure timeouts natively
---
.../springboot/HttpComponentTimeoutConverter.java | 60 ++++++++++
...rk.boot.autoconfigure.AutoConfiguration.imports | 1 +
.../HttpComponentTimeoutConverterTest.java | 125 +++++++++++++++++++++
3 files changed, 186 insertions(+)
diff --git a/components-starter/camel-http-starter/src/main/java/org/apache/camel/component/http/springboot/HttpComponentTimeoutConverter.java b/components-starter/camel-http-starter/src/main/java/org/apache/camel/component/http/springboot/HttpComponentTimeoutConverter.java
new file mode 100644
index 00000000000..06b9100d584
--- /dev/null
+++ b/components-starter/camel-http-starter/src/main/java/org/apache/camel/component/http/springboot/HttpComponentTimeoutConverter.java
@@ -0,0 +1,60 @@
+/*
+ * 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.http.springboot;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.hc.core5.util.Timeout;
+import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.stereotype.Component;
+
+
+@Configuration(proxyBeanMethods = false)
+@ConfigurationPropertiesBinding
+@Component
+public class HttpComponentTimeoutConverter extends HttpComponentConverter {
+
+ @Override
+ public Set<ConvertiblePair> getConvertibleTypes() {
+ Set<ConvertiblePair> answer = new LinkedHashSet<>();
+ answer.add(new ConvertiblePair(Integer.class, org.apache.hc.core5.util.Timeout.class));
+ answer.add(new ConvertiblePair(Long.class, org.apache.hc.core5.util.Timeout.class));
+ answer.add(new ConvertiblePair(String.class, org.apache.hc.core5.util.Timeout.class));
+ return answer;
+ }
+
+ @Override
+ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
+ if (source == null) {
+ return null;
+ }
+ if (source instanceof Integer value) {
+ return Timeout.ofMilliseconds(value.longValue());
+ } else if (source instanceof Long value) {
+ return Timeout.ofMilliseconds(value);
+ } else if (source instanceof String value) {
+ if (value.startsWith("#")) {
+ return super.convert(source, sourceType, targetType);
+ }
+ return Timeout.ofMilliseconds(Long.parseLong(value));
+ }
+ return null;
+ }
+}
diff --git a/components-starter/camel-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/components-starter/camel-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 29877893b1d..e92fc17e3f3 100644
--- a/components-starter/camel-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ b/components-starter/camel-http-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -17,3 +17,4 @@
org.apache.camel.component.http.springboot.HttpComponentConverter
org.apache.camel.component.http.springboot.HttpComponentAutoConfiguration
+org.apache.camel.component.http.springboot.HttpComponentTimeoutConverter
diff --git a/components-starter/camel-http-starter/src/test/java/org/apache/camel/component/http/springboot/HttpComponentTimeoutConverterTest.java b/components-starter/camel-http-starter/src/test/java/org/apache/camel/component/http/springboot/HttpComponentTimeoutConverterTest.java
new file mode 100644
index 00000000000..d89aa6a99a8
--- /dev/null
+++ b/components-starter/camel-http-starter/src/test/java/org/apache/camel/component/http/springboot/HttpComponentTimeoutConverterTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.http.springboot;
+
+import java.nio.charset.StandardCharsets;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpComponent;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+ classes = {
+ HttpComponentTimeoutConverter.class,
+ CamelAutoConfiguration.class,
+ HttpComponentAutoConfiguration.class,
+ HttpComponentTimeoutConverterTest.TestConfiguration.class
+ },
+ properties = {"camel.component.http.so-timeout = 30000"}
+)
+class HttpComponentTimeoutConverterTest {
+
+ @Autowired
+ ProducerTemplate template;
+ @Autowired
+ private CamelContext context;
+
+ private static CamelContext currentContext;
+ private static HttpServer localServer;
+
+ private static String baseUrl;
+
+ @BeforeAll
+ public static void setUp() throws Exception {
+ localServer = ServerBootstrap.bootstrap()
+ .register("/checkSoTimeout", (request, response, ctx) -> {
+ response.setCode(HttpStatus.SC_OK);
+ assertNotNull(currentContext);
+ response.setEntity(new StringEntity(String.valueOf(currentContext.getComponent("http", HttpComponent.class).getSoTimeout().toSeconds()), StandardCharsets.US_ASCII));
+ })
+ .create();
+ localServer.start();
+
+ baseUrl = "http://localhost:" + localServer.getLocalPort();
+ }
+
+ @AfterAll
+ public static void tearDown() {
+ if (localServer != null) {
+ localServer.stop();
+ }
+ }
+
+ @BeforeEach
+ public void init() {
+ currentContext = context;
+ }
+
+ @Test
+ void checkSoTimeout() {
+ Exchange exchange = template.request("direct:checkSoTimeout", exchange1 -> {});
+ assertNotNull(exchange);
+ assertNull(exchange.getException());
+ Message out = exchange.getMessage();
+ assertNotNull(out);
+ assertEquals("30", out.getBody(String.class));
+ }
+
+
+ // *************************************
+ // Config
+ // *************************************
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public RouteBuilder routeBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:checkSoTimeout").to(baseUrl + "/checkSoTimeout");
+ }
+ };
+ }
+ }
+}