Posts: 37
Registered: ‎03-28-2017
Accepted Solution

Java - GSS initiate failed Exception, Caused by: org.apache.thrift.transport.TTransportException: GS

I am trying to retrieve records from the Hive tables. For that I have written the following connection in Java.

public static Connection getHiveConnection() throws IOException, SQLException {
    System.out.println("Preparing Hive connection1");
    Configuration conf = new Configuration();
    conf.set("", "Kerberos");

    System.setProperty("", "ip-x-x-x-x.bc9.internal");
    System.setProperty("", "ABCDEV.COM");
    UserGroupInformation.loginUserFromKeytab("username@ABCDEV.COM", "/home/username/username.keytab");
    // UserGroupInformation.setConfiguration(conf);
    System.out.println("Kerberos Connected");
    // Hive Connection
    try {
        if((hiveConnection == null) || hiveConnection.isClosed()) {
            hiveConnection = DriverManager.getConnection("jdbc:hive2://x.x.x.x.x:10500/schema;principal=hive/_HOST@ABCDEV.COM", "user", "pwd");
            return hiveConnection;
        } else {
        return hiveConnection;
    } catch (ClassNotFoundException e) {
        return null;
    } catch (SQLException e) {
        return null;

When I try to use the connection from this class, in other class like below:

Connection hiveCon = (Connection) DbManager.getHiveConnection();
PreparedStatement hive_pstmnt =  hiveCon.prepareStatement(hiveCountQuery);
ResultSet hiveRs = hive_pstmnt.executeQuery();

I am getting the exception:

Preparing Hive connection1
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
Kerberos Connected
java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://x.x.x.x.x:10500/schema;principal=hive/_HOST@ABCDEV.COM: GSS initiate failed
Caused by: org.apache.thrift.transport.TTransportException: GSS initiate failed

In the code, I have commented the line: UserGroupInformation.setConfiguration(conf); and if I remove the comments and execute the code, I get a different exception:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(
Caused by: java.lang.IllegalArgumentException: Invalid attribute value for of Kerberos
        at com.dbconnections.gphive.DbManager.getHiveConnection(

I have done kinit and generated the ticket just to make sure the ticket has valid time period. Could anyone let me know what is the mistake I am doing here so that can correct the code.

Expert Contributor
Posts: 133
Registered: ‎01-08-2018

Re: Java - GSS initiate failed Exception, Caused by: org.apache.thrift.transport.TTransportException

The error complains about the value of "". You have set it to "Kerberos" while the accepted values are "simple" and "kerberos" (all letters in lowercase).