Cisco Cisco 3350 Mobility Services Engine Developer's Guide

Page of 224
C
ISCO 
MSE
 
API
 
S
PECI FICATI ON 
G
UI DE 
 
C
ONTEXT 
A
W ARE 
S
ERVICE  OF 
MSE,
 
R
ELEASE 
7.4
.
       
P
A G E  
215
  O F  
227  
5) 
Stub file will in turn use the Apache Axis2 jars to connect to the server and gets the 
response.
 
6)  Response contains full soap response so you can even get the individual values by 
parsing the xmlnodes.  
InstallCert Program
package com.cisco.mse; 
import java.io.*; 
import java.net.URL; 
import java.security.*; 
import java.security.cert.*; 
import javax.net.ssl.*; 
public class InstallCert { 
    public static void main(String[] args) throws Exception { 
 
String host; 
 
int port; 
 
char[] passphrase; 
 
if ((args.length == 1) || (args.length == 2))  
          { 
 
    String[] c = args[0].split(":"); 
 
    host = c[0]; 
 
    port = (c.length == 1) ? 443 : Integer.parseInt(c[1]); 
 
    String p = (args.length == 1) ? "changeit" : args[1]; 
 
    passphrase = p.toCharArray(); 
 
    } else  
           { 
 
    System.out.println("Usage: java InstallCert <host>[:port] [passphrase]"); 
 
    return; 
            } 
   
    File file = new File("jssecacerts"); 
  
    if (file.isFile() == false)  
            { 
 
    char SEP = File.separatorChar; 
 
    File dir = new File(System.getProperty("java.home") + SEP + "lib" + SEP +  
            "security"); 
 
    file = new File(dir, "jssecacerts"); 
 
    if (file.isFile() == false)  
               { 
 
 
file = new File(dir, "cacerts"); 
               } 
            } 
 
    System.out.println("Loading KeyStore " + file + "..."); 
   
    InputStream in = new FileInputStream(file); 
            KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); 
  
    ks.load(in, passphrase); 
   
    in.close(); 
 
    SSLContext context = SSLContext.getInstance("TLS"); 
 
    TrustManagerFactory tmf =        
            TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
 
    tmf.init(ks); 
 
X509TrustManager defaultTrustManager = X509TrustManager)tmf.getTrustManagers()[0];