12.07.2015 Views

Ridgeline 4.0 REST API Quick Start PDF - Extreme Networks

Ridgeline 4.0 REST API Quick Start PDF - Extreme Networks

Ridgeline 4.0 REST API Quick Start PDF - Extreme Networks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using the <strong>REST</strong> <strong>API</strong>Using <strong>REST</strong> <strong>API</strong> through a Simple Java ProgramTo use the <strong>REST</strong> <strong>API</strong> through a simple Java program:1 Ensure that <strong>Ridgeline</strong> <strong>4.0</strong> is running.2 Compile the Java program (see Java Program on page 19).3 Run the Java program.The associated HTTP responses from running the Java program are stored in a file with the followingname format: DD_MM_YYYY_hh_mm_ss_Rest_Get.[xml/json]Java ProgramThe following code is for a simple Java program that you can use to access the <strong>REST</strong> <strong>API</strong>.import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.StatusLine;import org.apache.http.auth.AuthScope;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.util.EntityUtils;public class RestHttpClient {private static final String xmlExtension = ".xml";private static final String jsonExtension = ".json";private DefaultHttpClient client = new DefaultHttpClient();private String Url = null;private String hostName;private int portNumber;private String userName;private String password;public RestHttpClient(String Url, String hostName, int portNumber,String userName, String password) {if (Url == null || Url.equals(""))throw new NullPointerException("Null URL");this.Url = Url;this.hostName = hostName;this.portNumber = portNumber;this.userName = userName;this.password = password;}private String httpGet() {HttpGet httpget = new HttpGet(this.Url);String response = null;client.getCredentialsProvider().setCredentials(<strong>Ridgeline</strong> <strong>4.0</strong> <strong>REST</strong> <strong>API</strong> <strong>Quick</strong> <strong>Start</strong> 19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!