0

So, I have a route which essentially looks like this-

from("direct:send_success")
        .to("http4://localhost:8089/mock/success?httpClient.socketTimeout=1000");

Using this way, I'm able to apply socket timeout of 1 sec successfully. I am using ProducerTemplate to invoke this route. This is all fine. But when I change the route to-

from("direct:send_success")
    .to("http4://localhost:8089/mock/success");

And route invocation to-

ProducerTemplate pt = ctx.createProducerTemplate();
Exchange ex = pt.send("direct:send_success", exOb -> {
    HttpComponent httpComp = exOb.getContext().getComponent("http4", HttpComponent.class);
    exOb.getContext().getComponent("http4", HttpComponent.class).setHttpClientConfigurer(httpClientBuilder -> {
            HttpClientBuilder
                .create()
                .setDefaultRequestConfig(requestConfigWithTimeout(1000))
                .build();
        });
});

And the method requestConfigWithTimeout() as-

private static RequestConfig requestConfigWithTimeout(int timeoutInMilliseconds) {
    return RequestConfig.copy(RequestConfig.DEFAULT)
            .setSocketTimeout(timeoutInMilliseconds)
            .build();
}

The timeout settings are not applied. Where am I going wrong?

1 Answer 1

2

You cannot change the http component after the Camel route has been created and started. Then the route was created with the http4 component which has not had its configured changed with that extra code you do.

So configure the http4 component earlier and not when you send the message.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok. I was able to do the same for SOAP endpoint using cxf's ClientPolicy in request header so I thought there would be a workaround here as well. Anyways, thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.