From 970fdc3ad9ff4672df8859639f99adb7e392fe44 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Ozawa Date: Thu, 5 Feb 2015 19:57:07 +0900 Subject: [PATCH] HDFS-7709. Fix findbug warnings in httpfs. Contributed by Rakesh R. (cherry picked from commit 20660b7a67b7f2815b1e27b98dce2b2682399505) --- .../org/apache/hadoop/fs/http/client/HttpFSUtils.java | 3 ++- .../hadoop/fs/http/server/HttpFSAuthenticationFilter.java | 8 ++++++-- .../lib/service/hadoop/FileSystemAccessService.java | 2 +- .../java/org/apache/hadoop/lib/wsrs/JSONMapProvider.java | 3 ++- .../java/org/apache/hadoop/lib/wsrs/JSONProvider.java | 3 ++- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java index e1cb81b77b7..45d9805d91d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSUtils.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.fs.http.client; +import org.apache.commons.io.Charsets; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.fs.Path; import org.json.simple.parser.JSONParser; @@ -127,7 +128,7 @@ public class HttpFSUtils { static Object jsonParse(HttpURLConnection conn) throws IOException { try { JSONParser parser = new JSONParser(); - return parser.parse(new InputStreamReader(conn.getInputStream())); + return parser.parse(new InputStreamReader(conn.getInputStream(), Charsets.UTF_8)); } catch (ParseException ex) { throw new IOException("JSON parser error, " + ex.getMessage(), ex); } diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSAuthenticationFilter.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSAuthenticationFilter.java index f0fe4c55961..004ff388c1e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSAuthenticationFilter.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSAuthenticationFilter.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.fs.http.server; +import org.apache.commons.io.Charsets; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.authentication.server.AuthenticationFilter; @@ -24,8 +25,10 @@ import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthentica import javax.servlet.FilterConfig; import javax.servlet.ServletException; -import java.io.FileReader; + +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStreamReader; import java.io.Reader; import java.util.Map; import java.util.Properties; @@ -77,7 +80,8 @@ public class HttpFSAuthenticationFilter try { StringBuilder secret = new StringBuilder(); - Reader reader = new FileReader(signatureSecretFile); + Reader reader = new InputStreamReader(new FileInputStream( + signatureSecretFile), Charsets.UTF_8); int c = reader.read(); while (c > -1) { secret.append((char)c); diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/service/hadoop/FileSystemAccessService.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/service/hadoop/FileSystemAccessService.java index 6091415e116..ccb15a30bab 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/service/hadoop/FileSystemAccessService.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/service/hadoop/FileSystemAccessService.java @@ -177,7 +177,7 @@ public class FileSystemAccessService extends BaseService implements FileSystemAc String hadoopConfDirProp = getServiceConfig().get(HADOOP_CONF_DIR, getServer().getConfigDir()); File hadoopConfDir = new File(hadoopConfDirProp).getAbsoluteFile(); - if (hadoopConfDir == null) { + if (!hadoopConfDir.exists()) { hadoopConfDir = new File(getServer().getConfigDir()).getAbsoluteFile(); } if (!hadoopConfDir.exists()) { diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONMapProvider.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONMapProvider.java index 12a2fc680bd..0809a85705c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONMapProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONMapProvider.java @@ -18,6 +18,7 @@ package org.apache.hadoop.lib.wsrs; +import org.apache.commons.io.Charsets; import org.apache.hadoop.classification.InterfaceAudience; import org.json.simple.JSONObject; @@ -55,7 +56,7 @@ public class JSONMapProvider implements MessageBodyWriter { public void writeTo(Map map, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap stringObjectMultivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { - Writer writer = new OutputStreamWriter(outputStream); + Writer writer = new OutputStreamWriter(outputStream, Charsets.UTF_8); JSONObject.writeJSONString(map, writer); writer.write(ENTER); writer.flush(); diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONProvider.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONProvider.java index 692643eec2f..15ea8e6bc8b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/JSONProvider.java @@ -18,6 +18,7 @@ package org.apache.hadoop.lib.wsrs; +import org.apache.commons.io.Charsets; import org.apache.hadoop.classification.InterfaceAudience; import org.json.simple.JSONStreamAware; @@ -55,7 +56,7 @@ public class JSONProvider implements MessageBodyWriter { public void writeTo(JSONStreamAware jsonStreamAware, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap stringObjectMultivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException { - Writer writer = new OutputStreamWriter(outputStream); + Writer writer = new OutputStreamWriter(outputStream, Charsets.UTF_8); jsonStreamAware.writeJSONString(writer); writer.write(ENTER); writer.flush(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index d21882cbcfa..34d80182b13 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -559,6 +559,8 @@ Release 2.7.0 - UNRELEASED in-memory state associated with volumes. (Lei (Eddy) Xu via Colin P. McCabe) + HDFS-7709. Fix findbug warnings in httpfs. (Rakesh R via ozawa) + Release 2.6.1 - UNRELEASED INCOMPATIBLE CHANGES