Cisco Cisco Security Manager 4.11 Guía Del Usuario
Cisco Security Manager 4.11 API Specification (Version 2.3)
Page 234
}
catch
(Exception ex){
System.
out
.println(ex.getMessage()); usage();}
}
public
static
void
usage(){
System.
out
.println(
"Please check the data entered in the properties file"
);
System.
out
.println(
"Usage : "
);
System.
out
.println(
"java RestClient <path_to_client.properties> [<uri>]"
);
}
}
}
9.2 Login and ping test
The following simple sample program implemented in java demonstrates a REST client that logs in to the CSM
server using the CSM API and then makes a “ping” request. Use the client.properties file as defined earlier.
server using the CSM API and then makes a “ping” request. Use the client.properties file as defined earlier.
After compiling, use the following command to run the program:
Command Prompt> java RestClient <path_to_client.properties> [<uri>]
Class
RestClient.java
/**
* Sample Program to login to the CSM Server and send a ping request
*/
import
java.io.IOException;
import
java.net.URI;
import
java.security.KeyManagementException;
import
java.security.NoSuchAlgorithmException;
import
java.security.SecureRandom;
import
java.security.cert.X509Certificate;
import
javax.net.ssl.SSLContext;
import
javax.net.ssl.TrustManager;
import
javax.net.ssl.X509TrustManager;
import
org.apache.http.HttpEntity;
import
org.apache.http.HttpResponse;
import
org.apache.http.HttpStatus;
import
org.apache.http.ParseException;
import
org.apache.http.StatusLine;
import
org.apache.http.client.ClientProtocolException;
import
org.apache.http.client.CookieStore;
import
org.apache.http.client.methods.HttpPost;
import
org.apache.http.conn.ClientConnectionManager;
import
org.apache.http.conn.scheme.Scheme;
import
org.apache.http.conn.scheme.SchemeRegistry;
import
org.apache.http.conn.ssl.SSLSocketFactory;
import
org.apache.http.entity.StringEntity;
import
org.apache.http.impl.client.DefaultHttpClient;
import
org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import
org.apache.http.params.BasicHttpParams;
import
org.apache.http.params.HttpParams;
import
org.apache.http.util.EntityUtils;
import
java.io.FileInputStream;
import
java.util.Properties;
public
class
RestClient {