Created On:  28 September 2011

Problem:

How do I export a Test Plan using the Services Exchange with HttpClient 4?  The current documentation demonstrates this procedure with the deprecated HttpClient 3.x.

Resolution:

The code below demonstrates how to export a Test Plan from SilkCentral using the Services Exchange and HttpClient 4:

public static void exportTP(String sFileName, String sServer, int sPort, int iParentNode, String sUser, String sPassword){

    
try{
         
//Construct URL for Export Testplan service
          URL sctm = new URL("http", sServer, sPort,String.format("/servicesExchange?hid=%s&userName=%s&passWord=%s&nodeID=%d", "exportTestPlan", sUser, sPassword, iParentNode));

          HttpClient client = new DefaultHttpClient();
          HttpGet fileGet = new HttpGet(sctm.toExternalForm());

          //Execute the URL
          HttpResponse status = client.execute(fileGet);

          //Gets the entity from the response
          HttpEntity ent = status.getEntity();

         
//If something was returned
         
if(ent != null){
              
//Write the response to a file
              
FileWriter fstream = new FileWriter(sFileName);
              
BufferedWriter out = new BufferedWriter(fstream);
              
out.write(EntityUtils.toString(ent));

              
//Close the output stream
              
out.close();
          
}
    
}
    
catch(Exception e){
         
e.printStackTrace();
    
}

}


Where:
 - sFileName is the file to which the test plan is to be exported
- sServer is the SilkCentral server name or IP
- iPort is the port on which the SilkCentral server is running
- iParentNode is the test plan node to be exported
- sUser is the SilkCentral user name used to access the Services Exchange
- sPassword is the associated password