dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19865
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8842: Document controller, returning informative message if document cannot be found
------------------------------------------------------------
revno: 8842
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-11-03 21:39:55 +0300
message:
Document controller, returning informative message if document cannot be found
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-05-28 14:25:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java 2012-11-03 18:39:55 +0000
@@ -27,22 +27,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_JPG;
+import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_PDF;
+import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_PNG;
+
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
import org.hisp.dhis.document.Document;
import org.hisp.dhis.document.DocumentService;
import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.external.location.LocationManagerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import javax.servlet.http.HttpServletResponse;
-import java.io.InputStream;
-
-import static org.hisp.dhis.api.utils.ContextUtils.*;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
* @author Lars Helge Overland
@@ -54,6 +61,8 @@
{
public static final String RESOURCE_PATH = "/documents";
+ private static final Log log = LogFactory.getLog( DocumentController.class );
+
@Autowired
private DocumentService documentService;
@@ -74,14 +83,26 @@
}
else
{
+ InputStream in = null;
+
+ try
+ {
+ in = locationManager.getInputStream( document.getUrl(), DocumentService.DIR );
+
+ }
+ 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 );
- InputStream in = locationManager.getInputStream( document.getUrl(), DocumentService.DIR );
-
IOUtils.copy( in, response.getOutputStream() );
}
}