[
https://issues.apache.org/jira/browse/TAMAYA-141?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John D. Ament resolved TAMAYA-141.
----------------------------------
Resolution: Fixed
Patch applied to master. Thanks!
> org.apache.tamaya.etcd.EtcdAccessor should use try with resources when
> performing http requests
> -----------------------------------------------------------------------------------------------
>
> Key: TAMAYA-141
> URL: https://issues.apache.org/jira/browse/TAMAYA-141
> Project: Tamaya
> Issue Type: Improvement
> Affects Versions: 0.2-incubating
> Reporter: Philipp Ottlinger
> Assignee: Philipp Ottlinger
> Priority: Minor
> Fix For: 0.2-incubating
>
> Attachments: TAMAYA-141.diff
>
>
> org.apache.tamaya.etcd.EtcdAccessor should use tryWithResources when doing
> httpClient-calls. It's just a small improvement, that modernizes the code.
> try-with-resources makes sure that the underlying HttpResponse is closed if
> the method is left.
> h3. Before
> {code}
> CloseableHttpResponse response = null;
> try{
> ,....
> response = httpclient.execute(get);
> } catch(final Exception e){
> LOG.log(Level.INFO, "Error reading properties for '"+directory+"'
> from etcd: " + serverURL, e);
> result.put("_ERROR", "Error reading properties for
> '"+directory+"' from etcd: " + serverURL + ": " + e.toString());
> } finally {
> if(response!=null){
> try {
> response.close();
> } catch (final IOException e) {
> LOG.log(Level.WARNING, "Failed to close http response",
> e);
> }
> }
> }
> {code}
> h3. After
> {code}
> try {
> final HttpGet httpGet = new HttpGet(serverURL + "/v2/keys/"+key);
> httpGet.setConfig(RequestConfig.copy(RequestConfig.DEFAULT)
> .setSocketTimeout(socketTimeout)
>
> .setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
> try (CloseableHttpResponse response =
> httpclient.execute(httpGet)) {
> ....
> SNIP
> ...
> } catch(final Exception e){
> LOG.log(Level.INFO, "Error reading key '"+key+"' from etcd: " +
> serverURL, e);
> result.put("_ERROR", "Error reading key '"+key+"' from etcd: " +
> serverURL + ": " + e.toString());
> }
> {code}
> IMHO this would improve readability of the class since this kind of exchange
> happens in nearly all methods of the class.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)