Add UTF-8 support for HTTP responses.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_result_distribution@1368 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
index 9a572c2..cfd553d 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/APIServlet.java
@@ -328,8 +328,9 @@
         String strPort = request.getParameter("hyracks-port");
         String strDisplayResult = request.getParameter("display-result");
         int port = Integer.parseInt(strPort);
-        PrintWriter out = response.getWriter();
+        response.setCharacterEncoding("utf-8");
         response.setContentType("text/html");
+        PrintWriter out = response.getWriter();
         out.println("<H1>Input statements:</H1>");
         printInHtml(out, query);
         ServletContext context = getServletContext();
@@ -383,6 +384,7 @@
 
     @Override
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        response.setCharacterEncoding("utf-8");
         PrintWriter out = response.getWriter();
         response.setContentType("text/html");
         final String form = HTML_HEADER_TEMPLATE + String.format(HTML_FORM_CONTENT_TEMPLATE, "")
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
index 8eb5ec2..c6708b3 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryResultAPIServlet.java
@@ -44,9 +44,10 @@
 
     @Override
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        response.setContentType("text/html");
+        response.setCharacterEncoding("utf-8");
         String strHandle = request.getParameter("handle");
         PrintWriter out = response.getWriter();
-        response.setContentType("text/html");
         ServletContext context = getServletContext();
         IHyracksClientConnection hcc;
         IHyracksDataset hds;
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java
index 9fd3bae..cb1556a 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/QueryStatusAPIServlet.java
@@ -42,9 +42,10 @@
 
     @Override
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        response.setContentType("text/html");
+        response.setCharacterEncoding("utf-8");
         String strHandle = request.getParameter("handle");
         PrintWriter out = response.getWriter();
-        response.setContentType("text/html");
         ServletContext context = getServletContext();
         IHyracksClientConnection hcc;
         IHyracksDataset hds;
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java
index 2180555..bb5ebef 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/api/http/servlet/RESTAPIServlet.java
@@ -49,6 +49,9 @@
 
     @Override
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        response.setContentType("application/json");
+        response.setCharacterEncoding("utf-8");
+
         PrintWriter out = response.getWriter();
 
         DisplayFormat format = DisplayFormat.HTML;
@@ -64,7 +67,6 @@
         String query = getQueryParameter(request);
         boolean asyncResults = isAsync(request);
 
-        response.setContentType("application/json");
         ServletContext context = getServletContext();
         IHyracksClientConnection hcc;
         IHyracksDataset hds;
diff --git a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
index 17fb24c..00d49a8 100644
--- a/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
+++ b/asterix-app/src/main/java/edu/uci/ics/asterix/aql/translator/AqlTranslator.java
@@ -313,7 +313,7 @@
                         }
                         response.put("results", results);
                     }
-                    out.write(response.toString());
+                    out.print(response);
                 }
                 hcc.waitForCompletion(jobId);
             }
diff --git a/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/ExecutionTest.java b/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/ExecutionTest.java
index de1f208..76cfcbe 100644
--- a/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/ExecutionTest.java
+++ b/asterix-app/src/test/java/edu/uci/ics/asterix/test/runtime/ExecutionTest.java
@@ -16,7 +16,6 @@
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.apache.commons.io.FileUtils;
-import org.json.JSONArray;
 import org.json.JSONObject;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -33,7 +32,6 @@
 import edu.uci.ics.asterix.testframework.context.TestCaseContext;
 import edu.uci.ics.asterix.testframework.context.TestFileContext;
 import edu.uci.ics.asterix.testframework.xml.TestCase.CompilationUnit;
-import edu.uci.ics.hyracks.algebricks.core.config.SysoutFormatter;
 
 /**
  * Runs the runtime test cases under 'asterix-app/src/test/resources/runtimets'.