Retrieve the IP address of a virtual user

 

+

Search Tips   |   Advanced Search

 

This example shows how to retrieve the local IP address of a virtual user. Retrieving IP addresses is particularly useful when virtual users are using IP aliases.

The following custom code retrieves the IP address that was assigned to a virtual user:

import java.net.InetAddress;
import com.ibm.rational.test.lt.kernel.IDataArea;
import com.ibm.rational.test.lt.kernel.services.ITestLogManager;
import com.ibm.rational.test.lt.kernel.services.IVirtualUserInfo;

public String exec(ITestExecutionServices tes, String[] args) 
{
    IVirtualUserInfo xVirtualUser = (IVirtualUserInfo) tes.findDataArea(IDataArea.VIRTUALUSER).get(IVirtualUserInfo.KEY);
    ITestLogManager xTestLogManager = tes.getTestLogManager();

    if (xVirtualUser != null) 
    {
        String localAddr = null;
        InetAddress ipAddr = xVirtualUser.getIPAddress();

        if (ipAddr != null)
            localAddr = ipAddr.toString();

        xTestLogManager.reportMessage("IPAlias address is " + (localAddr != null ? localAddr : "not set"));

        return localAddr;
    }
    else
        return ("Virtual User Info not found");
}

IP aliasing must be enabled. If not, xVirtualUser.getIPAddress() returns null.

IP aliases must be configured at the remote location.

The Log Level must be set to a value granular enough to include the IP address, so that the xTestLogManager.reportMessage() method can retrieve it. If you insert custom code at the page level, keep Log Level at the default value, Primary Test Actions.

If you insert custom code at the request level, set Log Level to Secondary Test Actions, a more granular value.