5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-10 22:13:07 +08:00

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

(Jarek Jarcec Cecho via Richard Zhou)
This commit is contained in:
Richard Zhou 2015-08-04 22:15:53 +08:00
parent 97c65879f2
commit 9e4c1b671c

View File

@ -42,12 +42,18 @@
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 @@ protected String doHttpRequest(String strURL, String method, String data) {
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 @@ protected String doHttpRequest(String strURL, String method, String data) {
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 @@ protected String doHttpRequest(String strURL, String method, String data) {
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 @@ protected String doHttpRequest(String strURL, String method, String data) {
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);