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
}
}
}
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(" <b>").append(KeyToolUtils.ROOT_CACERT_CRT_PFX).append("</b> ").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);
}
}
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;
}
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);
}
}
}
}
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());
}
}
Aggregations