Search in sources :

Example 46 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode 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();
            /*
                 * Will never be true. Probably intended to use
                 * org.apache.jmeter.threads.ThreadGroup rather than
                 * java.lang.ThreadGroup However, that does not work correctly;
                 * whereas treating it as a Controller does. if (te instanceof
                 * ThreadGroup) { name.append(parent_name);
                 * name.append(cur.getName()); name.append(separator);
                 * buildNodesModel(cur, name.toString(), level); } else
                 */
            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 || te instanceof WorkBench) {
                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) WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 47 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControlGui method startProxy.

private void 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;
        }
    }
    // Proxy can take some while to start up; show a waiting cursor
    Cursor cursor = getCursor();
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    // TODO somehow show progress
    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$
            new Object[] { 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>");
            JOptionPane.showMessageDialog(this, sb.toString(), // $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);
        }
    } 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);
    } 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);
    } 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);
    } finally {
        setCursor(cursor);
    }
}
Also used : InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) TreeNodeWrapper(org.apache.jmeter.control.gui.TreeNodeWrapper) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) BindException(java.net.BindException) IOException(java.io.IOException) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer) Cursor(java.awt.Cursor) RecordingController(org.apache.jmeter.protocol.http.control.RecordingController)

Example 48 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControl method findFirstNodeOfType.

/**
     * Finds the first enabled node of a given type in the tree.
     *
     * @param type
     *            class of the node to be found
     *
     * @return the first node of the given type in the test component tree, or
     *         <code>null</code> if none was found.
     */
private JMeterTreeNode findFirstNodeOfType(Class<?> type) {
    JMeterTreeModel treeModel = getJmeterTreeModel();
    List<JMeterTreeNode> nodes = treeModel.getNodesOfType(type);
    for (JMeterTreeNode node : nodes) {
        if (node.isEnabled()) {
            return node;
        }
    }
    return null;
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode)

Example 49 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControl method notifySampleListeners.

/**
     * This will notify sample listeners directly within the Proxy of the
     * sampling that just occurred -- so that we have a means to record the
     * server's responses as we go.
     *
     * @param event
     *            sampling event to be delivered
     */
private void notifySampleListeners(SampleEvent event) {
    JMeterTreeModel treeModel = getJmeterTreeModel();
    JMeterTreeNode myNode = treeModel.getNodeOf(this);
    Enumeration<JMeterTreeNode> kids = myNode.children();
    while (kids.hasMoreElements()) {
        JMeterTreeNode subNode = kids.nextElement();
        if (subNode.isEnabled()) {
            TestElement testElement = subNode.getTestElement();
            if (testElement instanceof SampleListener) {
                ((SampleListener) testElement).sampleOccurred(event);
            }
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) SampleListener(org.apache.jmeter.samplers.SampleListener)

Example 50 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.

the class ProxyControl method placeSampler.

private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, JMeterTreeNode myTarget) {
    try {
        final JMeterTreeModel treeModel = getJmeterTreeModel();
        boolean firstInBatch = false;
        long now = System.currentTimeMillis();
        long deltaT = now - lastTime;
        int cachedGroupingMode = groupingMode;
        if (deltaT > SAMPLE_GAP) {
            if (!myTarget.isLeaf() && cachedGroupingMode == GROUPING_ADD_SEPARATORS) {
                addDivider(treeModel, myTarget);
            }
            if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS) {
                addSimpleController(treeModel, myTarget, sampler.getName());
            }
            if (cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
                addTransactionController(treeModel, myTarget, sampler.getName());
            }
            // Remember this was first in its batch
            firstInBatch = true;
        }
        if (lastTime == 0) {
            // Decent value for timers
            deltaT = 0;
        }
        lastTime = now;
        if (cachedGroupingMode == GROUPING_STORE_FIRST_ONLY) {
            if (!firstInBatch) {
                // Huh! don't store this one!
                return;
            }
            // If we're not storing subsequent samplers, we'll need the
            // first sampler to do all the work...:
            sampler.setFollowRedirects(true);
            sampler.setImageParser(true);
        }
        if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS || cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
            // sampler there:
            for (int i = myTarget.getChildCount() - 1; i >= 0; i--) {
                JMeterTreeNode c = (JMeterTreeNode) myTarget.getChildAt(i);
                if (c.getTestElement() instanceof GenericController) {
                    myTarget = c;
                    break;
                }
            }
        }
        final long deltaTFinal = deltaT;
        final boolean firstInBatchFinal = firstInBatch;
        final JMeterTreeNode myTargetFinal = myTarget;
        JMeterUtils.runSafe(true, () -> {
            try {
                final JMeterTreeNode newNode = treeModel.addComponent(sampler, myTargetFinal);
                if (firstInBatchFinal) {
                    if (addAssertions) {
                        addAssertion(treeModel, newNode);
                    }
                    addTimers(treeModel, newNode, deltaTFinal);
                }
                if (testElements != null) {
                    for (TestElement testElement : testElements) {
                        if (isAddableTestElement(testElement)) {
                            treeModel.addComponent(testElement, newNode);
                        }
                    }
                }
            } catch (IllegalUserActionException e) {
                log.error("Error placing sampler", e);
                JMeterUtils.reportErrorToUser(e.getMessage());
            }
        });
    } catch (Exception e) {
        log.error("Error placing sampler", e);
        JMeterUtils.reportErrorToUser(e.getMessage());
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenericController(org.apache.jmeter.control.GenericController) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Aggregations

JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)68 GuiPackage (org.apache.jmeter.gui.GuiPackage)21 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)18 TestElement (org.apache.jmeter.testelement.TestElement)18 TreePath (javax.swing.tree.TreePath)10 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)10 IOException (java.io.IOException)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)7 TestPlan (org.apache.jmeter.testelement.TestPlan)7 HashTree (org.apache.jorphan.collections.HashTree)7 ActionEvent (java.awt.event.ActionEvent)6 JTree (javax.swing.JTree)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)6 TreeNode (javax.swing.tree.TreeNode)5 LinkedList (java.util.LinkedList)4 JMeterGUIComponent (org.apache.jmeter.gui.JMeterGUIComponent)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)4