Metacat Client Application Programming Interface

Back | Home | Next

Metacat provides a client programming interface for communicating with the server. The client API is available in Java and Perl, but the Java interface will be described here. This interface allows a client application to easily authenticate users and perform basic metacat operations such as reading metadata and data files, inserting, updating, and deleting files, and searching for packages based on metadata matches.

To use the client, developers must include the 'metacat-client.jar', 'utilities.jar', and 'httpclient.jar' in their classpath. Then, the API methods can be used. For example, a typical session to read a document from the database might look like this:

        String metacatUrl = "http://foo.com/context/metacat";
        String username = "uid=jones,o=NCEAS,dc=ecoinformatics,dc=org";
        String password = "neverHarcodeAPasswordInCode";
        try {
            Metacat m = MetacatFactory.createMetacatConnection(metacatUrl);
            m.login(username, password);
            Reader r = m.read("testdocument.1.1");
            // Do whatever you want with Reader r
        } catch (MetacatAuthException mae) {
            handleError("Authorization failed:\n" + mae.getMessage());
        } catch (MetacatInaccessibleException mie) {
            handleError("Metacat Inaccessible:\n" + mie.getMessage());
        } catch (Exception e) {
            handleError("General exception:\n" + e.getMessage());
        }
     

The Client API is defined by the interface edu.ucsb.nceas.metacat.client.Metacat, and all operations are fully defined inthe javadoc documentation. Briefly, the API provides the following operations:


Back | Home | Next