hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCORE-349) HttpResponse should implement Closeable (Java7 try-with-resources support)
Date Fri, 13 Sep 2013 16:18:51 GMT

    [ https://issues.apache.org/jira/browse/HTTPCORE-349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13766587#comment-13766587
] 

Oleg Kalnichevski commented on HTTPCORE-349:
--------------------------------------------

Truth to be told HttpClient 4.3 tutorial [1] consistently uses CloseableHttpClient everywhere,
so do examples. Feel free to raise a request in JIRA for Java 7 specific tutorial section
on resource management. You are also very welcome to contribute some content to it ;)

Oleg

[1] http://hc.apache.org/httpcomponents-client-4.3.x/tutorial/html/fundamentals.html
                
> HttpResponse should implement Closeable (Java7 try-with-resources support)
> --------------------------------------------------------------------------
>
>                 Key: HTTPCORE-349
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-349
>             Project: HttpComponents HttpCore
>          Issue Type: Improvement
>          Components: HttpCore
>    Affects Versions: 4.3
>            Reporter: Hendy Irawan
>             Fix For: Future
>
>
> Currently we've got code like this:
> {code}
> final HttpResponse response = client.execute(postReq);
> try {
> 	final StatusLine responseStatus = response.getStatusLine();
> 	final String responseBody;
> 	if (response.getEntity() != null)
> 		responseBody = IOUtils.toString(response.getEntity().getContent());
> 	else
> 		responseBody = null;
> 	if (responseStatus.getStatusCode() >= 200 && responseStatus.getStatusCode()
< 300) {
> 		log.info("Job returned {}: {}", responseStatus, responseBody);
> 	} else
> 		log.error("Job returned {}: {}", responseStatus, responseBody);
> } finally {
> 	HttpClientUtils.closeQuietly(response);
> }
> {code}
> It would be great if this could be simplified to : (in Java 7)
> {code}
> try (final HttpResponse response = client.execute(postReq)) { 
>     ...
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message