jmeter

How to specify an OS-independent relative path?


In our JMeter project, for the JDBC configuration item's JDBC URL, we need to specify a certificate and its path as a JDBC URL, e.g.

jdbc:snowflake://xx.snowflakecomputing.com:443/?db=xx&warehouse=xx&schema=xx&role=xx&private_key_file_pwd=xx&private_key_file=C%3A%5CUsers%yy%5Crsa_key_aes.p8

where here we have URL encoded an Windows absolute path to rsa_key_aes.p8 (works locally but won't work on Unix).

What we need is a relative path and OS-independent separator which will work on the target Unix server, as well as in the local Windows JMeter GUI.

I have tried URL encoding ~/rsa_key_aes.p8, ~\rsa_key_aes.p8, etc., and putting the key in the home dir of Unix and Windows, but neither work on Windows (it can't read the file due to the path), although one may work on Unix.

I also tried:


Solution

  • I created connections in two places, and didn't edit them both.

    The solution is to create a top level "user defined variables" thus:

    Name: CERT_FILE
    Value: ${__urlencode(${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir())}/rsa_key_aes.p8)}
    

    then in each JDBC connection:

    dbc:snowflake://xx.snowflakecomputing.com:443/?db=xx&warehouse=xx&schema=xx&role=xx&private_key_file_pwd=xx&private_key_file=${CERT_PATH}
    

    Now it works on Unix and Windows.