Cisco Cisco Security Manager 4.5 Guia De Especificação

Página de 217
 
 
 
  
 
Cisco Security Manager 4.4 API Specification (Version 1.1) 
 
OL- 29074-01 
Page  162
 
                client.doPost(uri, payload, host, 
false
); 
            }
else
                
//Step 1 :
 
                
if
(autoLogin){ 
                    String login_payload = 
"<?xml version=\"1.0\" encoding=\"UTF-
8\"?><csm:loginRequest 
xmlns:csm=\"csm\"><protVersion>1.0</protVersion><reqId>123</reqId><username>"
+username+
"</usernam
e><password>"
+password+
"</password></csm:loginRequest>"
                    client.doPost(
new
 URI(
"https://"
+host+
"/nbi/login"
), login_payload, host, 
false
); 
                } 
                
//Step 2:
 
                client.doPost(uri, payload, host, 
true
); 
            } 
        }
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>]"
); 
    } 
 
8.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. 
 
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;