Java Development

Main concepts

In order to access the Odilon server from a Java Application you have to include Odilon client JAR in the classpath. The interaction is managed by an instance of OdilonClient that connects to the server using the credentials: AccessKey (ie. username) and SecretKey (ie. password)

/* these are the default values for the Server */
String endpoint = "http://localhost";
int port = 9200;
String accessKey = "odilon";
String secretKey = "odilon";

/** OdilonClient is the interface, ODClient is the implementation */
OdilonClient client = new ODClient(endpoint, port, accessKey, secretKey);

/** ping can be used to check that the server is accesible, ping returns the String "ok" when the server is normal */
if (!ping.equals("ok")) {
System.out.println("ping error -> " + ping);
System.exit(1);
}

Odilon stores objects using a flat structure of containers called Buckets. A bucket is like a folder, it just contains binary objects, potentially a very large number. Every object contained by a bucket has a unique ObjectName in that bucket; therefore, the pair BucketName + ObjectName is a Unique ID for each object in Odilon.

try {
String bucketName = "bucket-demo";
/** check if the bucket exists, if not creates it */
if (client.existsBucket(bucketName))
System.out.println("bucket already exists ->" + bucketName );
else
client.createBucket(bucketName);
} catch (ODClientException e) {
System.out.println(String.valueOf(e.getHttpStatus())+ " " + e.getMessage() + " " + String.valueOf(e.getErrorCode()));
}

In addition to the binary file, an Object has Metadata (called ObjectMetadata) that is returned by some of the API calls.

Odilon allows to retrieve Objects individually by BucketName + ObjectName and also supports to list the contents of a bucket and other simple queries.

Sample programs

Create Bucket
SampleBucketCreation.java

List Buckets
SampleListBuckets.java

Upload file
Sample putObject and download ObjectMetadata
SamplePutObject.java

List all objects in a Bucket
SampleListObjects.java

Installation, Configuration and Operation

Installation, Configuration and Operation