zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zjf...@apache.org
Subject zeppelin git commit: ZEPPELIN-3099 Livy Interpreter doesn't support German Special Character - Encoding Issue
Date Tue, 13 Mar 2018 11:55:46 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master 4463967a5 -> b9d2f40bd


ZEPPELIN-3099 Livy Interpreter doesn't support German Special Character - Encoding Issue

### What is this PR for?
ZEPPELIN-3099 Livy Interpreter doesn't support German Special Character - Encoding Issue

### What type of PR is it?
BUG FIX for : ZEPPELIN-3099

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-3099

### How should this be tested?
test with German Special Characters like ß, ü, Ü, ä, Ä, ö, Ö .

Author: Akhil Subhash Naik <asnaik@hortonworks.com>

Closes #2860 from Akhilsnaik/ZEPPELIN-3099-master and squashes the following commits:

eee2f5a [Akhil Subhash Naik] ZEPPELIN-3099 Implement the UT cases and fix review comments
(asnaik)
ecf4b54 [Akhil Subhash Naik] ZEPPELIN-3099 Implement the UT cases and fix review comments
(asnaik)
7a65776 [Akhil Subhash Naik] ZEPPELIN-3099 Livy Interpreter doesn't support German Special
Character - Encoding Issue (asnaik)


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

Branch: refs/heads/master
Commit: b9d2f40bd737163be55681970b1f467f668c8fab
Parents: 4463967
Author: Akhil Subhash Naik <asnaik@hortonworks.com>
Authored: Tue Mar 13 16:10:07 2018 +0530
Committer: Jeff Zhang <zjffdu@apache.org>
Committed: Tue Mar 13 19:55:35 2018 +0800

----------------------------------------------------------------------
 .../apache/zeppelin/livy/BaseLivyInterpreter.java | 15 ++++++++++-----
 .../apache/zeppelin/livy/LivyInterpreterIT.java   | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/b9d2f40b/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 5fe7ce4..1eba9c2 100644
--- a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
+++ b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
@@ -19,6 +19,7 @@ package org.apache.zeppelin.livy;
 
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.security.KeyStore;
 import java.security.Principal;
 import java.util.ArrayList;
@@ -52,6 +53,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.zeppelin.interpreter.Interpreter;
+import org.apache.zeppelin.interpreter.Interpreter.FormType;
 import org.apache.zeppelin.interpreter.InterpreterContext;
 import org.apache.zeppelin.interpreter.InterpreterException;
 import org.apache.zeppelin.interpreter.InterpreterResult;
@@ -68,6 +70,7 @@ import org.springframework.http.HttpMethod;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.http.converter.StringHttpMessageConverter;
 import org.springframework.security.kerberos.client.KerberosRestTemplate;
 import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.HttpServerErrorException;
@@ -652,19 +655,21 @@ public abstract class BaseLivyInterpreter extends Interpreter {
       }
     }
 
-
+    RestTemplate restTemplate = null;
     if (isSpnegoEnabled) {
       if (httpClient == null) {
-        return new KerberosRestTemplate(keytabLocation, principal);
+        restTemplate = new KerberosRestTemplate(keytabLocation, principal);
       } else {
-        return new KerberosRestTemplate(keytabLocation, principal, httpClient);
+        restTemplate = new KerberosRestTemplate(keytabLocation, principal, httpClient);
       }
     }
     if (httpClient == null) {
-      return new RestTemplate();
+      restTemplate = new RestTemplate();
     } else {
-      return new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
+      restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
     }
+    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
+    return restTemplate;
   }
 
   private String callRestAPI(String targetURL, String method) throws LivyException {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/b9d2f40b/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 96fdbea..0c8bea9 100644
--- a/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
+++ b/livy/src/test/java/org/apache/zeppelin/livy/LivyInterpreterIT.java
@@ -371,14 +371,16 @@ public class LivyInterpreterIT {
     }
 
     // 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();
-    }
+    String utf8Str = "你你你你你你好";
+    InterpreterResult reslt = pysparkInterpreter.interpret("print(\"" + utf8Str + "\")",
context);
+    assertEquals(InterpreterResult.Code.SUCCESS, reslt.code());
+    assertTrue(reslt.message().get(0).getData().contains(utf8Str));
+
+    //test special characters
+    String charStr = "açñiñíûÑoç";
+    InterpreterResult res = pysparkInterpreter.interpret("print(\"" + charStr + "\")", context);
+    assertEquals(InterpreterResult.Code.SUCCESS, res.code());
+    assertTrue(res.message().get(0).getData().contains(charStr));
 
     try {
       InterpreterResult result = pysparkInterpreter.interpret("sc.version", context);


Mime
View raw message