dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22075
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10588: Changed DocumentController to handle potential resource leak
------------------------------------------------------------
revno: 10588
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
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 );
+ }
}
}
}