sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rzh...@apache.org
Subject sqoop git commit: SQOOP-2451: Sqoop2: Findbugs: Add explicit charset to client ResourceRequest class
Date Tue, 04 Aug 2015 14:29:58 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 97c65879f -> 9e4c1b671


SQOOP-2451: Sqoop2: Findbugs: Add explicit charset to client ResourceRequest class

(Jarek Jarcec Cecho via Richard Zhou)


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

Branch: refs/heads/sqoop2
Commit: 9e4c1b671c119e15bf5585423fd0bc2c67cbe4f5
Parents: 97c6587
Author: Richard Zhou <rzhou1@apache.org>
Authored: Tue Aug 4 22:15:53 2015 +0800
Committer: Richard Zhou <rzhou1@apache.org>
Committed: Tue Aug 4 22:15:53 2015 +0800

----------------------------------------------------------------------
 .../apache/sqoop/client/request/ResourceRequest.java  | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/9e4c1b67/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java b/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java
index e7f49f4..1d41183 100644
--- a/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java
+++ b/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java
@@ -42,12 +42,18 @@ import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.InetSocketAddress;
 import java.net.URL;
+import java.nio.charset.Charset;
 import java.util.Locale;
 
 /**
  * Represents the sqoop REST resource requests
  */
 public class ResourceRequest {
+  /**
+   * Charset used for Sqoop 2 protocol
+   */
+  private static final Charset CHARSET = Charset.forName("UTF-8");
+
   private static final Logger LOG = Logger.getLogger(ResourceRequest.class);
   private DelegationTokenAuthenticatedURL.Token authToken;
 
@@ -79,7 +85,7 @@ public class ResourceRequest {
       if (method.equalsIgnoreCase(HttpMethod.PUT) || method.equalsIgnoreCase(HttpMethod.POST))
{
         conn.setDoOutput(true);
         data = data == null ? "" : data;
-        conn.setRequestProperty("Content-Length", Integer.toString(data.getBytes().length));
+        conn.setRequestProperty("Content-Length", Integer.toString(data.getBytes(CHARSET).length));
 //        Send request
         wr = new DataOutputStream(conn.getOutputStream());
         wr.writeBytes(data);
@@ -92,7 +98,7 @@ public class ResourceRequest {
       int responseCode = conn.getResponseCode();
 
       if (responseCode == HttpURLConnection.HTTP_OK) {
-        reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+        reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), CHARSET));
         String line = reader.readLine();
         while (line != null) {
           result.append(line);
@@ -115,7 +121,7 @@ public class ResourceRequest {
           ThrowableBean ex = new ThrowableBean();
 
           result = new StringBuilder();
-          reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
+          reader = new BufferedReader(new InputStreamReader(conn.getErrorStream(), CHARSET));
           String line = reader.readLine();
           while (line != null) {
             result.append(line);
@@ -129,7 +135,7 @@ public class ResourceRequest {
           throw new SqoopException(ClientError.CLIENT_0001, ex.getThrowable());
         } else {
           result = new StringBuilder();
-          reader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
+          reader = new BufferedReader(new InputStreamReader(conn.getErrorStream(), CHARSET));
           String line;
           while ((line = reader.readLine()) != null) {
             result.append(line);


Mime
View raw message