use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class ArgumentsPanel method configure.
/**
* A newly created component can be initialized with the contents of a Test
* Element object by calling this method. The component is responsible for
* querying the Test Element object for the relevant information to display
* in its GUI.
*
* @param el the TestElement to configure
*/
@Override
public void configure(TestElement el) {
super.configure(el);
if (el instanceof Arguments) {
tableModel.clearData();
for (JMeterProperty jMeterProperty : (Arguments) el) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
tableModel.addRow(arg);
}
}
checkButtonsStatus();
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class BackendListenerGui method actionPerformed.
/**
* Handle action events for this component. This method currently handles
* events for the classname combo box.
*
* @param event
* the ActionEvent to be handled
*/
@Override
public void actionPerformed(ActionEvent event) {
if (event.getSource() == classnameCombo) {
String className = ((String) classnameCombo.getSelectedItem()).trim();
try {
BackendListenerClient client = (BackendListenerClient) Class.forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance();
Arguments currArgs = new Arguments();
argsPanel.modifyTestElement(currArgs);
Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
Arguments newArgs = new Arguments();
Arguments testParams = null;
try {
testParams = client.getDefaultParameters();
} catch (AbstractMethodError e) {
log.warn("BackendListenerClient doesn't implement " + "getDefaultParameters. Default parameters won't " + "be shown. Please update your client class: {}", className);
}
if (testParams != null) {
for (JMeterProperty jMeterProperty : testParams.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String name = arg.getName();
String value = arg.getValue();
// values that they did in the original test.
if (currArgsMap.containsKey(name)) {
String newVal = currArgsMap.get(name);
if (newVal != null && newVal.length() > 0) {
value = newVal;
}
}
newArgs.addArgument(name, value);
}
}
argsPanel.configure(newArgs);
} catch (Exception e) {
log.error("Error getting argument list for {}", className, e);
}
}
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class MultipartUrlConfigTest method testParseArgumentsCRLF.
@Test
public void testParseArgumentsCRLF() {
String queryString = "Content-Disposition: form-data; name=\"aa\"\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "\r\n" + "bb\r\n" + "--7d159c1302d0y0\r\n" + "Content-Disposition: form-data; name=\"xx\"\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "\r\n" + "yy\r\n" + "--7d159c1302d0y0\r\n" + "Content-Disposition: form-data; name=\"abc\"\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "\r\n" + "xyz \r\n" + "xyz \r\n" + "--7d159c1302d0y0\r\n" + "Content-Disposition: form-data; name=\"param1\"; filename=\"file1\"\r\n" + "Content-Type: text/plain\r\n" + "Content-Transfer-Encoding: binary\r\n" + "\r\n" + "file content\r\n" + "\r\n";
MultipartUrlConfig muc = new MultipartUrlConfig("7d159c1302d0y0");
muc.parseArguments(queryString);
HTTPFileArgs files = muc.getHTTPFileArgs();
assertEquals(1, files.getHTTPFileArgCount());
HTTPFileArg file = (HTTPFileArg) files.iterator().next().getObjectValue();
assertEquals("file1", file.getPath());
assertEquals("param1", file.getParamName());
assertEquals("text/plain", file.getMimeType());
Arguments args = muc.getArguments();
assertEquals(3, args.getArgumentCount());
Argument arg = args.getArgument(0);
assertEquals("aa", arg.getName());
assertEquals("bb", arg.getValue());
arg = args.getArgument(1);
assertEquals("xx", arg.getName());
assertEquals("yy", arg.getValue());
arg = args.getArgument(2);
assertEquals("abc", arg.getName());
assertEquals("xyz \r\nxyz ", arg.getValue());
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class MultipartUrlConfigTest method testParseArgumentsLF.
// TODO - should LF-only EOL be allowed?
@Test
public void testParseArgumentsLF() {
String queryString = "Content-Disposition: form-data; name=\"aa\"\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 8bit\n" + "\n" + "bb\n" + "--7d159c1302d0y0\n" + "Content-Disposition: form-data; name=\"xx\"\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 8bit\n" + "\n" + "yy\n" + "--7d159c1302d0y0\n" + "Content-Disposition: form-data; name=\"abc\"\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 8bit\n" + "\n" + "xyz \n" + "xyz \n" + "--7d159c1302d0y0\n" + "Content-Disposition: form-data; name=\"param1\"; filename=\"file1\"\n" + "Content-Type: text/plain\n" + "Content-Transfer-Encoding: binary\n" + "\n" + "file content\n" + "\n";
MultipartUrlConfig muc = new MultipartUrlConfig("7d159c1302d0y0");
muc.parseArguments(queryString);
HTTPFileArgs files = muc.getHTTPFileArgs();
assertEquals(1, files.getHTTPFileArgCount());
HTTPFileArg file = (HTTPFileArg) files.iterator().next().getObjectValue();
assertEquals("file1", file.getPath());
assertEquals("param1", file.getParamName());
assertEquals("text/plain", file.getMimeType());
Arguments args = muc.getArguments();
assertEquals(3, args.getArgumentCount());
Argument arg = args.getArgument(0);
assertEquals("aa", arg.getName());
assertEquals("bb", arg.getValue());
arg = args.getArgument(1);
assertEquals("xx", arg.getName());
assertEquals("yy", arg.getValue());
arg = args.getArgument(2);
assertEquals("abc", arg.getName());
assertEquals("xyz \nxyz ", arg.getValue());
}
use of org.apache.jmeter.config.Argument in project jmeter by apache.
the class SendMailCommand method prepareMessage.
/**
* Prepares message prior to be sent via execute()-method, i.e. sets
* properties such as protocol, authentication, etc.
*
* @return Message-object to be sent to execute()-method
* @throws MessagingException
* when problems constructing or sending the mail occur
* @throws IOException
* when the mail content can not be read or truststore problems
* are detected
*/
public Message prepareMessage() throws MessagingException, IOException {
Properties props = new Properties();
String protocol = getProtocol();
// set properties using JAF
props.setProperty("mail." + protocol + ".host", smtpServer);
props.setProperty("mail." + protocol + ".port", getPort());
props.setProperty("mail." + protocol + ".auth", Boolean.toString(useAuthentication));
// set timeout
props.setProperty("mail." + protocol + ".timeout", getTimeout());
props.setProperty("mail." + protocol + ".connectiontimeout", getConnectionTimeout());
if (useStartTLS || useSSL) {
try {
String allProtocols = StringUtils.join(SSLContext.getDefault().getSupportedSSLParameters().getProtocols(), " ");
logger.info("Use ssl/tls protocols for mail: " + allProtocols);
props.setProperty("mail." + protocol + ".ssl.protocols", allProtocols);
} catch (Exception e) {
logger.error("Problem setting ssl/tls protocols for mail", e);
}
}
if (enableDebug) {
props.setProperty("mail.debug", "true");
}
if (useStartTLS) {
props.setProperty("mail.smtp.starttls.enable", "true");
if (enforceStartTLS) {
// Requires JavaMail 1.4.2+
props.setProperty("mail.smtp.starttls.require", "true");
}
}
if (trustAllCerts) {
if (useSSL) {
props.setProperty("mail.smtps.ssl.socketFactory.class", TRUST_ALL_SOCKET_FACTORY);
props.setProperty("mail.smtps.ssl.socketFactory.fallback", "false");
} else if (useStartTLS) {
props.setProperty("mail.smtp.ssl.socketFactory.class", TRUST_ALL_SOCKET_FACTORY);
props.setProperty("mail.smtp.ssl.socketFactory.fallback", "false");
}
} else if (useLocalTrustStore) {
File truststore = new File(trustStoreToUse);
logger.info("load local truststore - try to load truststore from: " + truststore.getAbsolutePath());
if (!truststore.exists()) {
logger.info("load local truststore -Failed to load truststore from: " + truststore.getAbsolutePath());
truststore = new File(FileServer.getFileServer().getBaseDir(), trustStoreToUse);
logger.info("load local truststore -Attempting to read truststore from: " + truststore.getAbsolutePath());
if (!truststore.exists()) {
logger.info("load local truststore -Failed to load truststore from: " + truststore.getAbsolutePath() + ". Local truststore not available, aborting execution.");
throw new IOException("Local truststore file not found. Also not available under : " + truststore.getAbsolutePath());
}
}
if (useSSL) {
// Requires JavaMail 1.4.2+
props.put("mail.smtps.ssl.socketFactory", new LocalTrustStoreSSLSocketFactory(truststore));
props.put("mail.smtps.ssl.socketFactory.fallback", "false");
} else if (useStartTLS) {
// Requires JavaMail 1.4.2+
props.put("mail.smtp.ssl.socketFactory", new LocalTrustStoreSSLSocketFactory(truststore));
props.put("mail.smtp.ssl.socketFactory.fallback", "false");
}
}
session = Session.getInstance(props, null);
Message message;
if (sendEmlMessage) {
message = new MimeMessage(session, new BufferedInputStream(new FileInputStream(emlMessage)));
} else {
message = new MimeMessage(session);
// handle body and attachments
Multipart multipart = new MimeMultipart();
final int attachmentCount = attachments.size();
if (plainBody && (attachmentCount == 0 || (mailBody.length() == 0 && attachmentCount == 1))) {
if (attachmentCount == 1) {
// i.e. mailBody is empty
File first = attachments.get(0);
try (FileInputStream fis = new FileInputStream(first);
InputStream is = new BufferedInputStream(fis)) {
message.setText(IOUtils.toString(is, Charset.defaultCharset()));
}
} else {
message.setText(mailBody);
}
} else {
BodyPart body = new MimeBodyPart();
body.setText(mailBody);
multipart.addBodyPart(body);
for (File f : attachments) {
BodyPart attach = new MimeBodyPart();
attach.setFileName(f.getName());
attach.setDataHandler(new DataHandler(new FileDataSource(f.getAbsolutePath())));
multipart.addBodyPart(attach);
}
message.setContent(multipart);
}
}
// set from field and subject
if (null != sender) {
message.setFrom(new InternetAddress(sender));
}
if (null != replyTo) {
InternetAddress[] to = new InternetAddress[replyTo.size()];
message.setReplyTo(replyTo.toArray(to));
}
if (null != subject) {
message.setSubject(subject);
}
if (receiverTo != null) {
InternetAddress[] to = new InternetAddress[receiverTo.size()];
receiverTo.toArray(to);
message.setRecipients(Message.RecipientType.TO, to);
}
if (receiverCC != null) {
InternetAddress[] cc = new InternetAddress[receiverCC.size()];
receiverCC.toArray(cc);
message.setRecipients(Message.RecipientType.CC, cc);
}
if (receiverBCC != null) {
InternetAddress[] bcc = new InternetAddress[receiverBCC.size()];
receiverBCC.toArray(bcc);
message.setRecipients(Message.RecipientType.BCC, bcc);
}
for (int i = 0; i < headerFields.size(); i++) {
Argument argument = (Argument) headerFields.get(i).getObjectValue();
message.setHeader(argument.getName(), argument.getValue());
}
message.saveChanges();
return message;
}
Aggregations