How can I set proxy settings programatically for JMeter without running it using command line

Iggy Pop Eden

I need to run Jmeter programmatically using Java from behind a proxy. The problem lies in the fact I need to do it using HTTPS .

I have read the manual at: http://jmeter.apache.org/usermanual/get-started.html I have using Jmeter for a few months now and feel comfortable with it but the problem started when I needed to switch to HTTPS.

I have tried the following: (both separately and all together)

  1. Added a HTTP Request Defaults configuration with the proxy server details
  2. Added the proxy server details to each HTTP Request
  3. Added both https.proxyHost & https.proxyPort with the proxy server details to the system.properties file found at ...\apache-jmeter-3.1\bin

I am aware of the fact that I can run JMETER using the command line with -H -P as parameters (That works) but that isn't how I work with JMeter - I only use it programmatically therefore this is not an option.

This is a snippet describing a known JAVA bug related to my problem:

The Java HTTP implementation has some limitations: There is no control over how connections are re-used. When a connection is >released by JMeter, it may or may not be re-used by the same thread. The API is best suited to single-threaded usage - various settings are defined >via system properties, and therefore apply to all connections. There is a bug in the handling of HTTPS via a Proxy (the CONNECT is not handled >correctly). See Java bugs 6226610 and 6208335. It does not support virtual hosts. It supports only the following methods: GET, POST, HEAD, OPTIONS, PUT, DELETE and >TRACE It does not support client based certificate testing with Keystore Config.

Bug link: http://bugs.java.com/view_bug.do?bug_id=6226610

I've read the bug and saw that "Java SE Development Kit 8u131" would solve this problem - so I downloaded it and alas it didn't help at all.

I would appreciate any help.

Thank,

Yigal

Dmitri T

Given you run JMeter from a separate Java program you need to pass proxy arguments to this Java program. There are several ways on how this could be done, check our Java Networking and Proxies article for comprehensive information, you seem to be a fan of doing everything through the code so just add the following lines before launching a JMeter test:

System.setProperty("http.proxyHost","your_proxy_host");
System.setProperty("http.proxyPort", "your_proxy_port");
System.setProperty("https.proxyHost","your_proxy_host");
System.setProperty("https.proxyPort","your_proxy_port");
System.setProperty("http.nonProxyHosts","");

Just in case complete code demonstrating how you can run an existing JMeter test using JMeter API through JMeter's HTTP(S) Test Script Recorder as a proxy

import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.reporters.ResultCollector;
import org.apache.jmeter.reporters.Summariser;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.collections.HashTree;

import java.io.File;

public class JMeterFromCode {

    public static void main(String[] argv) throws Exception {


        //Define JVM Proxy Settings
        System.setProperty("http.proxyHost", "localhost");
        System.setProperty("http.proxyPort", "8888");
        System.setProperty("https.proxyHost", "localhost");
        System.setProperty("https.proxyPort", "8888");
        System.setProperty("http.nonProxyHosts", "");

        // JMeter Engine
        StandardJMeterEngine jmeter = new StandardJMeterEngine();

        // Initialize Properties, logging, locale, etc.
        JMeterUtils.loadJMeterProperties("/tmp/jmeter/bin/jmeter.properties");
        JMeterUtils.setJMeterHome("/tmp/jmeter");
        JMeterUtils.initLocale();


        // Initialize JMeter SaveService
        SaveService.loadProperties();

        // Load existing .jmx Test Plan
        HashTree testPlanTree = SaveService.loadTree(new File("/tmp/jmeter/bin/test.jmx"));

        Summariser summer = null;
        String summariserName = JMeterUtils.getPropDefault("summariser.name", "summary");
        if (summariserName.length() > 0) {
            summer = new Summariser(summariserName);
        }

        ResultCollector logger = new ResultCollector(summer);
        logger.setFilename("/tmp/jmeter/test.jtl");
        testPlanTree.add(testPlanTree.getArray()[0], logger);


        // Run JMeter Test
        jmeter.configure(testPlanTree);
        jmeter.run();
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to read "Security & Privacy" settings using command line or programatically

Can I set the proxy on the command line when using org.apache.commons.httpclient?

How do I download a file using windows command line without having to input a proxy password?

How can I save a result set after running the Jmeter Test using a program (JAVA CODE)?

How can I edit local Group Policy settings using command line?

How to set settings for a subproject in sbt shell (without using project command)?

How can I change the system proxy from the command line?

How can I determine the bus clock programatically or via command line in Windows 10?

How can I pass more than 10 command line parameter to jmeter command line run?

How to set proxy settings on MacOS using python

How can I get my Square Connect location without using command line

How do I get a list of running applications by using the command line?

Can I set the GOPATH using the go command line tool?

Can I set command line arguments using the YAML metadata

How can I set position independent build setting using xcodebuild from the command line?

How can I set mac address using the command line in Ubuntu 16.04?

Jmeter - How do I see sampler data following running a test from Command line?

How can i get proxy settings with wmi?

Can I make a batch file that sets up a https proxy for IE without showing command line or window?

How can i set my app icon to one signal notification using android studio 4.2.1 programatically

How can I programatically set Path geometry using C++/WinRT + WinUI 3

In Windows 7, how to change proxy settings from command line?

How can I build an Android apk without Gradle on the command line?

How can I learn the command which will start an application in Unity's 'System Settings' from the command line?

Windows: How can I use the command line to set registry permissions

How can I set run_name in mlflow command line?

How can I tell whether chrome.proxy.settings.set is correctly setting my proxies

Using RestTemplate, how to send the request to a proxy first so I can use my junits with JMeter?

Jmeter: How can i disable specific thread group from command line