Product Documentation

Create Your First NITRO Application

Sep 08, 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/MyFirstNitroApplication.java 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("10.102.29.170","HTTP");
    This code establishes a connection with an appliance that has IP address 10.102.29.170 and uses the HTTP protocol. Replace 10.102.29.170 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:
    ns_session.login("admin","verysecret");
    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"}; 
    ns_session.enable_features(features_to_be_enabled);
    This code first sets the features to be enabled in an array and then enables the LB feature.
  6. Create an instance of the com.citrix.netscaler.nitro.resource.config.lb.lbvserver 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:
    new_lbvserver_obj.set_name("MyFirstLbVServer"); 
    new_lbvserver_obj.set_ipv46("10.102.29.88"); 
    new_lbvserver_obj.set_servicetype("HTTP"); 
    new_lbvserver_obj.set_port(88); 
    new_lbvserver_obj.set_lbmethod("ROUNDROBIN"); 
    lbvserver.add(ns_session,new_lbvserver_obj);
    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:
    ns_session.save_config();
  11. Log out of the appliance:
    ns_session.logout();

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.