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.git
The following commit(s) were added to refs/heads/main by this push: new b62260e CAMEL-17568: camel-core - TypeConverterExists change default to ignore. Fix adding type converter that previously was missed. b62260e is described below commit b62260e19db2aa61fa4a6180eaf24b04194c5944 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Jan 31 15:50:24 2022 +0100 CAMEL-17568: camel-core - TypeConverterExists change default to ignore. Fix adding type converter that previously was missed. --- .../resources/org/apache/camel/spring/xml/camelContext.json | 4 ++-- .../org/apache/camel/spring/xml/CamelContextFactoryBean.java | 8 ++++---- .../java/org/apache/camel/spi/TypeConverterRegistry.java | 8 ++++---- .../camel/impl/converter/CoreTypeConverterRegistry.java | 12 +++++++++--- .../modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc | 9 +++++++++ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/camelContext.json b/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/camelContext.json index a53b993..9212a3e 100644 --- a/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/camelContext.json +++ b/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/camelContext.json @@ -46,8 +46,8 @@ "typeConverterStatisticsEnabled": { "kind": "attribute", "displayName": "Type Converter Statistics Enabled", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets whether or not type converter statistics is enabled. By default the type converter utilization statistics is disabled. Notice: If enabled then there is a slight performance impact under very heavy load. You can enable\/disable the [...] "loadHealthChecks": { "kind": "attribute", "displayName": "Load Health Checks", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "false", "description": "Whether to load custom health checks by scanning classpath." }, "inflightRepositoryBrowseEnabled": { "kind": "attribute", "displayName": "Inflight Repository Browse Enabled", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets whether the inflight repository should allow browsing each inflight exchange. This is by default disabled as there is a very slight performance overhead when enabled." }, - "typeConverterExists": { "kind": "attribute", "displayName": "Type Converter Exists", "required": false, "type": "enum", "javaType": "org.apache.camel.TypeConverterExists", "enum": [ "fail", "ignore", "override" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Override", "description": "What should happen when attempting to add a duplicate type converter. The default behavior is to override the existing." }, - "typeConverterExistsLoggingLevel": { "kind": "attribute", "displayName": "Type Converter Exists Logging Level", "required": false, "type": "enum", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "debug", "error", "info", "off", "trace", "warn" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "WARN", "description": "The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter. The defaul [...] + "typeConverterExists": { "kind": "attribute", "displayName": "Type Converter Exists", "required": false, "type": "enum", "javaType": "org.apache.camel.TypeConverterExists", "enum": [ "fail", "ignore", "override" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Ignore", "description": "What should happen when attempting to add a duplicate type converter. The default behavior is to ignore the duplicate." }, + "typeConverterExistsLoggingLevel": { "kind": "attribute", "displayName": "Type Converter Exists Logging Level", "required": false, "type": "enum", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "debug", "error", "info", "off", "trace", "warn" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "DEBUG", "description": "The logging level to use when logging that a type converter already exists when attempting to add a duplicate type converter. The defau [...] "globalOptions": { "kind": "element", "displayName": "Global Options", "required": false, "type": "object", "javaType": "org.apache.camel.model.GlobalOptionsDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Configuration of CamelContext properties such as limit of debug logging and other general options." }, "propertyPlaceholder": { "kind": "element", "displayName": "Property Placeholder", "required": false, "type": "object", "javaType": "org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition", "deprecated": false, "autowired": false, "secret": false, "description": "Configuration of property placeholder" }, "package": { "kind": "element", "displayName": "Package", "required": false, "type": "array", "javaType": "java.lang.String[]", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the package names to be recursively searched for Java classes which extend org.apache.camel.builder.RouteBuilder to be auto-wired up to the CamelContext as a route. Note that classes are excluded if they are specifically configured in the spring.xml A more advanced configuration c [...] diff --git a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelContextFactoryBean.java b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelContextFactoryBean.java index a1e6acf..94e5054 100644 --- a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelContextFactoryBean.java +++ b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelContextFactoryBean.java @@ -191,10 +191,10 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr @XmlAttribute private String inflightRepositoryBrowseEnabled; @XmlAttribute - @Metadata(defaultValue = "Override") + @Metadata(defaultValue = "Ignore") private TypeConverterExists typeConverterExists; @XmlAttribute - @Metadata(defaultValue = "WARN") + @Metadata(defaultValue = "DEBUG") private LoggingLevel typeConverterExistsLoggingLevel; @XmlElement(name = "globalOptions") private GlobalOptionsDefinition globalOptions; @@ -1234,7 +1234,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr /** * What should happen when attempting to add a duplicate type converter. * <p/> - * The default behavior is to override the existing. + * The default behavior is to ignore the duplicate. */ public void setTypeConverterExists(TypeConverterExists typeConverterExists) { this.typeConverterExists = typeConverterExists; @@ -1249,7 +1249,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr * The logging level to use when logging that a type converter already exists when attempting to add a duplicate * type converter. * <p/> - * The default logging level is <tt>WARN</tt> + * The default logging level is <tt>DEBUG</tt> */ public void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel) { this.typeConverterExistsLoggingLevel = typeConverterExistsLoggingLevel; diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java b/core/camel-api/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java index c80aa17..bd715cd 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/TypeConverterRegistry.java @@ -162,7 +162,7 @@ public interface TypeConverterRegistry extends StaticService, CamelContextAware * The logging level to use when logging that a type converter already exists when attempting to add a duplicate * type converter. * <p/> - * The default logging level is <tt>WARN</tt> + * The default logging level is <tt>DEBUG</tt> */ LoggingLevel getTypeConverterExistsLoggingLevel(); @@ -170,21 +170,21 @@ public interface TypeConverterRegistry extends StaticService, CamelContextAware * The logging level to use when logging that a type converter already exists when attempting to add a duplicate * type converter. * <p/> - * The default logging level is <tt>WARN</tt> + * The default logging level is <tt>DEBUG</tt> */ void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel); /** * What should happen when attempting to add a duplicate type converter. * <p/> - * The default behavior is to override the existing. + * The default behavior is to ignore the duplicate. */ TypeConverterExists getTypeConverterExists(); /** * What should happen when attempting to add a duplicate type converter. * <p/> - * The default behavior is to override the existing. + * The default behavior is to ignore the duplicate. */ void setTypeConverterExists(TypeConverterExists typeConverterExists); diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java b/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java index a1d4a4a..2828e69 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/converter/CoreTypeConverterRegistry.java @@ -74,8 +74,8 @@ public class CoreTypeConverterRegistry extends ServiceSupport implements TypeCon protected final LongAdder hitCounter = new LongAdder(); protected final LongAdder failedCounter = new LongAdder(); - protected TypeConverterExists typeConverterExists = TypeConverterExists.Override; - protected LoggingLevel typeConverterExistsLoggingLevel = LoggingLevel.WARN; + protected TypeConverterExists typeConverterExists = TypeConverterExists.Ignore; + protected LoggingLevel typeConverterExistsLoggingLevel = LoggingLevel.DEBUG; // to keep track of number of converters in the bulked classes private int sumBulkTypeConverters; @@ -578,9 +578,15 @@ public class CoreTypeConverterRegistry extends ServiceSupport implements TypeCon public void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter) { LOG.trace("Adding type converter: {}", typeConverter); TypeConverter converter = typeMappings.get(toType, fromType); + + if (converter == MISS_CONVERTER) { + // we have previously attempted to convert but missed so add this converter + typeMappings.put(toType, fromType, typeConverter); + return; + } + // only override it if its different // as race conditions can lead to many threads trying to promote the same fallback converter - if (typeConverter != converter) { // add the converter unless we should ignore diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc index e5599ec..66d1a71 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc @@ -12,3 +12,12 @@ The option `camel.main.packageScanRouteBuilders` has been renamed to `camel.main Using configuration classes must now implement the interface `org.apache.camel.main.CamelConfiguration` and the `configure` method now takes a `CamelContext` as argument. + +=== camel-core + +Change the default from `Override` to `Ignore` in the `TypeConverterExists` option, +and the TypeConverterExistsLoggingLevel from `WARN` to `DEBUG`. + +Previously when Camel detected a duplicate type converter during startup, Camel would +override the existing converter and log a WARN. A more correct behaviour would be +to keep the existing and ignore the duplicate.