robinvish2794 opened a new issue, #625:
URL: https://github.com/apache/camel-karaf/issues/625

   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> 
   
   <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> 
   
   E.g. - Defining http endpoint using <to>
   
   <to 
uri="http://localhost:8080?bridgeEndpoint=true&amp;responseTimeout=55000"/> 
   
   but when we create http endpoint using toD, the TypeConverter works just 
fine.
   E.g. - Defining http endpoint using <toD>
   
   <toD 
uri="http://localhost:8080?bridgeEndpoint=true&amp;httpClient.responseTimeout=55000"/>
 
   
   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 by using httpClient.responseTimeout property 
whereas responseTimeout property won't work as it does not resolve 
"#bean:socketTimeout" bean reference and still check for appropriate 
TypeConverter for conversion.
    
   E.g. -
   
   <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="httpClient.responseTimeout" 
value="#bean:socketTimeout"/>
           <property key="copyHeaders" value="false"/>
       </endpoint>
   </camelContext> 
   
   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've noticed 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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to