You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2017/09/28 05:03:16 UTC

zeppelin git commit: [ZEPPELIN-2641] Change encoding to UTF-8 when sending request to Livy

Repository: zeppelin
Updated Branches:
  refs/heads/master 0d13c0b56 -> f7c47af9b


[ZEPPELIN-2641] Change encoding to UTF-8 when sending request to Livy

### What is this PR for?
Change encoding of the request sent from Zeppelin to Livy to UTF-8. In this way, Zeppelin can support many more language than using ISO-8895-1 by default.

### What type of PR is it?
Bug Fix

### What is the Jira issue?
[ZEPPELIN-2641](https://issues.apache.org/jira/browse/ZEPPELIN-2641)

### How should this be tested?
Build from source.
Open a Livy note book.
Run some simple print command with Chinese or Korean, see whether the return can show the character correctly

### Screenshots (if appropriate)
before
![image](https://user-images.githubusercontent.com/14201792/27174528-11d45216-51ef-11e7-8f46-2f2e8347a3de.png)

after
![image](https://user-images.githubusercontent.com/14201792/27174517-08cdba04-51ef-11e7-989c-88e516b2d265.png)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: 汪赫扬 <qw...@gmail.com>

Closes #2412 from qwemicheal/utf-8 and squashes the following commits:

a72ffeb [汪赫扬] change utf8Str to explicit Chinese
8f144bc [汪赫扬] add unit test
f689a7e [汪赫扬] add utf-8 encoding


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/f7c47af9
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/f7c47af9
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/f7c47af9

Branch: refs/heads/master
Commit: f7c47af9b552843f63935a59302de31519ae6b97
Parents: 0d13c0b
Author: 汪赫扬 <qw...@gmail.com>
Authored: Mon Jun 19 12:39:55 2017 +0800
Committer: Jeff Zhang <zj...@apache.org>
Committed: Thu Sep 28 13:03:11 2017 +0800

----------------------------------------------------------------------
 .../org/apache/zeppelin/livy/BaseLivyInterpreter.java    |  3 ++-
 .../java/org/apache/zeppelin/livy/LivyInterpreterIT.java | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f7c47af9/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
----------------------------------------------------------------------
diff --git a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
index a5c87f8..ccab09b 100644
--- a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
+++ b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
@@ -41,6 +41,7 @@ import org.apache.zeppelin.interpreter.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpEntity;
+import org.springframework.http.MediaType;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
@@ -520,7 +521,7 @@ public abstract class BaseLivyInterpreter extends Interpreter {
     targetURL = livyURL + targetURL;
     LOGGER.debug("Call rest api in {}, method: {}, jsonData: {}", targetURL, method, jsonData);
     HttpHeaders headers = new HttpHeaders();
-    headers.add("Content-Type", "application/json");
+    headers.add("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
     headers.add("X-Requested-By", "zeppelin");
     ResponseEntity<String> response = null;
     try {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/f7c47af9/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
----------------------------------------------------------------------
diff --git a/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
index 60c9043..9a0aef4 100644
--- a/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
+++ b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Properties;
 
@@ -555,6 +556,16 @@ public class LivyInterpreterIT {
       assertTrue(result.message().get(0).getData().contains("Traceback"));
     }
 
+    // test utf-8 Encoding
+    try {
+      String utf8Str = "你你你你你你好";
+      InterpreterResult result = pysparkInterpreter.interpret("print(\""+utf8Str+"\")", context);
+      assertEquals(InterpreterResult.Code.SUCCESS, result.code());
+      assertTrue(result.message().get(0).getData().contains(utf8Str));
+    }catch (Exception e) {
+      e.printStackTrace();
+    }
+
     try {
       InterpreterResult result = pysparkInterpreter.interpret("sc.version", context);
       assertEquals(InterpreterResult.Code.SUCCESS, result.code());