(file) Return to TestSSLConnection.java CVS log (file) (dir) Up to [Pegasus] / pegasus-JavaCIMClient / cimclient / tests / ClientUnitTests

File: [Pegasus] / pegasus-JavaCIMClient / cimclient / tests / ClientUnitTests / TestSSLConnection.java (download)
Revision: 1.1, Thu Feb 12 18:12:27 2004 UTC (20 years, 4 months ago) by kumpf
Branch: MAIN
CVS Tags: pegasus25BeforeLicenseUpdate, SLPPERFINST-root, SLPPERFINST-branch, RELEASE_2_4_FC_CANDIDATE_1, RELEASE_2_4_1-BETA3, RELEASE_2_4_1-BETA2, RELEASE_2_4_1-BETA1, RELEASE_2_4_1, RELEASE_2_4_0-RC3, RELEASE_2_4_0-RC2, RELEASE_2_4_0, RELEASE_2_4-root, RELEASE_2_4-branch, RELEASE_2_3_2-branch-freeze, PEP217_PRE_BRANCH, PEP217_POST_BRANCH, PEP217_BRANCH, PEP214ROOT, PEP214BRANCH, PEP214-root, PEP214-branch, PEP213_SIZE_OPTIMIZATIONS, PEP-214B-root, PEG25_IBM_5_16_05, MONITOR_CONSOLIDATION_2_5_BRANCH, IBM_241_April1405, HPUX_TEST, HEAD, CQL_2_5_BRANCH, CHUNKTESTDONE_PEP140, BUG2493_BINREP-root, BUG2493_BINREP-branch
HP-BAPU: PEP125 Enhancements to Pegasus Java Client and Java Listener

//
// The Original Code is TestSSLConnection.java
//
// The Initial Developer of the Original Code:
//  Hewlett-Packard Company
//
// Revision 1.1  2002/09/15 09:36:59 bpatil
// Initial revision
//
package tests.ClientUnitTests;

import java.util.Enumeration;
import java.util.Vector;
import java.net.*;

import org.snia.wbemcmd.utils.SimpleEnum;
import org.snia.wbem.client.CIMClient;
import org.snia.wbem.cim.CIMNameSpace;
import org.snia.wbem.cim.CIMObjectPath;
import org.snia.wbem.cim.CIMClass;
import org.snia.wbem.cim.CIMProperty;
import org.snia.wbem.cim.CIMInstance;
import org.snia.wbem.cim.CIMValue;
import org.snia.wbem.cim.CIMQualifierType;
import org.snia.wbem.cim.CIMException;
import org.snia.wbemcfg.GlobalConfig;

/**
    A CIM Client example program that tests both SSL and Non-SSL(plain)
    socket connection to CIMServer. You must have CIMServer( or may be Servers 
    on same system or different systems) running in both SSL and Non-SSL mode.
    This assumes that the SSL  is on 5989 and Non-SSL is 5988.

    You may change it work with different port numbers.
 */

public class TestSSLConnection 
{

    public void example(String args[])
    {

	CIMNameSpace clientNameSpace;
	String sslHostName = "localhost";		// host for cimom
	String SSLHostName2 = "localhost";		// host for cimom
	String nameSpace = "root/cimv2";		// namespace
	CIMClient cc=null;
	int portNo=5989;
	int sslPortNo=5989;
	String hostURL;

        String myTrustManager1=null;
        String myTrustManager2="org.snia.wbemcmd.xml.DontValidateCertificate";

	//GlobalConfig.setTrustManager(myTrustManager1);
		
	if (args.length==2) {
	    sslHostName =args[0];
	    SSLHostName2=args[1];
	} else if (args.length!=0) {
	    System.err.println("TestSSLConnection [SSLHostName NonSSLHostName ]");
	    System.exit(1);
	}
	
	hostURL="https://"+sslHostName+":"+sslPortNo;
        System.err.println("Connecting to "+hostURL);
	try {

	    clientNameSpace = new CIMNameSpace(hostURL, nameSpace);  
	    cc = new CIMClient(clientNameSpace, "guest", "guest", CIMClient.XML);
	} catch (CIMException e) {
	    System.err.println("Failed to access CIMOM: "+e);
	    System.exit(1);
	}
	
	System.err.println("Client created");


     //
     // should return an instance
     //   - Gets an instance for the specified object path
     //
     //
System.err.println(" **********Enumerate Namespaces with No Deep");
     try 
     {
        //CIMObjectPath pa1=new CIMObjectPath("root", (Vector)null);
        CIMObjectPath pa1=new CIMObjectPath("", (Vector)null);
        Enumeration enum = cc.enumNameSpace(pa1, false);

        while (enum.hasMoreElements()) 
        {
	   String nsString = (String) enum.nextElement();
           System.out.println("NameSpace:"+ nsString);
        }
     cc.close(); 
     }
     catch (CIMException ce) {
	 System.err.println("Failed to fetch namespaces:"+ce);
         ce.printStackTrace();
	 //System.exit(1);
    }
     System.out.println(org.snia.wbemcfg.GlobalConfig.TrustManager + "*************SSL test done \n");

      GlobalConfig.setTrustManager(myTrustManager1);

      hostURL="https://"+SSLHostName2+":"+portNo;
      System.err.println("Connecting to "+hostURL);
      CIMClient cc2=null;

	try {

	    CIMNameSpace clientNameSpace2 = new CIMNameSpace(hostURL, nameSpace);  
	    cc2 = new CIMClient(clientNameSpace2, "guest", "guest", CIMClient.XML);
	} catch (CIMException e) {
	    System.err.println("Failed to access CIMOM: "+e);
	    System.exit(1);
	}
     //
     // should return an instance
     //   - Gets an instance for the specified object path
     //
     //
System.err.println("\n **********Enumerate Namespaces with No Deep");
     try 
     {
        CIMObjectPath pa1=new CIMObjectPath("", (Vector)null);
        Enumeration enum = cc2.enumNameSpace(pa1, false);

        while (enum.hasMoreElements()) 
        {
	   String nsString = (String) enum.nextElement();
           System.out.println("NameSpace:"+ nsString);
        }
     }
     catch (CIMException ce) {
	 System.err.println("Failed to fetch namespaces:"+ce);
	 //System.exit(1);
    }
     System.out.println(org.snia.wbemcfg.GlobalConfig.TrustManager + "*************SSL test done \n");
   }

   
   public TestSSLConnection() {
   }
   
    public static void main(String args[]){
	TestSSLConnection ea=new TestSSLConnection();
	ea.example(args);
    }
}

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2