Connect HBase via Knox using HBase Java Client on CDP

332 Views Asked by At

I need to connect to HBase via Knox using HBase Java Client. I have Knox details as following

Knox_Url: https://knox-host:port/gateway/cdp-proxy-api/hbase
Username: knox_user_name
Password: knox_password

With the below code, I am able to add the URL but not able to add the credentials.

URL url = new URL(Knox_Url);
Configuration conf = HBaseConfiguration.create();
conf.addResource(URL);

Connection con = ConnectionFactory.createConnection(conf);

I have seen other StackOverflow questions, but all they have mentioned the below properties to set in the configuration.

 public void setUp() throws IOException {
        config = HBaseConfiguration.create();
        config.set("zookeeper.znode.parent","/hbase-unsecure");
        config.set("hbase.zookeeper.quorum", ZOOKEEPER_QUORUM);
        config.set("hbase.zookeeper.property.clientPort", "2181");
        config.set("hbase.cluster.distributed", "true");
        connection = ConnectionFactory.createConnection(config);
    }

My question is there a way to use the Knox gateway details to connect to HBase and retrieve the data?

1

There are 1 best solutions below

0
On BEST ANSWER

We can use RestTemplate to connect to HBase.

Config

public RestTemplate create(){
    return new RestTemplateBuilder()
              .basicAuthentication(user, password)
              .setConnectTimeout(Duration.ofSeconds(60))
              .setReadTimeout(Duration.ofSeconds(60))
              .build();
}

Usage

String url = "https://host:port/gateway/cdp-proxy-api/hbase";
String response = config.create().getForEntity(url, String.class).getBody();