THRIFT-3964 Unsupported mechanism type ????? due to dependency on default OS-dependent charset
Client: Java
Patch: Gary Gregory <ggregory@apache.org>

This closes #1134
diff --git a/lib/java/src/org/apache/thrift/transport/TSaslClientTransport.java b/lib/java/src/org/apache/thrift/transport/TSaslClientTransport.java
index 5aa0ccd..8122289 100644
--- a/lib/java/src/org/apache/thrift/transport/TSaslClientTransport.java
+++ b/lib/java/src/org/apache/thrift/transport/TSaslClientTransport.java
@@ -19,6 +19,7 @@
 
 package org.apache.thrift.transport;
 
+import java.io.UnsupportedEncodingException;
 import java.util.Map;
 
 import javax.security.auth.callback.CallbackHandler;
@@ -96,7 +97,12 @@
     LOGGER.debug("Sending mechanism name {} and initial response of length {}", mechanism,
         initialResponse.length);
 
-    byte[] mechanismBytes = mechanism.getBytes();
+    byte[] mechanismBytes;
+	try {
+		mechanismBytes = mechanism.getBytes("UTF-8");
+	} catch (UnsupportedEncodingException e) {
+		throw new TTransportException(e);
+	}
     sendSaslMessage(NegotiationStatus.START,
                     mechanismBytes);
     // Send initial response
diff --git a/lib/java/src/org/apache/thrift/transport/TSaslServerTransport.java b/lib/java/src/org/apache/thrift/transport/TSaslServerTransport.java
index b5b8e7d..e6c0e3e 100644
--- a/lib/java/src/org/apache/thrift/transport/TSaslServerTransport.java
+++ b/lib/java/src/org/apache/thrift/transport/TSaslServerTransport.java
@@ -19,6 +19,7 @@
 
 package org.apache.thrift.transport;
 
+import java.io.UnsupportedEncodingException;
 import java.lang.ref.WeakReference;
 import java.util.Collections;
 import java.util.HashMap;
@@ -30,6 +31,7 @@
 import javax.security.sasl.SaslException;
 import javax.security.sasl.SaslServer;
 
+import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -130,7 +132,12 @@
     }
 
     // Get the mechanism name.
-    String mechanismName = new String(message.payload);
+    String mechanismName;
+	try {
+		mechanismName = new String(message.payload, "UTF-8");
+    } catch (UnsupportedEncodingException e) {
+        throw new TTransportException("JVM DOES NOT SUPPORT UTF-8");
+      }
     TSaslServerDefinition serverDefinition = serverDefinitionMap.get(mechanismName);
     LOGGER.debug("Received mechanism name '{}'", mechanismName);
 
diff --git a/lib/java/src/org/apache/thrift/transport/TSaslTransport.java b/lib/java/src/org/apache/thrift/transport/TSaslTransport.java
index 5bfea5b..a94d9a7 100644
--- a/lib/java/src/org/apache/thrift/transport/TSaslTransport.java
+++ b/lib/java/src/org/apache/thrift/transport/TSaslTransport.java
@@ -224,7 +224,7 @@
    */
   protected TTransportException sendAndThrowMessage(NegotiationStatus status, String message) throws TTransportException {
     try {
-      sendSaslMessage(status, message.getBytes());
+      sendSaslMessage(status, message.getBytes("UTF-8"));
     } catch (Exception e) {
       LOGGER.warn("Could not send failure response", e);
       message += "\nAlso, could not send response: " + e.toString();