------------------------------------------------------------ revno: 10588 committer: Lars Helge Ă˜verland <larshe...@gmail.com> branch nick: dhis2 timestamp: Tue 2013-04-16 20:06:03 +0200 message: Changed DocumentController to handle potential resource leak modified: dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java 2012-11-03 18:39:55 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java 2013-04-16 18:06:03 +0000 @@ -61,8 +61,6 @@ { public static final String RESOURCE_PATH = "/documents"; - private static final Log log = LogFactory.getLog( DocumentController.class ); - @Autowired private DocumentService documentService; @@ -83,27 +81,30 @@ } else { + String ct = document.getContentType(); + + boolean attachment = !(CONTENT_TYPE_PDF.equals( ct ) || CONTENT_TYPE_JPG.equals( ct ) || CONTENT_TYPE_PNG.equals( ct )); + + contextUtils.configureResponse( response, document.getContentType(), CacheStrategy.CACHE_TWO_WEEKS, document.getUrl(), attachment ); + InputStream in = null; try { in = locationManager.getInputStream( document.getUrl(), DocumentService.DIR ); + IOUtils.copy( in, response.getOutputStream() ); } catch ( LocationManagerException ex ) { ContextUtils.conflictResponse( response, "Document could not be found: " + document.getUrl() ); - log.error( ex ); + return; } - - String ct = document.getContentType(); - - boolean attachment = !(CONTENT_TYPE_PDF.equals( ct ) || CONTENT_TYPE_JPG.equals( ct ) || CONTENT_TYPE_PNG.equals( ct )); - - contextUtils.configureResponse( response, document.getContentType(), CacheStrategy.CACHE_TWO_WEEKS, document.getUrl(), attachment ); - - IOUtils.copy( in, response.getOutputStream() ); + finally + { + IOUtils.closeQuietly( in ); + } } } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp