Cisco Cisco Security Manager 4.0 仕様ガイド

ページ / 217
 
 
 
  
 
Cisco Security Manager 4.4 API Specification (Version 1.1) 
 
OL- 29074-01 
Page  185
 
                    System.
out
.println(
"Hit Authorization exception"
); 
                    System.
out
.println(response); 
                    
//Do something...
 
                }
else
 
if
 (sl.getStatusCode() == HttpStatus.
SC_OK
) { 
                    System.
out
.println(
"The request is a success..."
); 
                    System.
out
.println(response); 
                    
//Do something...
 
                }
else
                    System.
out
.println(
"Some issue, Obtained HTTP status code 
:"
+sl.getStatusCode()); 
                    System.
out
.println(response); 
                    
//Do something...
 
                } 
            } 
        } 
    } 
 
    
/**
 
     * Main method processing the request/response
 
     * 
@param
 args
 
     */
 
    
public
 
static
 
void
 main(String[] args){ 
        
try
            
//Load the basic properties
 
            FileInputStream fis = 
null
            Properties prop = 
new
 Properties(); 
            fis = 
new
 FileInputStream(args[0]); 
            prop.load(fis); 
 
            String host = prop.getProperty(
"HOST"
); 
            String payload = prop.getProperty(
"XML_REQUEST"
); 
            String username = prop.getProperty(
"USER"
); 
            String password = prop.getProperty(
"PASSWORD"
); 
            String path = prop.getProperty(
"URI"
); 
            
//If URI is not passed on commandline see if its defined in properties file
 
            URI uri = 
new
 URI( (args.
length
 == 2)?args[1] : path); 
            String temp = prop.getProperty(
"LOGIN_REQUIRED"
); 
            
boolean
 autoLogin = 
false
            
if
(
null
 != temp && temp.trim().length() != 0){ 
                autoLogin = Boolean.valueOf(temp); 
            } 
 
            RestClient client = 
new
 RestClient(); 
            
if
(uri.toString().endsWith(
"login"
)){ 
                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>]"
);