Folks

Now that HttpClient 5.2 runs I would like to deprecate a decade old way of handling responses in favor of HttpClientResponseHandler functional interface approach:


This common pattern should be discouraged going forward
```
try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
    System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
    System.out.println(EntityUtils.toString(response.getEntity()));
}
```
and be replaced by this one:

```
httpclient.execute(httppost, response -> {
    System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
    System.out.println(EntityUtils.toString(response.getEntity()));
    return null;
});
```

There are several advantages to the functional interface based approach:

1. it eliminates the entire class of resource leaks due sloppy exception handling in the application code.

2. it would make it easier to implement a classic i/o compatibility layer on top of the async APIs should we ever decide to build such a thing.

On the downside some users might not like the fact that they would need to adjust their existing HTTP response handling logic, but that is the case with all new things.

Please let me know what you think.

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to