1
votes

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

1

1 Answers

0
votes

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();
    }
}