Search in sources :

Example 1 with KeystoreConfig

use of org.apache.jmeter.config.KeystoreConfig in project jmeter by apache.

the class HTTPSamplerBase method setKeystoreConfig.

public void setKeystoreConfig(KeystoreConfig value) {
    KeystoreConfig mgr = getKeystoreConfig();
    if (mgr != null && log.isWarnEnabled()) {
        log.warn("Existing KeystoreConfig {} superseded by {}", mgr.getName(), value.getName());
    }
    setKeystoreConfigProperty(value);
}
Also used : KeystoreConfig(org.apache.jmeter.config.KeystoreConfig)

Example 2 with KeystoreConfig

use of org.apache.jmeter.config.KeystoreConfig in project jmeter by apache.

the class ParseCurlCommandAction method createKeystoreConfiguration.

private KeystoreConfig createKeystoreConfiguration() {
    KeystoreConfig keystoreConfig = new KeystoreConfig();
    keystoreConfig.setProperty(TestElement.GUI_CLASS, TestBeanGUI.class.getName());
    keystoreConfig.setProperty(TestElement.NAME, "Keystore Configuration");
    keystoreConfig.setProperty(TestElement.COMMENTS, getDefaultComment());
    return keystoreConfig;
}
Also used : TestBeanGUI(org.apache.jmeter.testbeans.gui.TestBeanGUI) KeystoreConfig(org.apache.jmeter.config.KeystoreConfig)

Example 3 with KeystoreConfig

use of org.apache.jmeter.config.KeystoreConfig in project jmeter by apache.

the class ParseCurlCommandAction method createSampler.

/**
 * @param request    {@link Request}
 * @param commentText
 * @return {@link HTTPSamplerProxy}
 * @throws MalformedURLException
 */
private HTTPSamplerProxy createSampler(Request request, String commentText) throws MalformedURLException {
    HTTPSamplerProxy httpSampler = (HTTPSamplerProxy) HTTPSamplerFactory.newInstance(HTTPSamplerFactory.DEFAULT_CLASSNAME);
    httpSampler.setProperty(TestElement.GUI_CLASS, HttpTestSampleGui.class.getName());
    httpSampler.setProperty(TestElement.NAME, "HTTP Request");
    if (!commentText.isEmpty()) {
        // NOSONAR
        httpSampler.setProperty(TestElement.COMMENTS, commentText);
    } else {
        httpSampler.setProperty(TestElement.COMMENTS, getDefaultComment());
    }
    // NOSONAR
    URL url = new URL(request.getUrl());
    httpSampler.setProtocol(url.getProtocol());
    if (url.getPort() != -1) {
        httpSampler.setPort(url.getPort());
    }
    String path = url.getPath();
    if (StringUtils.isNotEmpty(url.getQuery())) {
        path += "?" + url.getQuery();
    }
    httpSampler.setPath(path);
    httpSampler.setDomain(url.getHost());
    httpSampler.setUseKeepAlive(request.isKeepAlive());
    httpSampler.setFollowRedirects(true);
    httpSampler.setMethod(request.getMethod());
    HeaderManager headerManager = createHeaderManager(request);
    httpSampler.addTestElement(headerManager);
    configureTimeout(request, httpSampler);
    createProxyServer(request, httpSampler);
    if (request.getInterfaceName() != null) {
        httpSampler.setIpSourceType(1);
        httpSampler.setIpSource(request.getInterfaceName());
    }
    if (!"GET".equals(request.getMethod()) && request.getPostData() != null) {
        Arguments arguments = new Arguments();
        httpSampler.setArguments(arguments);
        httpSampler.addNonEncodedArgument("", request.getPostData(), "");
    }
    if (!request.getFormData().isEmpty() || !request.getFormStringData().isEmpty()) {
        setFormData(request, httpSampler);
        httpSampler.setDoMultipart(true);
    }
    if (CERT.equals(request.getCaCert())) {
        KeystoreConfig keystoreConfig = createKeystoreConfiguration();
        httpSampler.addTestElement(keystoreConfig);
    }
    return httpSampler;
}
Also used : HTTPSamplerProxy(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy) HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) KeystoreConfig(org.apache.jmeter.config.KeystoreConfig) Arguments(org.apache.jmeter.config.Arguments) URL(java.net.URL) HeaderManager(org.apache.jmeter.protocol.http.control.HeaderManager)

Example 4 with KeystoreConfig

use of org.apache.jmeter.config.KeystoreConfig in project jmeter by apache.

the class ParseCurlCommandAction method addToTestPlan.

private void addToTestPlan(final JMeterTreeNode currentNode, Request request, String statusText) throws MalformedURLException {
    final HTTPSamplerProxy sampler = createSampler(request, statusText);
    JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
    JMeterUtils.runSafe(true, () -> {
        try {
            boolean canAddAuthManagerInHttpRequest = false;
            boolean canAddDnsServer = false;
            boolean canAddDnsResolver = false;
            if (!request.getAuthorization().getUser().isEmpty()) {
                JMeterTreeNode jMeterTreeNodeAuth = findFirstNodeOfType(AuthManager.class);
                if (jMeterTreeNodeAuth == null) {
                    AuthManager authManager = new AuthManager();
                    createAuthManager(request, authManager);
                    treeModel.addComponent(authManager, currentNode);
                } else {
                    AuthManager authManager = (AuthManager) jMeterTreeNodeAuth.getTestElement();
                    if (canUpdateAuthManagerInThreadGroup(request, authManager)) {
                        createAuthManager(request, authManager);
                    } else {
                        canAddAuthManagerInHttpRequest = canAddAuthManagerInHttpRequest(request, authManager);
                    }
                }
            }
            if (!request.getDnsServers().isEmpty()) {
                DNSCacheManager dnsCacheManager = findNodeOfTypeDnsCacheManagerByType(false);
                if (dnsCacheManager == null) {
                    dnsCacheManager = new DNSCacheManager();
                    createDnsServer(request, dnsCacheManager);
                    treeModel.addComponent(dnsCacheManager, currentNode);
                } else {
                    canAddDnsServer = canAddDnsServerInHttpRequest(request, dnsCacheManager);
                }
            }
            if (request.getDnsResolver() != null) {
                DNSCacheManager dnsCacheManager = findNodeOfTypeDnsCacheManagerByType(true);
                if (dnsCacheManager == null) {
                    dnsCacheManager = new DNSCacheManager();
                    createDnsResolver(request, dnsCacheManager);
                    treeModel.addComponent(dnsCacheManager, currentNode);
                } else {
                    canAddDnsResolver = canAddDnsResolverInHttpRequest(request, dnsCacheManager);
                }
            }
            if (!request.getCookies(request.getUrl()).isEmpty() || !request.getFilepathCookie().isEmpty() || (!request.getCookieInHeaders(request.getUrl()).isEmpty() && uploadCookiesCheckBox.isSelected())) {
                JMeterTreeNode jMeterTreeNodeCookie = findFirstNodeOfType(CookieManager.class);
                if (jMeterTreeNodeCookie == null) {
                    CookieManager cookieManager = new CookieManager();
                    createCookieManager(cookieManager, request);
                    treeModel.addComponent(cookieManager, currentNode);
                } else {
                    CookieManager cookieManager = (CookieManager) jMeterTreeNodeCookie.getTestElement();
                    createCookieManager(cookieManager, request);
                }
            }
            HeaderManager headerManager = sampler.getHeaderManager();
            KeystoreConfig keystoreConfig = sampler.getKeystoreConfig();
            final JMeterTreeNode newNode = treeModel.addComponent(sampler, currentNode);
            treeModel.addComponent(headerManager, newNode);
            if (CERT.equals(request.getCaCert())) {
                treeModel.addComponent(keystoreConfig, newNode);
            }
            if (canAddAuthManagerInHttpRequest) {
                AuthManager authManager = new AuthManager();
                createAuthManager(request, authManager);
                treeModel.addComponent(authManager, newNode);
            }
            if (canAddDnsServer) {
                DNSCacheManager dnsCacheManager = new DNSCacheManager();
                createDnsServer(request, dnsCacheManager);
                treeModel.addComponent(dnsCacheManager, newNode);
            }
            if (canAddDnsResolver) {
                DNSCacheManager dnsCacheManager = new DNSCacheManager();
                createDnsResolver(request, dnsCacheManager);
                treeModel.addComponent(dnsCacheManager, newNode);
            }
        } catch (IllegalUserActionException ex) {
            LOGGER.error("Error placing sampler", ex);
            JMeterUtils.reportErrorToUser(ex.getMessage());
        }
    });
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) HTTPSamplerProxy(org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) KeystoreConfig(org.apache.jmeter.config.KeystoreConfig) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) DNSCacheManager(org.apache.jmeter.protocol.http.control.DNSCacheManager) CookieManager(org.apache.jmeter.protocol.http.control.CookieManager) HeaderManager(org.apache.jmeter.protocol.http.control.HeaderManager)

Aggregations

KeystoreConfig (org.apache.jmeter.config.KeystoreConfig)4 HeaderManager (org.apache.jmeter.protocol.http.control.HeaderManager)2 HTTPSamplerProxy (org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy)2 URL (java.net.URL)1 Arguments (org.apache.jmeter.config.Arguments)1 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)1 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)1 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)1 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)1 CookieManager (org.apache.jmeter.protocol.http.control.CookieManager)1 DNSCacheManager (org.apache.jmeter.protocol.http.control.DNSCacheManager)1 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)1 TestBeanGUI (org.apache.jmeter.testbeans.gui.TestBeanGUI)1