JAVA API

Top  Previous  Next

NOTE: Please see the Examples section for more commands.

Using the JAVA API is quit similar to the command line, but it enables you to do so

directly from within a JAVA program.

In this case the commands and parameters are passed to the NGAPIClient JAVA

exec method via a Properties object. Below is a use-case example that details how to

use the JAVA API from within a JAVA Program.

 

Create a sample JAVA source file,

~/apiclient/examples/MySaaSExample.java

(note the example is included in the apiclient package)

and add the following:

 

import ngasi.automationapi.NGAPIClient;

import java.io.*;

import java.util.*;

 

public class MySaaSExample {

 

public static void main(String args[])throws Exception {

       Properties properties = new Properties();

 

       //general

       properties.put("url","http://localhost:8666");

       properties.put("user","mysaasacc1");

       properties.put("password","coolgeek");

 

       //application

       properties.put("applicationname","mysaas");

       properties.put("jvmid","2");

       properties.put("email_to","customer@emailaddress.com");

 

       //install application command

       properties.put("command","installapplication");

       String result = NGAPIClient.exec(properties);

       System.out.println("Install Application Result: " + result);

 

       //Database Password command

       properties.put("command","getdbpassword");

       result = NGAPIClient.exec(properties);

       System.out.println("Application Database Password: " + result);

 

       //Database URL command

       properties.put("command","getdburl");

       result = NGAPIClient.exec(properties);

       System.out.println("Application Database URL: " + result);

 

       //Assigned IP Address command

       properties.put("command","getassignedaddress");

       result = NGAPIClient.exec(properties);

       System.out.println("Application Assigned IP Address: " + result);

 

       //Application Default User Password command

       properties.put("command","getrandomvalue");

       properties.put("randomid","1");

       result = NGAPIClient.exec(properties);

       System.out.println("Application Default User Password: " + result);

}}

 

 

Compile the JAVA source file like so (edit the paths accordingly):

 

export JAVA_PATH=/usr/java/dk1.6.0_10/bin/

 

export NG_HOME=~/mysaasacc1/apiclient

export CLASSPATH=$NG_HOME/classes/:$NG_HOME/lib/activation.jar:$NG_HOME/lib/mail.jar:$NG_HOME/lib/ngasi-axis.jar

 

$JAVA_PATH"javac" -classpath $CLASSPATH $NG_HOME/examples/MySaaSExample.java

 

 

Next, deploy the application (or other command) by running MySaaSExample like so:

 

export JAVA_PATH=/usr/java/dk1.6.0_10/bin/

 

export NG_HOME=~/mysaasacc1/apiclient

export CLASSPATH=$NG_HOME/classes/:$NG_HOME/lib/activation.jar:$NG_HOME/lib/mail.jar:$NG_HOME/lib/ngasi-axis.jar:$NG_HOME/examples/

 

$JAVA_PATH"java" MySaaSExample

 

NOTE: Please see the Examples section for more commands.