This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
commit b25135da7079bdd77cb429fe38d29ceafbf392cb Author: Claus Ibsen <[email protected]> AuthorDate: Wed May 27 21:02:31 2026 +0200 CAMEL-23079: Add Spring Boot auto-configuration for ErrorRegistry SPI Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../CamelErrorRegistryAutoConfiguration.java | 53 ++++++++ .../CamelErrorRegistryConfigurationProperties.java | 138 +++++++++++++++++++++ ...rk.boot.autoconfigure.AutoConfiguration.imports | 1 + 3 files changed, 192 insertions(+) diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/errorregistry/CamelErrorRegistryAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/errorregistry/CamelErrorRegistryAutoConfiguration.java new file mode 100644 index 00000000000..d5dc728314c --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/errorregistry/CamelErrorRegistryAutoConfiguration.java @@ -0,0 +1,53 @@ +/* + * 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.spring.boot.errorregistry; + +import java.time.Duration; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ErrorRegistry; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +@AutoConfiguration(after = CamelAutoConfiguration.class) +@ConditionalOnBean(CamelAutoConfiguration.class) +@EnableConfigurationProperties(CamelErrorRegistryConfigurationProperties.class) +public class CamelErrorRegistryAutoConfiguration { + + @Bean + public ErrorRegistry errorRegistry(CamelContext camelContext, CamelErrorRegistryConfigurationProperties config) { + if (!config.isEnabled()) { + return null; + } + + ErrorRegistry errorRegistry = camelContext.getErrorRegistry(); + errorRegistry.setEnabled(true); + errorRegistry.setMaximumEntries(config.getMaximumEntries()); + errorRegistry.setTimeToLive(Duration.ofSeconds(config.getTimeToLiveSeconds())); + errorRegistry.setBodyMaxChars(config.getBodyMaxChars()); + errorRegistry.setBodyIncludeStreams(config.isBodyIncludeStreams()); + errorRegistry.setBodyIncludeFiles(config.isBodyIncludeFiles()); + errorRegistry.setIncludeExchangeProperties(config.isIncludeExchangeProperties()); + errorRegistry.setIncludeExchangeVariables(config.isIncludeExchangeVariables()); + + return errorRegistry; + } + +} diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/errorregistry/CamelErrorRegistryConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/errorregistry/CamelErrorRegistryConfigurationProperties.java new file mode 100644 index 00000000000..147be9eb7c8 --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/errorregistry/CamelErrorRegistryConfigurationProperties.java @@ -0,0 +1,138 @@ +/* + * 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.spring.boot.errorregistry; + +import org.apache.camel.spi.Metadata; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.errorregistry") +public class CamelErrorRegistryConfigurationProperties { + + /** + * Whether the error registry is enabled to capture errors during message routing. + */ + private boolean enabled; + + /** + * The maximum number of error entries to keep in the registry. When the limit is exceeded, the oldest entries are + * evicted. + */ + @Metadata(defaultValue = "100") + private int maximumEntries = 100; + + /** + * The time-to-live in seconds for error entries. Entries older than this are evicted. + */ + @Metadata(defaultValue = "3600") + private int timeToLiveSeconds = 3600; + + /** + * To limit the message body to a maximum size in the captured error data. Use 0 or negative value to use unlimited + * size. + */ + @Metadata(label = "advanced", defaultValue = "32768") + private int bodyMaxChars = 32 * 1024; + + /** + * Whether to include the message body of stream based messages. If enabled then beware the stream may not be + * re-readable later. See more about Stream Caching. + */ + private boolean bodyIncludeStreams; + + /** + * Whether to include the message body of file based messages. The overhead is that the file content has to be read + * from the file. + */ + @Metadata(defaultValue = "true") + private boolean bodyIncludeFiles = true; + + /** + * Whether to include the exchange properties in the captured error data. + */ + @Metadata(defaultValue = "true") + private boolean includeExchangeProperties = true; + + /** + * Whether to include the exchange variables in the captured error data. + */ + @Metadata(defaultValue = "true") + private boolean includeExchangeVariables = true; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public int getMaximumEntries() { + return maximumEntries; + } + + public void setMaximumEntries(int maximumEntries) { + this.maximumEntries = maximumEntries; + } + + public int getTimeToLiveSeconds() { + return timeToLiveSeconds; + } + + public void setTimeToLiveSeconds(int timeToLiveSeconds) { + this.timeToLiveSeconds = timeToLiveSeconds; + } + + public int getBodyMaxChars() { + return bodyMaxChars; + } + + public void setBodyMaxChars(int bodyMaxChars) { + this.bodyMaxChars = bodyMaxChars; + } + + public boolean isBodyIncludeStreams() { + return bodyIncludeStreams; + } + + public void setBodyIncludeStreams(boolean bodyIncludeStreams) { + this.bodyIncludeStreams = bodyIncludeStreams; + } + + public boolean isBodyIncludeFiles() { + return bodyIncludeFiles; + } + + public void setBodyIncludeFiles(boolean bodyIncludeFiles) { + this.bodyIncludeFiles = bodyIncludeFiles; + } + + public boolean isIncludeExchangeProperties() { + return includeExchangeProperties; + } + + public void setIncludeExchangeProperties(boolean includeExchangeProperties) { + this.includeExchangeProperties = includeExchangeProperties; + } + + public boolean isIncludeExchangeVariables() { + return includeExchangeVariables; + } + + public void setIncludeExchangeVariables(boolean includeExchangeVariables) { + this.includeExchangeVariables = includeExchangeVariables; + } +} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 31f55659dc8..bf307457a06 100644 --- a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -24,6 +24,7 @@ org.apache.camel.spring.boot.actuate.health.CamelHealthCheckAutoConfiguration org.apache.camel.spring.boot.actuate.health.CamelAvailabilityCheckAutoConfiguration org.apache.camel.spring.boot.actuate.info.CamelInfoAutoConfiguration org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration +org.apache.camel.spring.boot.errorregistry.CamelErrorRegistryAutoConfiguration org.apache.camel.spring.boot.routecontroller.SupervisingRouteControllerAutoConfiguration org.apache.camel.spring.boot.security.CamelSecurityPolicyAutoConfiguration org.apache.camel.spring.boot.security.CamelSSLAutoConfiguration
