You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Henrik Brautaset Aronsen <he...@synth.no> on 2015/07/01 13:06:30 UTC

Sending abort() to a httpclient

I can control the httpclient connection and socket timeouts by adding query
parameters to the URL delivered in ProcessorDefinition.to(), e.g. "
http://example.com/stuff?httpClient.connectTimeout=1000&httpClient.socketTimeout=5000
"

I'd like to have an hard overall time limit on the request, though.
HttpClient doesn't support that as an argument, but it has an abort() call
that can be used like this:

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getMethod = new HttpGet("http://example.com/stuff");
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            if (getMethod != null) {
                getMethod.abort();
            }
        }
    };
    new Timer(true).schedule(task, 5000);
    HttpResponse response = httpClient.execute(getMethod);

How can I achieve the same in a Camel route?

Cheers,
Henrik

Re: Sending abort() to a httpclient

Posted by Pontus Ullgren <ul...@gmail.com>.
I guess you could create you own clientConnectionManager (see the option on
the HTTP/HTTP4 component documentation) that returns a decorated HTTP
client that, when execute is called, creates the timer and starts it.
Or do some other more fancy handling to avoid having to start another
thread for each request.

Best regards
Pontus

On Wed, 1 Jul 2015 13:07 Henrik Brautaset Aronsen <he...@synth.no> wrote:

> I can control the httpclient connection and socket timeouts by adding query
> parameters to the URL delivered in ProcessorDefinition.to(), e.g. "
>
> http://example.com/stuff?httpClient.connectTimeout=1000&httpClient.socketTimeout=5000
> "
>
> I'd like to have an hard overall time limit on the request, though.
> HttpClient doesn't support that as an argument, but it has an abort() call
> that can be used like this:
>
>     DefaultHttpClient httpClient = new DefaultHttpClient();
>     HttpGet getMethod = new HttpGet("http://example.com/stuff");
>     TimerTask task = new TimerTask() {
>         @Override
>         public void run() {
>             if (getMethod != null) {
>                 getMethod.abort();
>             }
>         }
>     };
>     new Timer(true).schedule(task, 5000);
>     HttpResponse response = httpClient.execute(getMethod);
>
> How can I achieve the same in a Camel route?
>
> Cheers,
> Henrik
>