dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #34226
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17568: Web api, moved generic method for checking for request for compression accept to ContextUtils
------------------------------------------------------------
revno: 17568
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-11-24 12:08:48 +0100
message:
Web api, moved generic method for checking for request for compression accept to ContextUtils
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.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/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2014-11-17 07:54:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2014-11-24 11:08:48 +0000
@@ -208,7 +208,7 @@
OutputStream outputStream = response.getOutputStream();
response.setContentType( "application/csv" );
- if ( isGzip( request ) )
+ if ( ContextUtils.isAcceptGzip( request ) )
{
response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
outputStream = new GZIPOutputStream( outputStream );
@@ -522,7 +522,7 @@
@RequestParam( required = false, defaultValue = "false" ) boolean skipFirst,
HttpServletResponse response, HttpServletRequest request, ImportOptions importOptions ) throws IOException
{
- InputStream inputStream = isGzip( request ) ? new GZIPInputStream( request.getInputStream() ) : request.getInputStream();
+ InputStream inputStream = ContextUtils.isAcceptGzip( request ) ? new GZIPInputStream( request.getInputStream() ) : request.getInputStream();
Events events = csvEventService.readEvents( inputStream, skipFirst );
@@ -667,11 +667,4 @@
response.setStatus( HttpServletResponse.SC_NO_CONTENT );
eventService.deleteEvent( event );
}
-
- private boolean isGzip( HttpServletRequest request )
- {
- return request != null && (
- (request.getPathInfo() != null && request.getPathInfo().endsWith( ".gz" ))
- || (request.getHeader( "Accept" ) != null && request.getHeader( "Accept" ).contains( "application/csv+gzip" )));
- }
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.java 2014-11-17 22:18:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/ContextUtils.java 2014-11-24 11:08:48 +0000
@@ -410,4 +410,18 @@
return false;
}
+
+ /**
+ * Indicates whether the given requests indicates that it accepts a compressed
+ * response.
+ *
+ * @param request the HttpServletRequest.
+ * @return whether the given requests indicates that it accepts a compressed
+ * response.
+ */
+ public static boolean isAcceptGzip( HttpServletRequest request )
+ {
+ return request != null && ( ( request.getPathInfo() != null && request.getPathInfo().endsWith( ".gz" ) )
+ || ( request.getHeader( "Accept" ) != null && request.getHeader( "Accept" ).contains( "application/csv+gzip" ) ) );
+ }
}
\ No newline at end of file