Hi Oleg,
Thanks for the input.

> On 31. Aug 2023, at 11:17, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> On Thu, 2023-08-31 at 10:08 +0200, Konrad Windszus wrote:
>> Hi,
>> I can pass a FutureCallback implementation to
>> HttpAsyncClient.execute(…).
>> However the javadoc at
>> https://hc.apache.org/httpcomponents-core-5.1.x/current/httpcore5/apidocs/org/apache/hc/core5/concurrent/FutureCallback.html
>>  is very sparse.
>> Particularly the following questions are not answered:
>> 
>> 1) Is "completed(HttpResponse)" only called for success status codes
>> or for all kinds server of responses? Would be good to mention that
>> in
> 
> It is called for all valid final HTTP response messages (status code =>
> 200).

Then I guess 
https://hc.apache.org/httpcomponents-core-5.1.x/current/httpcore5/apidocs/org/apache/hc/core5/concurrent/FutureCallback.html#failed(java.lang.Exception)
 is called for status code >= 300? How to access the response body there?
> 
>> https://hc.apache.org/httpcomponents-client-5.2.x/current/httpclient5/apidocs/org/apache/hc/client5/http/impl/async/CloseableHttpAsyncClient.html
>>  and other mentions of the execute method leveraging the parameter
>> FutureCallback (because it seems to be specific to the FutureCallback
>> being used from HttpAsyncClient.execute(…))
>> 
>> 2) What (unchecked) exception to throw in the FutureCallback method
>> for the future to fail with ExecutionException.html. Does it matter?
>> Is there any recommendation, e.g. if the HTTP endpoint returned a 500
>> status? Maybe also the examples e.g. in
>> https://github.com/apache/httpcomponents-client/blob/5.2.x/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientHttp1Pipelining.java
>>  could be extended in this regard.
>> 
> 
> You should consider returning a object with error information as a
> result of the operation instead of throwing an unchecked exception from
> the callback. 
Why is that? I want Future.get() to throw an exception in case of unexpected 
responses, otherwise callers you have to call Future.get() and in addition 
check that additional object.
And I guess by "consider returning a object with error” you meant populating 
some error object, because none of the FutureCallback methods allow to return 
anything.

Konrad

> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org 
> <mailto:httpclient-users-unsubscr...@hc.apache.org>
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org 
> <mailto:httpclient-users-h...@hc.apache.org>

Reply via email to