Search in sources :

Example 21 with JMeterTreeNode

use of org.apache.jmeter.gui.tree.JMeterTreeNode 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.
     * <li>If none is found, the Workspace.
     * </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;
    }
    myTarget = findFirstNodeOfType(WorkBench.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) WorkBench(org.apache.jmeter.testelement.WorkBench)

Example 22 with JMeterTreeNode

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

the class ProxyControl method deliverSampler.

/**
     * Receives the recorded sampler from the proxy server for placing in the
     * test tree; this is skipped if the sampler is null (e.g. for recording SSL errors)
     * Always sends the result to any registered sample listeners.
     *
     * @param sampler the sampler, may be null
     * @param testElements the test elements to be added (e.g. header manager) under the Sampler
     * @param result the sample result, not null
     * TODO param serverResponse to be added to allow saving of the
     * server's response while recording.
     */
public synchronized void deliverSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, final SampleResult result) {
    boolean notifySampleListeners = true;
    if (sampler != null) {
        if (ATTEMPT_REDIRECT_DISABLING && (samplerRedirectAutomatically || samplerFollowRedirects) && result instanceof HTTPSampleResult) {
            final HTTPSampleResult httpSampleResult = (HTTPSampleResult) result;
            final String urlAsString = httpSampleResult.getUrlAsString();
            if (urlAsString.equals(LAST_REDIRECT)) {
                // the url matches the last redirect
                sampler.setEnabled(false);
                sampler.setComment("Detected a redirect from the previous sample");
            } else {
                // this is not the result of a redirect
                // so break the chain
                LAST_REDIRECT = null;
            }
            if (httpSampleResult.isRedirect()) {
                // Save Location so resulting sample can be disabled
                if (LAST_REDIRECT == null) {
                    sampler.setComment("Detected the start of a redirect chain");
                }
                LAST_REDIRECT = httpSampleResult.getRedirectLocation();
            } else {
                LAST_REDIRECT = null;
            }
        }
        if (filterContentType(result) && filterUrl(sampler)) {
            JMeterTreeNode myTarget = findTargetControllerNode();
            // OK, because find only returns correct element types
            @SuppressWarnings("unchecked") Collection<ConfigTestElement> defaultConfigurations = (Collection<ConfigTestElement>) findApplicableElements(myTarget, ConfigTestElement.class, false);
            // OK, because find only returns correct element types
            @SuppressWarnings("unchecked") Collection<Arguments> userDefinedVariables = (Collection<Arguments>) findApplicableElements(myTarget, Arguments.class, true);
            removeValuesFromSampler(sampler, defaultConfigurations);
            replaceValues(sampler, testElements, userDefinedVariables);
            sampler.setAutoRedirects(samplerRedirectAutomatically);
            sampler.setFollowRedirects(samplerFollowRedirects);
            sampler.setUseKeepAlive(useKeepAlive);
            sampler.setImageParser(samplerDownloadImages);
            String prefix = getPrefixHTTPSampleName();
            if (!StringUtils.isEmpty(prefix)) {
                sampler.setName(prefix + sampler.getName());
                result.setSampleLabel(prefix + result.getSampleLabel());
            }
            Authorization authorization = createAuthorization(testElements, sampler);
            if (authorization != null) {
                setAuthorization(authorization, myTarget);
            }
            placeSampler(sampler, testElements, myTarget);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Sample excluded based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
            }
            notifySampleListeners = notifyChildSamplerListenersOfFilteredSamples;
            result.setSampleLabel("[" + result.getSampleLabel() + "]");
        }
    }
    if (notifySampleListeners) {
        // SampleEvent is not passed JMeterVariables, because they don't make sense for Proxy Recording
        notifySampleListeners(new SampleEvent(result, "WorkBench"));
    } else {
        log.debug("Sample not delivered to Child Sampler Listener based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
    }
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Arguments(org.apache.jmeter.config.Arguments) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Collection(java.util.Collection) SampleEvent(org.apache.jmeter.samplers.SampleEvent) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 23 with JMeterTreeNode

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

the class ProxyControl method notifyTestListenersOfEnd.

/**
     * This will notify test listeners directly within the Proxy that the 'test'
     * (here meaning the proxy recording) has ended.
     */
private void notifyTestListenersOfEnd() {
    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 TestStateListener) {
                // TL - TE
                ((TestStateListener) testElement).testEnded();
            }
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestStateListener(org.apache.jmeter.testelement.TestStateListener) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 24 with JMeterTreeNode

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

the class ProxyControl method setAuthorization.

/**
     * Find if there is any AuthManager in JMeterTreeModel
     * If there is no one, create and add it to tree
     * Add authorization object to AuthManager
     * @param authorization {@link Authorization}
     * @param target {@link JMeterTreeNode}
     */
private void setAuthorization(Authorization authorization, JMeterTreeNode target) {
    JMeterTreeModel jmeterTreeModel = getJmeterTreeModel();
    List<JMeterTreeNode> authManagerNodes = jmeterTreeModel.getNodesOfType(AuthManager.class);
    if (authManagerNodes.isEmpty()) {
        try {
            log.debug("Creating HTTP Authentication manager for authorization:" + authorization);
            AuthManager authManager = newAuthorizationManager(authorization);
            jmeterTreeModel.addComponent(authManager, target);
        } catch (IllegalUserActionException e) {
            log.error("Failed to add Authorization Manager to target node:" + target.getName(), e);
        }
    } else {
        AuthManager authManager = (AuthManager) authManagerNodes.get(0).getTestElement();
        authManager.addAuth(authorization);
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 25 with JMeterTreeNode

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

the class ProxyControl method notifyTestListenersOfStart.

/**
     * This will notify test listeners directly within the Proxy that the 'test'
     * (here meaning the proxy recording) has started.
     */
private void notifyTestListenersOfStart() {
    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 TestStateListener) {
                ((TestStateListener) testElement).testStarted();
            }
        }
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestStateListener(org.apache.jmeter.testelement.TestStateListener) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

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