/** * Report an error through a dialog box in GUI mode * or in logs and stdout in Non GUI mode * * @param errorMsg - the error message. * @param titleMsg - title string */ public static void reportErrorToUser(String errorMsg, String titleMsg) { reportErrorToUser(errorMsg, titleMsg, null); }
/** * Create a new file for the graphics. Since the method creates a new file, * we shouldn't get a FNFE. * * @param filename * @return output stream created from the filename */ private FileOutputStream createFile(File filename) { try { return new FileOutputStream(filename); } catch (FileNotFoundException e) { JMeterUtils.reportErrorToUser("Could not create file: "+e.getMessage(), "Problem creating image file"); return null; } }
private static void reportError(final String messageFormat, final Throwable ex, final boolean stackTrace) { if (log.isWarnEnabled()) { if (stackTrace) { log.warn(messageFormat, ex.toString(), ex); } else { log.warn(messageFormat, ex.toString()); } } String msg = ex.getMessage(); if (msg == null) { msg = "Unexpected error - see log for details"; } JMeterUtils.reportErrorToUser(msg); }
/** * Report an error through a dialog box. * Title defaults to "error_title" resource string * @param errorMsg - the error message. * @param exception {@link Exception} */ public static void reportErrorToUser(String errorMsg, Exception exception) { reportErrorToUser(errorMsg, JMeterUtils.getResString("error_title"), exception); }
/** * Report an error through a dialog box. * Title defaults to "error_title" resource string * @param errorMsg - the error message. */ public static void reportErrorToUser(String errorMsg) { reportErrorToUser(errorMsg, JMeterUtils.getResString("error_title"), null); // $NON-NLS-1$ }
/** * Handle Locale Change by reloading BeanInfo * @param event {@link LocaleChangeEvent} */ @Override public void localeChanged(LocaleChangeEvent event) { try { beanInfo = Introspector.getBeanInfo(testBeanClass); setupGuiClasses(); } catch (IntrospectionException e) { log.error("Can't get beanInfo for {}", testBeanClass, e); JMeterUtils.reportErrorToUser("Can't get beanInfo for " + testBeanClass.getName()); } }
/** * @see org.apache.jmeter.gui.action.AbstractActionWithNoRunningTest#doActionAfterCheck(ActionEvent) */ @Override public void doActionAfterCheck(ActionEvent e) { String locale = ((Component) e.getSource()).getName(); Locale loc; int sep = locale.indexOf('_'); if (sep > 0) { loc = new Locale(locale.substring(0, sep), locale.substring(sep + 1)); } else { loc = new Locale(locale, ""); } log.debug("Changing locale to {}", loc); try { JMeterUtils.setLocale(loc); } catch (JMeterError err) { JMeterUtils.reportErrorToUser(err.toString()); } }
@Override public void actionPerformed(ActionEvent ev) { if (ev.getSource() == saveTable) { JFileChooser chooser = FileDialoger.promptToSaveFile("summary.csv");//$NON-NLS-1$ if (chooser == null) { return; } try (FileOutputStream fo = new FileOutputStream(chooser.getSelectedFile()); OutputStreamWriter writer = new OutputStreamWriter(fo, Charset.forName("UTF-8"))) { CSVSaveService.saveCSVStats(StatGraphVisualizer.getAllTableData(model, FORMATS),writer, saveHeaders.isSelected() ? StatGraphVisualizer.getLabels(COLUMNS) : null); } catch (IOException e) { JMeterUtils.reportErrorToUser(e.getMessage(), "Error saving data"); } } } }
@Override public void doAction(ActionEvent e) { GuiPackage guiPackage = GuiPackage.getInstance(); JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode(); if (!(currentNode.getUserObject() instanceof Controller)) { Toolkit.getDefaultToolkit().beep(); return; } try { applyNamingPolicyToCurrentNode(guiPackage, currentNode); } catch (Exception err) { Toolkit.getDefaultToolkit().beep(); log.error("Failed to apply naming policy", err); JMeterUtils.reportErrorToUser("Failed to apply naming policy", err); } }
private JMeterEngine getClientEngine(String address, HashTree testTree) { JMeterEngine engine; try { engine = createEngine(address); engine.configure(testTree); if (!remoteProps.isEmpty()) { engine.setProperties(remoteProps); } return engine; } catch (Exception ex) { log.error("Failed to create engine at {}", address, ex); JMeterUtils.reportErrorToUser(ex.getMessage(), JMeterUtils.getResString("remote_error_init") + ": " + address); // $NON-NLS-1$ $NON-NLS-2$ return null; } }
@Override public void actionPerformed(ActionEvent ev) { if (ev.getSource() == saveTable) { JFileChooser chooser = FileDialoger.promptToSaveFile("aggregate.csv");//$NON-NLS-1$ if (chooser == null) { return; } try (FileOutputStream fo = new FileOutputStream(chooser.getSelectedFile()); OutputStreamWriter writer = new OutputStreamWriter(fo, Charset.forName("UTF-8"))){ CSVSaveService.saveCSVStats(StatGraphVisualizer.getAllTableData(model, StatGraphVisualizer.getFormatters()), writer, saveHeaders.isSelected() ? StatGraphVisualizer.getLabels(StatGraphVisualizer.getColumns()) : null); } catch (IOException e) { JMeterUtils.reportErrorToUser(e.getMessage(), "Error saving data"); } } } }
/** * Starts a remote testing engines * * @param addresses list of the DNS names or IP addresses of the remote testing engines */ public void start(List<String> addresses) { println("Starting remote engines"); long now = System.currentTimeMillis(); println("Starting the test @ " + new Date(now) + " (" + now + ")"); for (String address : addresses) { try { if (engines.containsKey(address)) { engines.get(address).runTest(); } else { log.warn(HOST_NOT_FOUND_MESSAGE, address); } } catch (IllegalStateException | JMeterEngineException e) { // NOSONAR already reported to user JMeterUtils.reportErrorToUser(e.getMessage(), JMeterUtils.getResString("remote_error_starting")); // $NON-NLS-1$ } } println("Remote engines have been started"); }
/** * Use Batik to save a TIFF file of the graph * * @param filename * name of the file to store the image into * @param image * to be stored */ public void saveTIFFWithBatik(String filename, BufferedImage image) { File outfile = new File(filename); OutputStream fos = createFile(outfile); if (fos == null) { return; } TIFFEncodeParam param = new TIFFEncodeParam(); TIFFImageEncoder encoder = new TIFFImageEncoder(fos, param); try { encoder.encode(image); } catch (IOException e) { JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file"); } catch (Error e) { // NOSONAR TIFFImageEncoder uses Error to report runtime problems JMeterUtils.reportErrorToUser("TIFFImageEncoder reported: "+e.getMessage(), "Problem creating image file"); if (e.getClass() != Error.class){// NOSONAR rethrow other errors throw e; } } finally { JOrphanUtils.closeQuietly(fos); } }
@Override public void doAction(ActionEvent ev) { try { String className = ev.getActionCommand().substring(ActionNames.LAF_PREFIX.length()).replace('/', '.'); UIManager.setLookAndFeel(className); JMeterUtils.refreshUI(); PREFS.put(USER_PREFS_KEY, className); int chosenOption = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils .getResString("laf_quit_after_change"), // $NON-NLS-1$ JMeterUtils.getResString("exit"), // $NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (chosenOption == JOptionPane.YES_OPTION) { ActionRouter.getInstance().doActionNow(new ActionEvent(ev.getSource(), ev.getID(), ActionNames.EXIT)); } } catch (UnsupportedLookAndFeelException | InstantiationException | ClassNotFoundException | IllegalAccessException e) { JMeterUtils.reportErrorToUser("Look and Feel unavailable:" + e.toString()); } }
@Override public void doAction(ActionEvent e) { GuiPackage guiPackage = GuiPackage.getInstance(); JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode(); if (! (currentNode.getUserObject() instanceof Controller || currentNode.getUserObject() instanceof ThreadGroup) ) { Toolkit.getDefaultToolkit().beep(); return; } try { addThinkTimeToChildren(guiPackage, currentNode); } catch (Exception err) { Toolkit.getDefaultToolkit().beep(); log.error("Failed to add think times", err); JMeterUtils.reportErrorToUser("Failed to add think times", err); } }
/** * Use Batik to save a PNG of the graph * * @param filename * name of the file to store the image into * @param image * to be stored */ public void savePNGWithBatik(String filename, BufferedImage image) { File outfile = new File(filename); OutputStream fos = createFile(outfile); if (fos == null) { return; } PNGEncodeParam param = PNGEncodeParam.getDefaultEncodeParam(image); PNGImageEncoder encoder = new PNGImageEncoder(fos, param); try { encoder.encode(image); } catch (IOException e) { JMeterUtils.reportErrorToUser("PNGImageEncoder reported: "+e.getMessage(), "Problem creating image file"); } finally { JOrphanUtils.closeQuietly(fos); } }
@Override public void run() { running = false; resetSingletonEngine(); if (now) { tellThreadGroupsToStop(); pause(10L * countStillActiveThreads()); boolean stopped = verifyThreadsStopped(); if (!stopped) { // we totally failed to stop the test if (JMeter.isNonGUI()) { // TODO should we call test listeners? That might hang too ... log.error(JMeterUtils.getResString("stopping_test_failed")); //$NON-NLS-1$ if (SYSTEM_EXIT_ON_STOP_FAIL) { // default is true log.error("Exiting"); System.out.println("Fatal error, could not stop test, exiting"); // NOSONAR Intentional System.exit(1); // NOSONAR Intentional } else { System.out.println("Fatal error, could not stop test"); // NOSONAR Intentional } } else { JMeterUtils.reportErrorToUser( JMeterUtils.getResString("stopping_test_failed"), //$NON-NLS-1$ JMeterUtils.getResString("stopping_test_title")); //$NON-NLS-1$ } } // else will be done by threadFinished() } else { stopAllThreadGroups(); } } }
group.start(groupCount, notifier, threadGroupTree, this); } catch (JMeterStopTestException ex) { // NOSONAR Reported by log JMeterUtils.reportErrorToUser("Error occurred starting thread group :" + group.getName()+ ", error message:"+ex.getMessage() +", \r\nsee log file for more details", ex); return; // no point continuing
private void addNode(JMeterTreeNode parent, JMeterTreeNode node) { try { // Add this node JMeterTreeNode newNode = GuiPackage.getInstance().getTreeModel().addComponent(node.getTestElement(), parent); // Add all the child nodes of the node we are adding for (int i = 0; i < node.getChildCount(); i++) { addNode(newNode, (JMeterTreeNode)node.getChildAt(i)); } } catch (IllegalUserActionException iuae) { log.error("Illegal user action while adding a tree node.", iuae); // $NON-NLS-1$ JMeterUtils.reportErrorToUser(iuae.getMessage()); } } }
/** * Adds the specified class to the current node of the tree. */ @Override public void doAction(ActionEvent e) { GuiPackage guiPackage = GuiPackage.getInstance(); try { guiPackage.updateCurrentNode(); TestElement testElement = guiPackage.createTestElement(((JComponent) e.getSource()).getName()); JMeterTreeNode parentNode = guiPackage.getCurrentNode(); JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode); guiPackage.getNamingPolicy().nameOnCreation(node); guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath())); } catch (Exception err) { log.error("Exception while adding a component to tree.", err); // $NON-NLS-1$ String msg = err.getMessage(); if (msg == null) { msg = err.toString(); } JMeterUtils.reportErrorToUser(msg); } } }