use of org.apache.jmeter.testelement.property.TestElementProperty in project jmeter by apache.
the class ProxyControl method createAuthorization.
/**
* Detect Header manager in subConfigs,
* Find(if any) Authorization header
* Construct Authentication object
* Removes Authorization if present
*
* @param subConfigs {@link TestElement}[]
* @param sampler {@link HTTPSamplerBase}
* @return {@link Authorization}
*/
private Authorization createAuthorization(final TestElement[] testElements, HTTPSamplerBase sampler) {
Header authHeader;
Authorization authorization = null;
// Iterate over subconfig elements searching for HeaderManager
for (TestElement te : testElements) {
if (te instanceof HeaderManager) {
// headers should only contain the correct classes
@SuppressWarnings("unchecked") List<TestElementProperty> headers = (ArrayList<TestElementProperty>) ((HeaderManager) te).getHeaders().getObjectValue();
for (Iterator<?> iterator = headers.iterator(); iterator.hasNext(); ) {
TestElementProperty tep = (TestElementProperty) iterator.next();
if (tep.getName().equals(HTTPConstants.HEADER_AUTHORIZATION)) {
//Construct Authorization object from HEADER_AUTHORIZATION
authHeader = (Header) tep.getObjectValue();
//$NON-NLS-1$
String[] authHeaderContent = authHeader.getValue().split(" ");
String authType;
String authCredentialsBase64;
if (authHeaderContent.length >= 2) {
authType = authHeaderContent[0];
authCredentialsBase64 = authHeaderContent[1];
authorization = new Authorization();
try {
authorization.setURL(sampler.getUrl().toExternalForm());
} catch (MalformedURLException e) {
log.error("Error filling url on authorization, message:" + e.getMessage(), e);
//$NON-NLS-1$
authorization.setURL("${AUTH_BASE_URL}");
}
// if HEADER_AUTHORIZATION contains "Basic"
// then set Mechanism.BASIC_DIGEST, otherwise Mechanism.KERBEROS
authorization.setMechanism(authType.equals(BASIC_AUTH) || authType.equals(DIGEST_AUTH) ? AuthManager.Mechanism.BASIC_DIGEST : AuthManager.Mechanism.KERBEROS);
if (BASIC_AUTH.equals(authType)) {
String authCred = new String(Base64.decodeBase64(authCredentialsBase64));
//$NON-NLS-1$
String[] loginPassword = authCred.split(":");
authorization.setUser(loginPassword[0]);
authorization.setPass(loginPassword[1]);
} else {
// Digest or Kerberos
//$NON-NLS-1$
authorization.setUser("${AUTH_LOGIN}");
//$NON-NLS-1$
authorization.setPass("${AUTH_PASSWORD}");
}
}
// remove HEADER_AUTHORIZATION from HeaderManager
// because it's useless after creating Authorization object
iterator.remove();
}
}
}
}
return authorization;
}
use of org.apache.jmeter.testelement.property.TestElementProperty in project jmeter by apache.
the class JMSProperties method addJmsProperty.
/**
* Add a new argument.
*
* @param arg
* the new argument
*/
public void addJmsProperty(JMSProperty arg) {
TestElementProperty newArg = new TestElementProperty(arg.getName(), arg);
if (isRunningVersion()) {
this.setTemporary(newArg);
}
getProperties().addItem(newArg);
}
use of org.apache.jmeter.testelement.property.TestElementProperty in project jmeter by apache.
the class LdapConfigGui method modifyTestElement.
/**
* Modifies a given TestElement to mirror the data in the gui components.
*
* @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
*/
@Override
public void modifyTestElement(TestElement element) {
element.clear();
configureTestElement(element);
element.setProperty(LDAPSampler.SERVERNAME, servername.getText());
element.setProperty(LDAPSampler.PORT, port.getText());
element.setProperty(LDAPSampler.ROOTDN, rootdn.getText());
element.setProperty(new BooleanProperty(LDAPSampler.USER_DEFINED, userDefined.isSelected()));
if (addTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.ADD));
element.setProperty(new StringProperty(LDAPSampler.BASE_ENTRY_DN, add.getText()));
element.setProperty(new TestElementProperty(LDAPSampler.ARGUMENTS, tableAddPanel.createTestElement()));
}
if (modifyTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.MODIFY));
element.setProperty(new StringProperty(LDAPSampler.BASE_ENTRY_DN, modify.getText()));
element.setProperty(new TestElementProperty(LDAPSampler.ARGUMENTS, tableModifyPanel.createTestElement()));
}
if (deleteTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.DELETE));
element.setProperty(new StringProperty(LDAPSampler.DELETE, delete.getText()));
}
if (searchTest.isSelected()) {
element.setProperty(new StringProperty(LDAPSampler.TEST, LDAPSampler.SEARCHBASE));
element.setProperty(new StringProperty(LDAPSampler.SEARCHBASE, searchbase.getText()));
element.setProperty(new StringProperty(LDAPSampler.SEARCHFILTER, searchfilter.getText()));
}
}
use of org.apache.jmeter.testelement.property.TestElementProperty in project jmeter by apache.
the class LDAPArguments method addArgument.
/**
* Add a new argument.
*
* @param arg
* the new argument
*/
public void addArgument(LDAPArgument arg) {
TestElementProperty newArg = new TestElementProperty(arg.getName(), arg);
if (isRunningVersion()) {
this.setTemporary(newArg);
}
getArguments().addItem(newArg);
}
use of org.apache.jmeter.testelement.property.TestElementProperty in project jmeter by apache.
the class UrlConfigGui method modifyTestElement.
/**
* Save the GUI values in the sampler.
*
* @param element {@link TestElement} to modify
*/
public void modifyTestElement(TestElement element) {
boolean useRaw = postContentTabbedPane.getSelectedIndex() == tabRawBodyIndex;
Arguments args;
if (useRaw) {
args = new Arguments();
String text = postBodyContent.getText();
/*
* Textfield uses \n (LF) to delimit lines; we need to send CRLF.
* Rather than change the way that arguments are processed by the
* samplers for raw data, it is easier to fix the data.
* On retrieval, CRLF is converted back to LF for storage in the text field.
* See
*/
HTTPArgument arg = new HTTPArgument("", text.replaceAll("\n", "\r\n"), false);
arg.setAlwaysEncoded(false);
args.addArgument(arg);
} else {
args = (Arguments) argsPanel.createTestElement();
HTTPArgument.convertArgumentsToHTTP(args);
if (showFileUploadPane) {
filesPanel.modifyTestElement(element);
}
}
element.setProperty(HTTPSamplerBase.POST_BODY_RAW, useRaw, HTTPSamplerBase.POST_BODY_RAW_DEFAULT);
element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
element.setProperty(HTTPSamplerBase.PORT, port.getText());
element.setProperty(HTTPSamplerBase.PROTOCOL, protocol.getText());
element.setProperty(HTTPSamplerBase.CONTENT_ENCODING, contentEncoding.getText());
element.setProperty(HTTPSamplerBase.PATH, path.getText());
if (notConfigOnly) {
element.setProperty(HTTPSamplerBase.METHOD, method.getText());
element.setProperty(new BooleanProperty(HTTPSamplerBase.FOLLOW_REDIRECTS, followRedirects.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.AUTO_REDIRECTS, autoRedirects.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.USE_KEEPALIVE, useKeepAlive.isSelected()));
element.setProperty(new BooleanProperty(HTTPSamplerBase.DO_MULTIPART_POST, useMultipartForPost.isSelected()));
element.setProperty(HTTPSamplerBase.BROWSER_COMPATIBLE_MULTIPART, useBrowserCompatibleMultipartMode.isSelected(), HTTPSamplerBase.BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT);
}
}
Aggregations