NITRO: Some tips on writing program based on Java

3:34 PM
NITRO: Some tips on writing program based on Java -

So far in this series of blog NITRO, we saw various advantages and features of API and how NITRO use with NetScaler, Command Center and SDX appliance. Last (/ blogs / / 08/27/2011 nitro providing programmatic administration and monitoring via-commander center /) covered the use with Command Center. It is time for real hands on specific data and code snippets to help you write your NetScaler management programs using NetScaler API and SDK. In this blog, we will focus on how to write a Java program using NetScaler NITRO API.

We provide Java SDK for NITRO and that helps a lot as you begin to code as the most basic methods and functionality is integrated and ready for use by the import of base classes. We'll review the steps to do following simple tasks that put together can give you the first program:

  • Log in to NetScaler
  • Add LB vserver
  • Set LB vserver
  • View LB vserver
  • Clear LB vserver
  • Disconnecting NetScaler

going more step by step procedure on how we can do this

step 1 :. relevant import Java classes

  • import com.citrix.netscaler.nitro .exception.nitro_exception;
  • import com.citrix.netscaler.nitro.resource.base.base_response;
  • import com.citrix.netscaler.nitro.resource.config.lb.lbvserver;
  • import com.citrix.netscaler.nitro.service.nitro_service;

These classes provide functions for creating the session / termination, dealing with the configuration of LB vserver, handling response and exception handling. NITRO has excellent handling and exceptional media you can use "getErrorCode ()" and "getMessage ()" API to obtain key data except

Step 2 :. Connecting to NetScaler and the creation of a session

Before any functional operation using NITRO API must have an established session by making the connection to the NetScaler appliance.

  • nitro_service session = new nitro_service (ip_address, "https");
  • base_response result = session.login (username, password);

The above code provides NITRO session NetScaler with the given IP address and performs login with the username and password password given. You need to analyze and process the response to check for exceptions and errors. You can use http instead of https as a means of communication, but it will not be secure

Step 3 :. Adding LB vserver

Once you have established a valid session, it is very easy to start with a specific configuration vserver LB.

  • lbvserver lbvserver1 = new lbvserver ();
  • lbvserver1 set_name ( "lbvip1") ;.
  • lbvserver1 set_servicetype ( "http").
  • lbvserver1 set_ipv46 ( "10.10.10.11").
  • lbvserver1 set_port (80).
  • base_response result. Lbvserver = add (session lbvserver1);

We create a vserver LB object of the appropriate class so that we can use the built-in variables and methods. We put the required arguments as name, ServiceType, IP address and port before calling the function to add LB vserver on NetScaler. You must look through the response in case of error or exception

Step 4 :. Setting properties LB vserver

LB vserver has several properties that you may want to change at runtime using the update function

  • lbvserver1 set_lbmethod ( "RoundRobin") ..;
  • base_response lbvserver result = update (session lbvserver1) ;.

For the update, we use the object "lbvserver1" created in the previous step. We update the LB method is changed default "Least Connection" to "Round Robin". If you make this update in a separate session, then you will need to define the name of LB vserver start

  • lbvserver lbvserver1 = new lbvserver () ;.
  • .
  • lbvserver1 set_name ( "lbvip1");
  • lbvserver1 set_lbmethod ( "RoundRobin") ;.
  • base_response result = lbvserver. update (session lbvserver1);

well, you can set parameters remaining the same object and then call the "update" method to make one call and change all the required properties.

Step 5: Show LB vserver

Display the operation is simple and requires only a single API call

    [
  • result = lbvserver lbvserver get (session, "lbvip1") ;.

This call sends you the complete structure for the LB vserver "lbvip1." You can analyze the results and use other methods to obtain specific data.

  • result. get_name ()
    • retrieves the name of LB vserver
  • result. get_port ()
    • retrieves the port on which vserver listening
  • result. get_servicetype ()
    • recovers servicetype settings / Protocol

Similarly, there are several other methods to get specific information.

Step 6: remove LB vserver

Let us remove the LB vserver configuration we created in this example. It is again a simple operation with a single API call to remove the configuration

  • base_response lbvserver result = delete (session lbvserver1) ..

We use the same session object "lbvserver1" we created to add LB vserver and set its properties. Using the same object we can call the method "delete" to delete LB vserver configured.

So, are we done? Yeah looks like we have completed all the operations that we wanted.

What about the object "session", have we done anything about it ?? It is an active and authenticated session that can be used to communicate with the same NetScaler unless the session timeout. Hmmm ... so we need to log out and kill the session structure before we call it done. Otherwise, we are security holes to create !!

Step 7: Disconnecting NetScaler

Another simple API

  • base_response result = session logout ()

With this, you have ensured the successful disconnection of the system. Make sure you analyze the response and ensure a successful disconnection. Is it not easy to write this Java program with the help of NITRO SDK for Java :)

Previous
Next Post »

1 comment

  1. Nitro: Some Tips On Writing Program Based On Java - How Do Vpns Work >>>>> Download Now

    >>>>> Download Full

    Nitro: Some Tips On Writing Program Based On Java - How Do Vpns Work >>>>> Download LINK

    >>>>> Download Now

    Nitro: Some Tips On Writing Program Based On Java - How Do Vpns Work >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete