Search in sources :

Example 6 with Argument

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();
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments)

Example 7 with Argument

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);
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments)

Example 8 with Argument

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());
}
Also used : Argument(org.apache.jmeter.config.Argument) HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) Arguments(org.apache.jmeter.config.Arguments) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.Test)

Example 9 with Argument

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());
}
Also used : Argument(org.apache.jmeter.config.Argument) HTTPFileArgs(org.apache.jmeter.protocol.http.util.HTTPFileArgs) Arguments(org.apache.jmeter.config.Arguments) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) Test(org.junit.Test)

Example 10 with Argument

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;
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) InternetAddress(javax.mail.internet.InternetAddress) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) Argument(org.apache.jmeter.config.Argument) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) DataHandler(javax.activation.DataHandler) Properties(java.util.Properties) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MimeMessage(javax.mail.internet.MimeMessage) BufferedInputStream(java.io.BufferedInputStream) MimeMultipart(javax.mail.internet.MimeMultipart) FileDataSource(javax.activation.FileDataSource) MimeBodyPart(javax.mail.internet.MimeBodyPart) File(java.io.File)

Aggregations

Argument (org.apache.jmeter.config.Argument)28 Arguments (org.apache.jmeter.config.Arguments)13 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 Test (org.junit.Test)7 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BasicAttribute (javax.naming.directory.BasicAttribute)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3 File (java.io.File)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 JTextField (javax.swing.JTextField)2 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)2 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)2 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)2 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 Sampler (org.apache.jmeter.samplers.Sampler)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BufferedInputStream (java.io.BufferedInputStream)1