use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter-plugins by undera.
the class AbstractGraphPanelVisualizer method clearRowsFromCompositeModels.
private void clearRowsFromCompositeModels(String vizualizerName) {
GuiPackage gui = GuiPackage.getInstance();
if (gui == null) {
log.debug("No GUI Package present, ignored removing from composite");
return;
}
JMeterTreeModel testTree = gui.getTreeModel();
for (JMeterTreeNode obj : testTree.getNodesOfType(CompositeResultCollector.class)) {
// System.out.println("obj");
CompositeResultCollector compositeResultCollector = (CompositeResultCollector) obj.getTestElement();
compositeResultCollector.getCompositeModel().clearRows(vizualizerName);
}
}
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 (USE_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);
Authorization authorization = createAuthorization(testElements, result);
if (authorization != null) {
setAuthorization(authorization, myTarget);
}
sampleQueue.add(new SamplerInfo(sampler, testElements, myTarget, getPrefixHTTPSampleName(), groupingMode));
} 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());
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ProxyControl method findApplicableElements.
/**
* Finds all configuration objects of the given class applicable to the
* recorded samplers, that is:
* <ul>
* <li>All such elements directly within the HTTP(S) Test Script Recorder (these have
* the highest priority).
* <li>All such elements directly within the target controller (higher
* priority) or directly within any containing controller (lower priority),
* including the Test Plan itself (lowest priority).
* </ul>
*
* @param myTarget tree node for the recording target controller.
* @param myClass Class of the elements to be found.
* @param ascending true if returned elements should be ordered in ascending
* priority, false if they should be in descending priority.
* @return a collection of applicable objects of the given class.
*/
// TODO - could be converted to generic class?
@SuppressWarnings("JdkObsolete")
private Collection<?> findApplicableElements(JMeterTreeNode myTarget, Class<? extends TestElement> myClass, boolean ascending) {
JMeterTreeModel treeModel = getJmeterTreeModel();
Deque<TestElement> elements = new ArrayDeque<>();
// Look for elements directly within the HTTP proxy:
JMeterTreeNode node = treeModel.getNodeOf(this);
if (node != null) {
Enumeration<?> kids = node.children();
while (kids.hasMoreElements()) {
JMeterTreeNode subNode = (JMeterTreeNode) kids.nextElement();
if (subNode.isEnabled()) {
TestElement element = (TestElement) subNode.getUserObject();
if (myClass.isInstance(element)) {
if (ascending) {
elements.addFirst(element);
} else {
elements.add(element);
}
}
}
}
}
// Look for arguments elements in the target controller or higher up:
for (JMeterTreeNode controller = myTarget; controller != null; controller = (JMeterTreeNode) controller.getParent()) {
Enumeration<?> kids = controller.children();
while (kids.hasMoreElements()) {
JMeterTreeNode subNode = (JMeterTreeNode) kids.nextElement();
if (subNode.isEnabled()) {
TestElement element = (TestElement) subNode.getUserObject();
if (myClass.isInstance(element)) {
log.debug("Applicable: {}", element.getName());
if (ascending) {
elements.addFirst(element);
} else {
elements.add(element);
}
}
// Special case for the TestPlan's Arguments sub-element:
if (element instanceof TestPlan) {
TestPlan tp = (TestPlan) element;
Arguments args = tp.getArguments();
if (myClass.isInstance(args)) {
if (ascending) {
elements.addFirst(args);
} else {
elements.add(args);
}
}
}
}
}
}
return elements;
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ParseCurlCommandAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
statusText.setText("");
statusText.setForeground(Color.GREEN);
boolean isReadFromFile = false;
if (e.getActionCommand().equals(CREATE_REQUEST)) {
List<String> commandsList = null;
try {
if (!filePanel.getFilename().trim().isEmpty() && cURLCommandTA.getText().trim().isEmpty()) {
commandsList = readFromFile(filePanel.getFilename().trim());
isReadFromFile = true;
} else if (filePanel.getFilename().trim().isEmpty() && !cURLCommandTA.getText().trim().isEmpty()) {
commandsList = readFromTextPanel(cURLCommandTA.getText().trim());
} else {
throw new IllegalArgumentException("Error creating tast plan ,Please select one between reading file and directly fill in the panel");
}
List<Request> requests = parseCommands(isReadFromFile, commandsList);
for (int i = 0; i < requests.size(); i++) {
BasicCurlParser.Request request = requests.get(i);
try {
String commentText = createCommentText(request);
GuiPackage guiPackage = GuiPackage.getInstance();
guiPackage.updateCurrentNode();
JMeterTreeNode treeNode = findFirstNodeOfType(AbstractThreadGroup.class);
if (treeNode == null) {
LOGGER.info("No AbstractThreadGroup found, potentially empty plan, creating a new plan");
createTestPlan(e, request, commentText);
} else {
JMeterTreeNode currentNode = guiPackage.getCurrentNode();
Object userObject = currentNode.getUserObject();
if (userObject instanceof Controller && !(userObject instanceof ReplaceableController)) {
LOGGER.info("Newly created element will be placed under current selected node {}", currentNode.getName());
addToTestPlan(currentNode, request, commentText);
} else {
LOGGER.info("Newly created element will be placed under first AbstractThreadGroup node {}", treeNode.getName());
addToTestPlan(treeNode, request, commentText);
}
}
statusText.setText(JMeterUtils.getResString("curl_create_success"));
} catch (Exception ex) {
LOGGER.error("Error creating test plan from cURL command:{}, error:{}", commandsList.get(i), ex.getMessage(), ex);
statusText.setText(MessageFormat.format(JMeterUtils.getResString("curl_create_failure"), ex.getMessage()));
statusText.setForeground(UIManager.getColor(JMeterUIDefaults.LABEL_ERROR_FOREGROUND));
break;
}
}
} catch (Exception ex) {
LOGGER.error("Error creating test plan from cURL command list:{}", commandsList, ex);
statusText.setText(MessageFormat.format(JMeterUtils.getResString("curl_create_failure"), ex.getMessage()));
statusText.setForeground(UIManager.getColor(JMeterUIDefaults.LABEL_ERROR_FOREGROUND));
}
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ParseCurlCommandAction method findNodeOfTypeDnsCacheManagerByType.
private DNSCacheManager findNodeOfTypeDnsCacheManagerByType(boolean isCustom) {
JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
List<JMeterTreeNode> res = treeModel.getNodesOfType(DNSCacheManager.class);
for (JMeterTreeNode jm : res) {
DNSCacheManager dnsCacheManager = (DNSCacheManager) jm.getTestElement();
if (dnsCacheManager.isCustomResolver() == isCustom) {
return dnsCacheManager;
}
}
return null;
}
Aggregations