Product Documentation

Create Your First NITRO Application

Jun 14, 2016
After completing this tutorial, you will understand and be able to perform the following tasks:
  • Integrate NITRO with the IDE
  • Log in to the appliance
  • Create a load balancing virtual server (lbvserver)
  • Retrieve details of an lbvserver
  • Delete an lbvserver
  • Save the configurations on the appliance
  • Log out of the appliance
  • Debug the NITRO application

Before you begin, make sure that you have the latest NITRO SDK and that the client application satisfies the prerequisites for using the NITRO SDK.

Sample Code

For the executable code, see the <NITRO_SDK_HOME>/sample/ sample file.

To create your first NITRO application:

  1. Copy the libraries from <NITRO_SDK_HOME>/lib folder to the project classpath.
  2. Create a new class and name it MyFirstNitroApplication.
  3. Create an instance of com.citrix.netscaler.nitro.service.nitro_service class. This instance is used to perform all operations on the appliance:
    nitro_service ns_session = new nitro_service("","HTTP");
    This code establishes a connection with an appliance that has IP address and uses the HTTP protocol. Replace with the IP address of the NetScaler appliance that you have access to.
  4. Use the nitro_service instance to log in to the appliance using your credentials:
    This code logs into the appliance, with user name as admin and password as verysecret. Replace the credentials with your login credentials.
  5. Enable the load balancing feature:
    String[] features_to_be_enabled = {"lb"}; 
    This code first sets the features to be enabled in an array and then enables the LB feature.
  6. Create an instance of the class. You will use this instance to perform operations on the lbvserver.
    lbvserver new_lbvserver_obj = new lbvserver();
  7. Use the lbvserver instance to create a new lbvserver:
    This code first sets the attributes (name, IP address, service type, port, and load balancing method) of the lbvserver locally and then adds it to the appliance by using the corresponding add() method.
  8. Retrieve the details of the lbvserver you have created:
    new_lbvserver_obj = lbvserver.get(ns_session,new_lbvserver_obj.get_name()); 
    System.out.println("Name : " +new_lbvserver_obj.get_name() +"\n" +"Protocol : " +new_lbvserver_obj.get_servicetype());
    This code first retrieves the details of the lbvserver as an object from the NetScaler, extracts the required attributes (name and service type) from the object, and displays the results.
  9. Delete the lbvserver you created in the above steps:
    lbvserver.delete(ns_session, new_lbvserver_obj.get_name());
  10. Save the configurations:
  11. Log out of the appliance:

Debug the NITRO application

All NITRO exceptions are captured by the com.citrix.netscaler.nitro.exception.nitro_exception class. For a more detailed description, see Exception Handling.