swinefish
swinefish

Reputation: 561

Accessing HBase REST API through Java Applet

I am currently writing a small Java applet to access HBase data using the REST API. Accessing the data using Java is not particularly difficult, I have done this successfully. When running on a machine in my HDP cluster, the results are perfect. However when running as an applet I get no results at all. (I have chosen an applet since distributing an executable JAR is something my boss wants to avoid)

Having finally found what I believe to be the underlying issue, I have found the following runtime exception: hbase-default.xml file seems to be for an older version of HBase (null), this version is 1.1.2.2.4.0.0-169. My assumption is that this is caused by the fact that my local machine does not have HBase at all. The intention is that users will be able to view their own data from a local machine, and so I cannot expect all users to have HBase (or anything other than a browser)

My question really has two parts:

Posting my code in case I have made some significant mistake:

public class HBaseConnector extends JApplet
{
    private Cluster cluster;

    public void init()
    {
        System.out.println("Applet initialising");
        cluster = new Cluster();
        cluster.add("hbase_server", 9080);
    }

    public void start()
    {
        System.out.println("Applet starting");
        Client client = new Client(cluster);
        RemoteHTable table = new RemoteHTable(client, "table_name");
        Get get = new Get(Bytes.toBytes("key"));
        get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("Record"));
        try
        {
            Result result1 = table.get(get);
            JOptionPane.showMessageDialog(null, Bytes.toString(result1.getValue(Bytes.toBytes("f1"), Bytes.toBytes("Record"))), "Result", JOptionPane.INFORMATION_MESSAGE);

        }
        catch (Exception ex)
        {
            System.err.println("Exception occurred");
        }
    }

    public void stop()
    {
        System.out.println("Applet stopping");
    }

    public void destroy()
    {
        System.out.println("Applet destroyed");
    }
}

Upvotes: 0

Views: 206

Answers (1)

swinefish
swinefish

Reputation: 561

While I haven't been able to solve this problem for an applet itself, I managed to get the app working by moving over the a JNLP app (JNLP). Given this, I suspect the underlying problem was a permissions issue due to the fact that applets run in a sandbox. This is fine, since I am aware that most browsers are moving away from Java plugins.

Another possible cause I discovered: hbase-default.xml must be in the root folder of the jar.

Upvotes: 1

Related Questions