当前位置: 首页 > 知识库问答 >
问题:

如何在Java代码中使用jmeter库添加keystore文件

潘高洁
2023-03-14

比如,我尝试过在jmeter应用程序中添加keystore.jks文件,方法是转到Options

比如有没有办法补充。jks文件通过Java代码使用jmeter库,以便实现类似的事情,我在jmeter应用程序?

这就是我尝试使用jmeter库进行java,ALIAS_VALUE,ENDPOINT_VALUE,CONTENT_PATH_VALUE,API_KEY_VALUE用于掩盖安全问题的原始值。

StandardJMeterEngine jmeterEngine = new StandardJMeterEngine();
        JMeterUtils.setJMeterHome("C:/Users/pmaiya/Downloads/apache-jmeter-5.2.1/apache-jmeter-5.2.1");
        JMeterUtils.loadJMeterProperties("C:/Users/pmaiya/Downloads/apache-jmeter-5.2.1/apache-jmeter-5.2.1/bin/jmeter.properties");
        JMeterUtils.initLocale();
        System.setProperty("javax.net.ssl.keyStore", "C:/Users/pmaiya/Documents/Zoom/identity.jks");
        System.setProperty("javax.net.ssl.keyStorePassword", "123456");

        HashTree testPlanHashTree = new HashTree();




        JmeterKeyStore.getInstance("JKS").load(new FileInputStream("C:/Users/pmaiya/Documents/Zoom/identity.jks"), "123456");
        JmeterKeyStore.DEFAULT_ALIAS_VAR_NAME.contentEquals("ALIAS_VALUE");

        JmeterKeyStore.getInstance("JKS", 0, -1, "test").load(new FileInputStream("C:/Users/pmaiya/Documents/Zoom/identity.jks"), "123456");


       SSLManager.getInstance().configureKeystore(true, 0, -1, "ALIAS_VALUE");
       SSLManager.isSSLSupported();





        // create http sampler
        HTTPSamplerProxy httpSampler = new HTTPSamplerProxy();
        httpSampler.setProtocol("HTTPS");
        httpSampler.setDomain("ENDPOINT_VALUE");
        httpSampler.setPath("CONTEXT_PATH_VALUE");
        httpSampler.setMethod("GET");
        httpSampler.setName("get call");
        httpSampler.setFollowRedirects(true);
        httpSampler.setAutoRedirects(false);
        httpSampler.setUseKeepAlive(true);
        httpSampler.setEnabled(true);
        httpSampler.setProperty(TestElement.TEST_CLASS, HTTPSampler.class.getName());
        httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());


        HeaderManager manager = new HeaderManager();
        manager.setEnabled(true);
        manager.add(new Header("apikey", "API_KEY_VALUE"));
        manager.add(new Header("Content-Type", "application/json"));
        manager.setName("headermanager"); 
        manager.setProperty(TestElement.TEST_CLASS, HeaderManager.class.getName());
        manager.setProperty(TestElement.GUI_CLASS, HeaderPanel.class.getName());





        LoopController loopController = new LoopController();
        loopController.setLoops(1);
        loopController.setFirst(true);
        loopController.setProperty(TestElement.TEST_CLASS, LoopController.class.getName());
        loopController.setProperty(TestElement.GUI_CLASS, LoopControlPanel.class.getName());
        loopController.initialize();

        //create thread group
        ThreadGroup threadGroup = new ThreadGroup();
        threadGroup.setNumThreads(1);
        threadGroup.setRampUp(1);
        threadGroup.setSamplerController(loopController);
        threadGroup.setName("get");
        threadGroup.setProperty(TestElement.TEST_CLASS, ThreadGroup.class.getName());
        threadGroup.setProperty(TestElement.GUI_CLASS, ThreadGroupGui.class.getName());

        //create test plan
        TestPlan testPlan = new TestPlan();
        testPlan.setEnabled(true);
        testPlan.setName("Test Plan");
        testPlan.setProperty(TestElement.TEST_CLASS, TestPlan.class.getName());
        testPlan.setProperty(TestElement.GUI_CLASS, TestPlanGui.class.getName());
        testPlan.setUserDefinedVariables((Arguments) new ArgumentsPanel().createTestElement());



        //Add sampler to the thread group


        HashTree threadGroupHashTree = testPlanHashTree.add(testPlan, threadGroup);
        threadGroupHashTree.add(httpSampler);
       threadGroupHashTree.add(manager);



        // Generating the JMX file
        SaveService.saveTree(testPlanHashTree, new FileOutputStream("C:/Users/pmaiya/Desktop/TestSSL.jmx"));
        jmeterEngine.configure(testPlanHashTree);
        jmeterEngine.run();            
         System.out.println("executed successfully");

共有1个答案

竺展
2023-03-14

如果您的密钥库只包含一个用于客户端加密的证书-设置javax.net.ssl.keyStorejavax.net.ssl.keyStorePassword,请确保调用以下函数

System.setProperty("javax.net.ssl.keyStore", "C:/Users/pmaiya/Documents/Zoom/identity.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "123456");

在这条线之前

JMeterUtils.loadJMeterProperties("C:/Users/pmaiya/Downloads/apache-jmeter-5.2.1/apache-jmeter-5.2.1/bin/jmeter.properties");

如果您的密钥库包含

 类似资料:
  • 问题内容: 我有一个.dll文件,必须在Java中使用。该.dll文件具有参数化方法,该方法应将类型返回为字符串。当我将参数传递给它时,我得到的消息是 这是代码… 问题答案: 只需在项目中添加引用即可。和名称空间在顶部..然后您可以访问所有dll方法。如果您使用的是Eclispe,请右键单击您的项目->然后单击“构建路径”->,然后单击“添加库”,然后单击用户库。 在这里您可以导入dll

  • 那么我该如何安装这些库来尝试新的项目呢?谢谢!

  • 问题内容: 假设我键入“ sout”,智能感知应将其扩展为“ System.out.println()”。有没有添加此类模板的方法? 问题答案: 该功能在Eclipse中称为“代码模板”。您可以使用以下方法添加模板: 窗口->首选项-> Java->编辑器->模板。 两篇好文章: 不要编写代码,生成它 自定义模板 另外,这个SO问题: 有用的Eclipse Java代码模板 已映射到,因此您可以通

  • 我正在通过添加Beanshell预处理器读取xlsx文件。当我在Eclispe中运行代码时,它工作得很好。

  • 问题内容: 我需要编写一个代码来比较Java 和Scala的性能。我很难在我的Java代码中使用Scala 。有人可以发布一个真正简单的“ hello world”示例,该示例如何使用Java代码(在文件中)创建Scala 并在其中添加100个随机数吗? PS:我非常擅长Java,但从未使用过Scala。 问题答案: 与其他方式相比,在Scala中使用Java集合要容易得多,但是由于您提出了以下要