Search in sources :

Example 1 with TreeNodeWrapper

use of org.apache.jmeter.control.gui.TreeNodeWrapper in project jmeter by apache.

the class ProxyControlGui method actionPerformed.

/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent action) {
    String command = action.getActionCommand();
    // Prevent both redirect types from being selected
    final Object source = action.getSource();
    if (source.equals(samplerFollowRedirects) && samplerFollowRedirects.isSelected()) {
        samplerRedirectAutomatically.setSelected(false);
    } else if (source.equals(samplerRedirectAutomatically) && samplerRedirectAutomatically.isSelected()) {
        samplerFollowRedirects.setSelected(false);
    }
    if (command.equals(ACTION_STOP)) {
        stopRecorder();
    } else if (command.equals(ACTION_START)) {
        if (startProxy()) {
            recorderDialog.setVisible(true);
        }
    } else if (command.equals(ACTION_RESTART)) {
        model.stopProxy();
        if (startProxy()) {
            recorderDialog.setVisible(true);
        }
    } else if (command.equals(ENABLE_RESTART)) {
        enableRestart();
    } else if (command.equals(ADD_EXCLUDE)) {
        excludeModel.addNewRow();
        excludeModel.fireTableDataChanged();
        enableRestart();
    } else if (command.equals(ADD_INCLUDE)) {
        includeModel.addNewRow();
        includeModel.fireTableDataChanged();
        enableRestart();
    } else if (command.equals(DELETE_EXCLUDE)) {
        deleteRowFromTable(excludeModel, excludeTable);
    } else if (command.equals(DELETE_INCLUDE)) {
        deleteRowFromTable(includeModel, includeTable);
    } else if (command.equals(CHANGE_TARGET)) {
        log.debug("Change target {} in model {}", targetNodes.getSelectedItem(), model);
        TreeNodeWrapper nw = (TreeNodeWrapper) targetNodes.getSelectedItem();
        model.setTarget(nw.getTreeNode());
        enableRestart();
    } else if (command.equals(ADD_TO_INCLUDE_FROM_CLIPBOARD)) {
        addFromClipboard(includeTable);
        includeModel.fireTableDataChanged();
        enableRestart();
    } else if (command.equals(ADD_TO_EXCLUDE_FROM_CLIPBOARD)) {
        addFromClipboard(excludeTable);
        excludeModel.fireTableDataChanged();
        enableRestart();
    } else if (command.equals(ADD_SUGGESTED_EXCLUDES)) {
        addSuggestedExcludes(excludeTable);
        excludeModel.fireTableDataChanged();
        enableRestart();
    }
}
Also used : TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper)

Example 2 with TreeNodeWrapper

use of org.apache.jmeter.control.gui.TreeNodeWrapper 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)

Example 3 with TreeNodeWrapper

use of org.apache.jmeter.control.gui.TreeNodeWrapper in project jmeter by apache.

the class ProxyControlGui method modifyTestElement.

/**
 * {@inheritDoc}
 */
@Override
public void modifyTestElement(TestElement el) {
    GuiUtils.stopTableEditing(excludeTable);
    GuiUtils.stopTableEditing(includeTable);
    configureTestElement(el);
    if (el instanceof ProxyControl) {
        model = (ProxyControl) el;
        model.setPort(portField.getText());
        model.setSslDomains(sslDomains.getText());
        setIncludeListInProxyControl(model);
        setExcludeListInProxyControl(model);
        model.setCaptureHttpHeaders(httpHeaders.isSelected());
        model.setGroupingMode(groupingMode.getSelectedIndex());
        model.setAssertions(addAssertions.isSelected());
        if (samplerTypeName.getSelectedIndex() < HTTPSamplerFactory.getImplementations().length) {
            model.setSamplerTypeName(HTTPSamplerFactory.getImplementations()[samplerTypeName.getSelectedIndex()]);
        } else {
            model.setSamplerTypeName(USE_DEFAULT_HTTP_IMPL);
        }
        model.setSamplerRedirectAutomatically(samplerRedirectAutomatically.isSelected());
        model.setSamplerFollowRedirects(samplerFollowRedirects.isSelected());
        model.setUseKeepAlive(useKeepAlive.isSelected());
        model.setDetectGraphQLRequest(detectGraphQLRequest.isSelected());
        model.setSamplerDownloadImages(samplerDownloadImages.isSelected());
        model.setHTTPSampleNamingMode(httpSampleNamingMode.getSelectedIndex());
        model.setDefaultEncoding(defaultEncoding.getText());
        model.setPrefixHTTPSampleName(prefixHTTPSampleName.getText());
        model.setProxyPauseHTTPSample(proxyPauseHTTPSample.getText());
        model.setNotifyChildSamplerListenerOfFilteredSamplers(notifyChildSamplerListenerOfFilteredSamplersCB.isSelected());
        model.setRegexMatch(regexMatch.isSelected());
        model.setContentTypeInclude(contentTypeInclude.getText());
        model.setContentTypeExclude(contentTypeExclude.getText());
        httpSampleNameFormat.setEnabled(httpSampleNamingMode.getSelectedIndex() == 3);
        if (StringUtils.isNotBlank(httpSampleNameFormat.getText())) {
            model.setHttpSampleNameFormat(httpSampleNameFormat.getText());
        }
        TreeNodeWrapper nw = (TreeNodeWrapper) targetNodes.getSelectedItem();
        if (nw == null) {
            model.setTarget(null);
        } else {
            model.setTarget(nw.getTreeNode());
        }
    }
}
Also used : TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper) ProxyControl(org.apache.jmeter.protocol.http.proxy.ProxyControl)

Example 4 with TreeNodeWrapper

use of org.apache.jmeter.control.gui.TreeNodeWrapper in project jmeter by apache.

the class ProxyControlGui method buildNodesModel.

private void buildNodesModel(JMeterTreeNode node, String parentName, int level) {
    String separator = " > ";
    if (node != null) {
        for (int i = 0; i < node.getChildCount(); i++) {
            StringBuilder name = new StringBuilder();
            JMeterTreeNode cur = (JMeterTreeNode) node.getChildAt(i);
            TestElement te = cur.getTestElement();
            if (te instanceof Controller) {
                name.append(parentName);
                name.append(cur.getName());
                TreeNodeWrapper tnw = new TreeNodeWrapper(cur, name.toString());
                targetNodesModel.addElement(tnw);
                name.append(separator);
                buildNodesModel(cur, name.toString(), level + 1);
            } else if (te instanceof TestPlan) {
                name.append(cur.getName());
                name.append(separator);
                buildNodesModel(cur, name.toString(), 0);
            }
        // Ignore everything else
        }
    }
}
Also used : TestPlan(org.apache.jmeter.testelement.TestPlan) TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) Controller(org.apache.jmeter.control.Controller) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Example 5 with TreeNodeWrapper

use of org.apache.jmeter.control.gui.TreeNodeWrapper in project jmeter by apache.

the class ProxyControlGui method reinitializeTargetCombo.

private void reinitializeTargetCombo() {
    log.debug("Reinitializing target combo");
    // Stop action notifications while we shuffle this around:
    targetNodes.removeActionListener(this);
    targetNodesModel.removeAllElements();
    GuiPackage gp = GuiPackage.getInstance();
    JMeterTreeNode root;
    if (gp != null) {
        root = (JMeterTreeNode) GuiPackage.getInstance().getTreeModel().getRoot();
        targetNodesModel.addElement(// $NON-NLS-1$
        new TreeNodeWrapper(null, JMeterUtils.getResString("use_recording_controller")));
        buildNodesModel(root, "", 0);
    }
    TreeNodeWrapper choice = null;
    for (int i = 0; i < targetNodesModel.getSize(); i++) {
        choice = (TreeNodeWrapper) targetNodesModel.getElementAt(i);
        log.debug("Selecting item {} for model {} in {}", choice, model, this);
        if (// .equals caused NPE
        choice.getTreeNode() == model.getTarget()) {
            break;
        }
    }
    // Reinstate action notifications:
    targetNodes.addActionListener(this);
    // Set the current value:
    targetNodesModel.setSelectedItem(choice);
    log.debug("Reinitialization complete");
}
Also used : GuiPackage(org.apache.jmeter.gui.GuiPackage) TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Aggregations

TreeNodeWrapper (org.apache.jmeter.control.gui.TreeNodeWrapper)5 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 RecordingController (org.apache.jmeter.protocol.http.control.RecordingController)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 Controller (org.apache.jmeter.control.Controller)1 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)1 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)1 GuiPackage (org.apache.jmeter.gui.GuiPackage)1 ProxyControl (org.apache.jmeter.protocol.http.proxy.ProxyControl)1 TestElement (org.apache.jmeter.testelement.TestElement)1 TestPlan (org.apache.jmeter.testelement.TestPlan)1