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