Overriding HTTP client config while declaring routes.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Overriding HTTP client config while declaring routes.

Abhishek.Jha09
Hi,

I have a web application from which I'm calling around 50-60 rest/soap apis. For this, I've created routes in JAVA DSL. Now, to have default application level timeout settings, I've done configuration like this-

public class DefaultHttpClientConfig implements HttpClientConfigurer {   // http4

        @Override
        public void configureHttpClient(HttpClientBuilder clientBuilder) {
                clientBuilder.setDefaultRequestConfig(
                                RequestConfig.custom()
                                        .setConnectTimeout(1000)
                                        .setSocketTimeout(1000).build());
        }
}
and I've set this in camel context like this-

        static CamelContext ctx = new DefaultCamelContext();

        static {
                try {
                        HttpComponent httpComponent = ctx.getComponent("http4", HttpComponent.class);
                        httpComponent.setConnectionTimeToLive(10);
                        httpComponent.setHttpClientConfigurer(new DefaultHttpClientConfig());
                        ctx.addRoutes(new DirectRestRouteBuilder());
                        ctx.start();
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

Now when creating individual routes, I want to override these configuration, so I'm trying this as shown below-

from("direct:success")
       .to("http4://localhost:8089/mockcarrier/success?httpClient.socketTimeout=8000");

However, it seems that the direct configuration is not picked up. Where am I going wrong?
Loading...