You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2025/05/30 07:41:00 UTC
[jira] [Resolved] (CAMEL-22128) camel-http TypeConverterLoader issue
[ https://issues.apache.org/jira/browse/CAMEL-22128?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-22128.
---------------------------------
Resolution: Invalid
> camel-http TypeConverterLoader issue
> ------------------------------------
>
> Key: CAMEL-22128
> URL: https://issues.apache.org/jira/browse/CAMEL-22128
> Project: Camel
> Issue Type: Bug
> Components: camel-core, camel-http
> Affects Versions: 4.10.3
> Reporter: Robin Vishwakarma
> Priority: Major
>
> While migrating from Camel 3.22.2 (Karaf 4.4.4) -> Camel 4.10.3 (Karaf 4.4.6).
> I've noticed in the Camel 3.x to 4.0 Migration Guide and specially camel-http component ([https://camel.apache.org/manual/camel-4-migration-guide.html#_camel_http])
> Apache HttpComponents v5 client library is introduced which has new Timeout properties ( e.g. responseTimeout) and introduced Timeout object for such properties.
> E.g.- [https://github.com/apache/camel/blob/camel-4.10.3/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java#L135]
> camel-http component does have HttpConverters provided which takes care of converting String, long, etc values to Timeout object. (HttpConvertersLoader auto generated
> TypeConverterLoader)
>
> but the issue is with the availability of this TypeConverter when creating the HTTP endpoints.
>
> Example -
> When we create HTTP endpoint in Blueprint XML or JAVA DSL. The TypeConverter is not found in current Camel Context TypeConverterRegistry -
>
> E.g. - Defining http endpoint using <endpoint>
> {code:java}
> <camelContext id="context-v1.ctx" streamCache="true" useMDCLogging="true" xmlns="http://camel.apache.org/schema/blueprint">
> <endpoint id="httpEndpoint" uri="http://localhost:8080">
> <property key="bridgeEndpoint" value="true"/>
> <property key="responseTimeout" value="55000"/>
> </endpoint>
> </camelContext> {code}
> E.g. - Defining http endpoint using <to>
> {code:java}
> <to uri="http://localhost:8080?bridgeEndpoint=true&responseTimeout=55000"/> {code}
> but when we create http endpoint using toD, the TypeConverter works just fine.
> E.g. - Defining http endpoint using <toD>
> {code:java}
> <toD uri="http://localhost:8080?bridgeEndpoint=true&httpClient.responseTimeout=55000"/> {code}
> *Note -* for this toD way of creating http endpoint responseTimeout property does not work and it gets filtered out, the reason being it is not listed in know properties hence we need to send it as httpClient.responseTimeout ([https://github.com/apache/camel/blob/camel-4.10.3/components/camel-http/src/generated/resources/META-INF/org/apache/camel/component/http/http.json#L91])
>
> The reason why <endpoint> and <to> does not work is because http endpoint is created before the TypeConverter is actually loaded and made available in Current Camel Context TypeConverterRegistry.
>
> The http endpoint is created in/before doInit() method of AbstractCamelContext. ([https://github.com/apache/camel/blob/camel-4.10.3/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java#L2264])
>
> Whereas, The loading of HttpConvertersLoader happens when doStart() method of AbstractCamelContext is called. Specially when starting DeferServiceStartupListener at line - [https://github.com/apache/camel/blob/camel-4.10.3/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java#L2871]
>
> In simpler words - HTTP endpoint is created before the HTTP TypeConverter is loaded. Why it works for toD is because the http endpoint is created when it is first invoked (Lazy Init ?) and all the TypeConverters are already loaded in the TypeConverterRegistry.
>
> In order to make http endpoint work with <endpoint> or <to>, I created a bean of Timeout object and passed it as a reference to bypass this TypeConverter not found issue.
>
> E.g. -
> {code:java}
> <bean id="socketTimeout" class="org.apache.hc.core5.util.Timeout" factory-method="ofMilliseconds">
> <argument value="55000"/>
> </bean>
> <camelContext id="context-v1.ctx" streamCache="true" useMDCLogging="true" xmlns="http://camel.apache.org/schema/blueprint">
> <endpoint id="httpEndpoint" uri="http://localhost:9999">
> <property key="bridgeEndpoint" value="true"/>
> <property key="responseTimeout" value="#bean:socketTimeout"/>
> <property key="copyHeaders" value="false"/>
> </endpoint>
> </camelContext> {code}
> Now my question is, is there any limitation of how the TypeConverters are loaded in OSGi or is there any other way to make them work, apart from "toD" solution ?
>
> Please let me know if I am missing something.
>
> Currently, I'venoticed this issue for camel-http because now it deals with special objects for configuration/properties and there might be other components as well which have their own TypeConverters for special handling.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)