Friday, May 29, 2015

Convert Java key store certificate from ".jks" to LoadRunner ".pem" format.


This article show you step by step approach how to convert ".jks" to ".pem". Two different tools will be used for the process and there are two steps... 
Keytool – It a Java key and certificate management utility. It allows users to manage their own public/private key pairs and certificates. It comes with Java/JRE/JDK and almost all computer has JRE.
OpenSSL - It comes with LoadRunner. If not can be downloaded from internet (https://www.openssl.org). 

First, convert JKS to PKCS12 format:

  • Save the ".jks" file in your computer. My ".jks" file name is "demo.jks" and saved in "C:\temp".
  • Open the command prompt ("Start >> All Programs >> Accessories >> Command Prompt" or "Start >> Run and type 'cmd' and hit enter")
  • Navigate to Java or JRE bin folder on the command prompt. On the command prompt type "Java\jre1.x.x_xx\bin". It could be different on your computer.
  • On the command prompt, type following and it will create another file with “.p12” extension. Make sure to replace file and folder path.
keytool -importkeystore -srckeystore "C:\Temp\demo.jks" -srcalias cpwxc_test -destkeystore "C:\Temp\demo.p12" -deststoretype PKCS12
  • It prompts you to enter password, enter the password. Remember this password, you will need it on the next step.

Next, convert PKCS12 to PEM format:

On the command prompt, go to the OpenSSL location and type following text and it will create a file with “.pem” extention.
openssl pkcs12 -in "C:\Temp\demo.p12" -out "C:\Temp\demo.pem"
It will ask you to enter password. Enter the password you entered in the previous step.

>>> Let me know what you think in the comment. Any constructive feedback will be appreciated & will helpful to others…

Tuesday, April 2, 2013

How to install and configure MySQL Connector/J to java

MySQL Connector is JDBC implementation for communicating with MySQL.

Test Environment

  • OS: Windows 7 64-bit
  • Java: 1.7
  • MySQL: 5.5

Installing Connector/J

  • Go to the MySQL Drivers page.
  • Click Download link next to "JDBC Driver for MySQL (Connector/J)".
  • You can download Connector/J package  either the compressed TAR archive or ZIP archive. Here I will show only the ZIP archive.
  • After download, save the zip file in the C:\Temp.
  • Extract ZIP file using any Zip file extractor tool such as 7-Zip, WinZip.
  • In my case, I save the output folder in "C:\MySQL Related\mysql-connector-java-version"

Configuring Driver & Connector/J CLASSPATH

  • Once you extract and save the output files in specific folder (see Installing Connector/J section), you set the CLASSPATH using environment variable or using -cp command.
  • Using Environment Variable:
    • Right click My Computer, click properties.
    • Click the advanced tab.
    • Click the Environment Variables button at the bottom of the tab.
    • Under user variables, add a new variable named "CLASSPATH".
    • Set "CLASSPATH" to "C:\Folder Path\mysql-connectorjava-
    • version-bin.jar" and click "OK".
    • Click "OK" in "Environment Variables" and "System Properties" windows.

How to write LoadRunner/VuGen Output to external file

Compatibility: This script will work in all version of LoadRunner/VuGen
Following C lanuage function in LoadRunner will be used in this articles:
  • long fopen( const char *filename, const char *access_mode ); //To open file
  • int fprintf( FILE *file_pointer, const char *format_string [, args ] ); //To write formatted output
Step 1: Define the file name to be used or created or to be added. Make sure to replace one backslash with two backslashes. Set access mode and file stream.
//Name and location of a file to be open or created.      
char * filename = "c:\\temp\\logfile.txt";     
/*** access mode ***;      
* r or r+ = open for reading      
* w or w+ = open for writing      
* a or a+ = open for appending      
* t = text mode      
* b = binary mode      
* where the "+" sign indicates that the file must already exist  *******************/      
// Open the file with append mode      
char * access_mode = "a+";  
//File pointer  long file_stream;
Step 2: Open the file with an access mode. If it can't open LoadRunner error function will display error.
if ((file_stream = fopen(filename, access_mode)) == NULL)  { 
lr_error_message ("Cannot open or create %s", filename);   
return -1;
}
Step 3: Write message to output file
fprintf(file_stream, "This is the message to output file");
Step 4: fclose(file_stream); Complete Source Code:
//Name and location of a file to be open or created.     
char * filename = "c:\\temp\\logfile.txt";     
/*** access mode ***      
* r or r+ = open for reading      
* w or w+ = open for writing      
* a or a+ = open for appending      
* t = text mode      
* b = binary mode      
* where the "+" sign indicates that the file must already exist      *******************/     
// Open the file with append mode     
char * access_mode = "a+";     
//File pointer     
long file_stream;          
if ((file_stream = fopen(filename, access_mode)) == NULL) {         
lr_error_message ("Cannot open or create %s", filename);         
return -1;     
}     
//Write message to output file     
fprintf(file_stream, "This is the message to output file");          
//Close the file stream     
fclose(file_stream);



How to generate GUID in LoadRunner

How to generate GUID in LoadRunner
Today I came accross a SOAP request that uses a java function (java.util.UUID.randomUUID()) to generate random number. In very high level, this java function generate strong pseudo random number using randomUUID() function from java util library. Here is the part of the SOAP request with Java funtion:
   
   
      
         
            
               ${=java.util.UUID.randomUUID()}
               ABC
            
         
      
   

If I need to generate this random number using Java, that is easy. Here is the example:
import java.util.*;

public class UUIDGenerator {
   public static void main(String[] args) {
      // creating UUID      
      UUID uid = UUID.fromString("12300000-afcd-11bd-b23e-10b96e4ef00d");           
      // checking the value of random UUID
      System.out.println("Randomly generated UUID value: "+uid.randomUUID());    
   }    
}
Output would be:
Randomly generated UUID value: 69b9c547-2278-45d0-a632-b627e30119aa
But the problem was to convert this solution to LoadRunner. Thanks to Scotte Moore for coming up with the creative solution. Here are the steps:
  • Create a test using the protocols that generate C scripts.
  • Download the "ole32.dll" file from online (If you google it, you should be able to find it)
  • Save that "ole32.dll" file into the test folder so that lr_load_dll() function can load this dll
  • Finally, you can either create seperate functions to generate GUID/randomUUID or can embaded in the action that will use it.
Action()
{
    lr_guid_gen();
 return 0;
}


int lr_guid_gen()
{
    typedef struct _GUID
    {
        unsigned long Data1;
        unsigned short Data2;
        unsigned short Data3;
        unsigned char Data4[8];
    } GUID;
 
    GUID m_guid;
    char buf[50];
    char bufx[50];
 
    lr_load_dll ("ole32.dll");
 
    CoCreateGuid(&m_guid);
 
    sprintf (buf, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
    m_guid.Data1, m_guid.Data2, m_guid.Data3,
    m_guid.Data4[0], m_guid.Data4[1], m_guid.Data4[2], m_guid.Data4[3],
    m_guid.Data4[4], m_guid.Data4[5], m_guid.Data4[6], m_guid.Data4[7]);
 
    lr_save_string(buf, "lrGUID");
    lr_output_message(lr_eval_string(buf));
    return 0;
}
Output would be similar to following:
Action.c(54): {1FC2EFD0-3887-45D7-9432-5682802E6D82}
I am open for comments. How others solve this problem.

How to convert Internet Explorer (IE) Desktop version to mobile version?

Tested on: IE7
More and more of our applications are moving into mobile site. In order for any testing tool such as LoadRunner or Neoload to record mobile scripts, you need to convert the browser to mobile browser. Here is how to do it.
Follow the below steps to change your Internet Explorer to Mobile Browser:
  • Step 1: Go to “Start >> Run”, type “regedit” and hit {ENTER}
  • Step 2: Go to “HKEY_LOCAL_MACHINE >> SOFTWARE >> Microsoft >> Windows >> Internet Settings >> 5.0 >> User Agent”
  • Step 3: Create “String Value” name “Version”
  • Step 4: Modify Value to “Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; MB860 Build/4.5.91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1”
  • Step 5: Close “Registry Editor” and close any open “Internet Explorer” browser.
Now, test it out…
  • Step 1: Open Internet Explorer
  • Step 2: type “http://en.wikipedia.org/”and hit {ENTER}
  • Step 3: You will browser’s address bar changed to mobile site

Counters to analyze on Windows environment during performance testing

Windows environment contains hundred different counters. However, following below main counters one can get good picture of the system:
Memory:
  • Pages/sec: Detects the Pages/sec swap rate. The pages/sec rate is the speed at which the pages are read from or written to the disk when resolving hardware page faults. A hardware page fault occurs when a process has to access code on a physical disk because it cannot be accessed in the memory.
  • Available Megabytes: Indicates how much physical memory remains after the working sets of running processes and the cache have been served.
Processor:
  • Processor Time \%: CPU activity in percentage.
System:
  • Processor Queue Length: This counter displays the number of threads waiting to be executed in the queue that is shared by all processors on the system.
Physical Disk:
  • Disk Time \%: Percentage of elapsed time spent by the selected physical disk drive executing read or write requests.
Network Interface:
  • Packets/sec.: Rate at which packets are sent and received on the network interface.

Convert .p12 to .pem

C:\Program Files (x86)\HP\LoadRunner\bin\openssl pkcs12 -in CPWXC_test -out CPWXC_test.pem