Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-349

HttpResponse should implement Closeable (Java7 try-with-resources support)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 4.3
    • None
    • HttpCore
    • None

    Description

      Currently we've got code like this:

      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);
      }
      

      It would be great if this could be simplified to : (in Java 7)

      try (final HttpResponse response = client.execute(postReq)) { 
          ...
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ceefour Hendy Irawan
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: