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

File: [Pegasus] / pegasus-JavaCIMClient / cimclient / tests / IndTests / sockPost.java (download)
Revision: 1.2, Thu Feb 12 18:12:28 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, 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
Changes since 1.1: +23 -11 lines
HP-BAPU: PEP125 Enhancements to Pegasus Java Client and Java Listener

//  sockPost.java
//
// The contents of this file are subject to the SNIA Public License Version 1.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
//      http://www.snia.org/resources/openSource.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Initial Developers of the Original Code
//     Bapu Patil ( bapu_patil@hp.com)
//     Hewlett-Packard Company.
//
// Contributor(s):
//
//

/**
 sockPost.java
 This is a test program to send more than one Indication to CIM Listener.
 Program uses Java Sockets to do the communication.
*/

package tests.IndTests;


import java.io.*;
import java.net.*;
import java.security.*;
import sun.misc.*;
//import javax.net.ssl.*;
import com.sun.net.ssl.*;

import java.net.HttpURLConnection.*;
import org.snia.wbemcmd.xml.Base64Encoder;

public class sockPost
{

//wbemexec [ -h hostname ] [ -p portnumber ]  [ -u username ] [ -w password ] [ -s ] [ inputfilepath ]
//wbemexec [ -h hostname ] [ -p portnumber ]  [ -s ] [ -f inputfilepath ]

  public static void main(String[] args) throws Exception 
  {
        String inputString = "";
        String input;
        String hostname=null;
        int portNumber=0;
        String username;
        String passwd;
        String xmlfile=null;
        String hostURL;
        boolean isSSL=false;
        HttpURLConnection c = null;
        HttpsURLConnection sc = null;
        

        if (args.length < 2) 
        {
            System.out.println("sockPost ");
            System.exit(1);
        }
      int i=0;
      while ( i <args.length )
      {
        if ( args[i].equals("-h") )
        {
            i++;
            hostname=args[i];
        }
        else if ( args[i].equals("-p") )
        {
            i++;
            portNumber=Integer.parseInt(args[i]);
        }
        else if ( args[i].equals("-u") )
        {
            i++;
            username=args[i];
        }
        else if ( args[i].equals("-w") )
        {
            i++;
            passwd=args[i];
        }
        else if ( args[i].equals("-f") )
        {
            i++;
            xmlfile=args[i];
        }
        else if ( args[i].equals("-s") )
        {
          isSSL = true;
        } 
        i++;
      }
      if ( isSSL == true )
      {
            //get SSL provider 
            System.setProperty("java.protocol.handler.pkgs",
                                 "com.sun.net.ssl.internal.www.protocol");
            //System.setProperty("java.protocol.handler.pkgs", "javax.net.ssl");
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
            hostURL="https://"+hostname+":"+portNumber+"/cimom";
      }
      else
      {
            hostURL="http://"+hostname+":"+portNumber+"/cimom/listen1";
      }
      Base64Encoder b64e=new Base64Encoder("guest:guest");
      String encoded=b64e.processString();

      //byte[] authCookie = "guest:guest".getBytes();
      //BASE64Encoder encoder = new BASE64Encoder();
      //String encoded = encoder.encodeBuffer(authCookie);
      System.out.println(encoded);


    BufferedReader in = new BufferedReader(new FileReader(xmlfile));
    while((input = in.readLine()) != null)
    {
       inputString = inputString + input;
    }

    in.close();

    System.out.println("hostname " + hostURL);


// C++
//CIMProtocolVersion: 1.0
//CIMMethod: SendTestIndication
//CIMObject: root/SampleProvider:RT_TestIndication
//
     try 
     {
   
    int ch;
    int bufSize;
    int maxBufSize=8192;
    byte[] inputBuf=new byte[maxBufSize];
    
        // Create a socket to the host
        InetAddress addr = InetAddress.getByName(hostname);
        Socket socket = new Socket(addr, portNumber);

        // Send header
        String path = "/cimom/listener1";
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));

        // Input Stream reader
        InputStream ins = socket.getInputStream();

       for (int j=1; j<3; j++ )
       {

         System.out.println("************Loop Number:"+ j + " BEGIN\n");
         System.out.println("Sending *********************");
         System.out.println(inputString);
         System.out.println("\n");

        wr.write("POST "+path+" HTTP/1.1\r\n");
        wr.write( "Content-type: application/xml; charset=\"utf-8\" \r\n");
        wr.write("Content-Length: "+inputString.length() + "\r\n");
        wr.write( "CIMProtocolVersion: 1.0 \r\n");
        wr.write( "CIMExport: MethodRequest \r\n");
        wr.write( "CIMExportMethod: ExportIndication\r\n");
        wr.write( "CIMObject: root/SampleProvider:RT_TestIndication \r\n");
        wr.write("\r\n");
    
        // Send input data
        wr.write(inputString);
        wr.flush();
    
        // Get response
        System.out.println("*********** Read Response Loop No#" + j);

        // CASE #2
        bufSize=ins.read(inputBuf,0,maxBufSize);
        if (bufSize<0)
        {
            System.out.println("Loop Number: "+ j + "Failed to read");
        }
        else
        {
           // System.out.println("Buffer size" + bufSize);
           String inputStr = new String(inputBuf);
           System.out.println(inputStr);
        }

        System.out.println("************Loop Number="+ j + " DONE");
 
       }
      ins.close();
      wr.close();
      socket.close();
    } 
    catch (Exception e) { e.printStackTrace(); }

  }
}


No CVS admin address has been configured
Powered by
ViewCVS 0.9.2