← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8859: fixed nasty encoding bug in webapi, now sending ; charset=UTF-8 with the content-type for textual ...

 

------------------------------------------------------------
revno: 8859
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-11-04 14:30:04 +0100
message:
  fixed nasty encoding bug in webapi, now sending ;charset=UTF-8 with the content-type for textual responses
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SmsConfigurationController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.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/SmsConfigurationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SmsConfigurationController.java	2012-05-31 17:02:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SmsConfigurationController.java	2012-11-04 13:30:04 +0000
@@ -35,6 +35,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.sms.SmsConfigurationManager;
 import org.hisp.dhis.sms.config.GenericHttpGatewayConfig;
 import org.hisp.dhis.sms.config.SmsConfiguration;
@@ -111,7 +112,7 @@
     {
         log.info( "Exception", exception );
         response.setStatus( HttpServletResponse.SC_CONFLICT );
-        response.setContentType( "text/plain" );
+        response.setContentType( ContextUtils.CONTENT_TYPE_TEXT );
         response.getWriter().write( exception.getMessage() );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java	2012-09-26 08:46:31 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java	2012-11-04 13:30:04 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.dxf2.metadata.ImportSummary;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
@@ -72,7 +73,7 @@
     @RequestMapping( value = "/uid", method = RequestMethod.GET )
     public void getUid( HttpServletResponse response ) throws IOException
     {
-        response.setContentType( "text/plain" );
+        response.setContentType( ContextUtils.CONTENT_TYPE_TEXT );
         response.getWriter().write( CodeGenerator.generateCode() );
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java	2012-10-30 14:13:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java	2012-11-04 13:30:04 +0000
@@ -55,15 +55,15 @@
     public static final String CONTENT_TYPE_PDF = "application/pdf";
     public static final String CONTENT_TYPE_ZIP = "application/zip";
     public static final String CONTENT_TYPE_GZIP = "application/gzip";
-    public static final String CONTENT_TYPE_JSON = "application/json";
-    public static final String CONTENT_TYPE_HTML = "text/html";
-    public static final String CONTENT_TYPE_TEXT = "text/plain";
-    public static final String CONTENT_TYPE_XML = "application/xml";
-    public static final String CONTENT_TYPE_CSV = "application/csv";
+    public static final String CONTENT_TYPE_JSON = "application/json; charset=UTF-8";
+    public static final String CONTENT_TYPE_HTML = "text/html; charset=UTF-8";
+    public static final String CONTENT_TYPE_TEXT = "text/plain; charset=UTF-8";
+    public static final String CONTENT_TYPE_XML = "application/xml; charset=UTF-8";
+    public static final String CONTENT_TYPE_CSV = "application/csv; charset=UTF-8";
     public static final String CONTENT_TYPE_PNG = "image/png";
     public static final String CONTENT_TYPE_JPG = "image/jpeg";
     public static final String CONTENT_TYPE_EXCEL = "application/vnd.ms-excel";
-    public static final String CONTENT_TYPE_JAVASCRIPT = "application/javascript";
+    public static final String CONTENT_TYPE_JAVASCRIPT = "application/javascript; charset=UTF-8";
 
     public static final String HEADER_USER_AGENT = "User-Agent";
     public static final String HEADER_CACHE_CONTROL = "Cache-Control";

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java	2012-05-27 21:50:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java	2012-11-04 13:30:04 +0000
@@ -81,11 +81,12 @@
     }
 
     @Override
-    protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request,
+        HttpServletResponse response ) throws Exception
     {
         Object object = model.get( "model" );
         Class<?> viewClass = JacksonUtils.getViewClass( model.get( "viewClass" ) );
-        response.setContentType( getContentType() );
+        response.setContentType( getContentType() + "; charset=UTF-8" );
 
         if ( withPadding )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.java	2012-05-27 21:50:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.java	2012-11-04 13:30:04 +0000
@@ -49,11 +49,12 @@
     }
 
     @Override
-    protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request,
+        HttpServletResponse response ) throws Exception
     {
         Object object = model.get( "model" );
         Class<?> viewClass = JacksonUtils.getViewClass( model.get( "viewClass" ) );
-        response.setContentType( getContentType() );
+        response.setContentType( getContentType() + "; charset=UTF-8" );
         response.setStatus( HttpServletResponse.SC_OK );
 
         if ( viewClass != null )