Search in sources :

Example 1 with RecordingController

use of org.apache.jmeter.protocol.http.control.RecordingController in project jmeter by apache.

the class ProxyControl method findTargetControllerNode.

/**
 * Finds the controller where samplers have to be stored, that is:
 * <ul>
 * <li>The controller specified by the <code>target</code> property.
 * <li>If none was specified, the first RecordingController in the tree.
 * <li>If none is found, the first AbstractThreadGroup in the tree.
 * </ul>
 *
 * @return the tree node for the controller where the proxy must store the
 *         generated samplers.
 */
public JMeterTreeNode findTargetControllerNode() {
    JMeterTreeNode myTarget = getTarget();
    if (myTarget != null) {
        return myTarget;
    }
    myTarget = findFirstNodeOfType(RecordingController.class);
    if (myTarget != null) {
        return myTarget;
    }
    myTarget = findFirstNodeOfType(AbstractThreadGroup.class);
    if (myTarget != null) {
        return myTarget;
    }
    log.error("Program error: test script recording target not found.");
    return null;
}
Also used : AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Example 2 with RecordingController

use of org.apache.jmeter.protocol.http.control.RecordingController in project jmeter by apache.

the class RecordController method createTestElement.

@Override
public TestElement createTestElement() {
    RecordingController con = new RecordingController();
    super.configureTestElement(con);
    return con;
}
Also used : RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Example 3 with RecordingController

use of org.apache.jmeter.protocol.http.control.RecordingController in project jmeter by apache.

the class ProxyControlGui method startProxy.

private boolean startProxy() {
    ValueReplacer replacer = GuiPackage.getInstance().getReplacer();
    modifyTestElement(model);
    TreeNodeWrapper treeNodeWrapper = (TreeNodeWrapper) targetNodesModel.getSelectedItem();
    if (JMeterUtils.getResString("use_recording_controller").equals(treeNodeWrapper.getLabel())) {
        JMeterTreeNode targetNode = model.findTargetControllerNode();
        if (targetNode == null || !(targetNode.getTestElement() instanceof RecordingController)) {
            JOptionPane.showMessageDialog(this, // $NON-NLS-1$
            JMeterUtils.getResString("proxy_cl_wrong_target_cl"), // $NON-NLS-1$
            JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }
    // Proxy can take some while to start up; show a waiting cursor
    Cursor cursor = getCursor();
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try {
        replacer.replaceValues(model);
        model.startProxy();
        start.setEnabled(false);
        stop.setEnabled(true);
        restart.setEnabled(false);
        if (ProxyControl.isDynamicMode()) {
            String[] details = model.getCertificateDetails();
            StringBuilder sb = new StringBuilder();
            sb.append("<html>");
            // $NON-NLS-1$
            sb.append(JMeterUtils.getResString("proxy_daemon_msg_rootca_cert")).append("&nbsp;<b>").append(KeyToolUtils.ROOT_CACERT_CRT_PFX).append("</b>&nbsp;").append(JMeterUtils.getResString("proxy_daemon_msg_created_in_bin"));
            // $NON-NLS-1$
            sb.append("<br>").append(JMeterUtils.getResString("proxy_daemon_msg_install_as_in_doc"));
            sb.append("<br><b>").append(MessageFormat.format(JMeterUtils.getResString("proxy_daemon_msg_check_expiration"), // $NON-NLS-1$
            ProxyControl.CERT_VALIDITY)).append("</b><br>");
            sb.append("<br>").append(JMeterUtils.getResString("proxy_daemon_msg_check_details")).append(// $NON-NLS-1$
            "<ul>");
            for (String detail : details) {
                sb.append("<li>").append(detail).append("</li>");
            }
            sb.append("</ul>").append("</html>");
            // Make dialog disappear after 7 seconds
            JLabel messageLabel = new JLabel(sb.toString());
            Timer timer = new Timer(7000, evt -> {
                Window window = SwingUtilities.getWindowAncestor(messageLabel);
                // Window may be closed by user
                if (window != null) {
                    window.dispose();
                }
            });
            timer.setRepeats(false);
            timer.start();
            JOptionPane.showMessageDialog(this, messageLabel, // $NON-NLS-1$
            JMeterUtils.getResString("proxy_daemon_msg_rootca_cert") + SPACE + KeyToolUtils.ROOT_CACERT_CRT_PFX + SPACE + // $NON-NLS-1$
            JMeterUtils.getResString("proxy_daemon_msg_created_in_bin"), JOptionPane.INFORMATION_MESSAGE);
        }
        return true;
    } catch (InvalidVariableException e) {
        JOptionPane.showMessageDialog(this, // $NON-NLS-1$ $NON-NLS-2$
        JMeterUtils.getResString("invalid_variables") + ": " + e.getMessage(), // $NON-NLS-1$
        JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
        return false;
    } catch (BindException e) {
        JOptionPane.showMessageDialog(this, // $NON-NLS-1$ $NON-NLS-2$
        JMeterUtils.getResString("proxy_daemon_bind_error") + ": " + e.getMessage(), // $NON-NLS-1$
        JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
        return false;
    } catch (IOException e) {
        JOptionPane.showMessageDialog(this, // $NON-NLS-1$ $NON-NLS-2$
        JMeterUtils.getResString("proxy_daemon_error") + ": " + e.getMessage(), // $NON-NLS-1$
        JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
        return false;
    } finally {
        setCursor(cursor);
    }
}
Also used : Window(java.awt.Window) InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper) JLabel(javax.swing.JLabel) BindException(java.net.BindException) IOException(java.io.IOException) Cursor(java.awt.Cursor) Timer(javax.swing.Timer) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Aggregations

RecordingController (org.apache.jmeter.protocol.http.control.RecordingController)3 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)2 Cursor (java.awt.Cursor)1 Window (java.awt.Window)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1 JLabel (javax.swing.JLabel)1 Timer (javax.swing.Timer)1 TreeNodeWrapper (org.apache.jmeter.control.gui.TreeNodeWrapper)1 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)1 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)1 AbstractThreadGroup (org.apache.jmeter.threads.AbstractThreadGroup)1