Skip to content

Commit

Permalink
Fix NumberFormatException when counter is empty or not a digit on Pro…
Browse files Browse the repository at this point in the history
…xy Settings panel
  • Loading branch information
milamberspace committed May 10, 2023
1 parent 193bd55 commit e368513
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ proxy_sampler_graphql_settings=GraphQL HTTP Sampler settings
proxy_sampler_settings=HTTP Sampler settings
proxy_sampler_type=Type\:
proxy_separators=Add Separators
proxy_settings_counter_error_digits=Only digits allowed
proxy_settings_counter_error_invalid_data=Invalid data
proxy_settings_pause_error_digits=Only digits allowed
proxy_settings_pause_error_invalid_data=Invalid data
proxy_settings_port_error_digits=Only digits allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ proxy_sampler_graphql_settings=Configuration de la requête GraphQL
proxy_sampler_settings=Paramètres Echantillon HTTP
proxy_sampler_type=Type \:
proxy_separators=Ajouter des séparateurs
proxy_settings_counter_error_digits=Seuls les chiffres sont autorisés.
proxy_settings_counter_error_invalid_data=Données invalides
proxy_settings_pause_error_digits=Seuls les chiffres sont autorisés.
proxy_settings_pause_error_invalid_data=Données invalides
proxy_settings_port_error_digits=Seuls les chiffres sont autorisés.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import javax.swing.Timer;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.jmeter.control.Controller;
import org.apache.jmeter.control.gui.LogicControllerGui;
import org.apache.jmeter.control.gui.TreeNodeWrapper;
Expand Down Expand Up @@ -237,6 +238,8 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp
private JButton start;
private JButton restart;

private JTextField counterValue;

private transient RecorderDialog recorderDialog;

private JTextField httpSampleNameFormat;
Expand Down Expand Up @@ -265,6 +268,8 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp

private static final String ADD_SUGGESTED_EXCLUDES = "exclude_suggested";

private static final String SET_COUNTERS = "set_counters";

static final String HTTP_SAMPLER_NAMING_MODE = "proxy_http_sampler_naming_mode"; // $NON-NLS-1$

static final String PREFIX_HTTP_SAMPLER_NAME = "proxy_prefix_http_sampler_name"; // $NON-NLS-1$
Expand Down Expand Up @@ -410,7 +415,7 @@ public void configure(TestElement element) {
httpSampleNameFormat.setText(model.getHttpSampleNameFormat());

reinitializeTargetCombo();// Set up list of potential targets and
// enable listener
// enable listener

populateTable(includeModel, model.getIncludePatterns().iterator());
populateTable(excludeModel, model.getExcludePatterns().iterator());
Expand Down Expand Up @@ -499,6 +504,8 @@ public void actionPerformed(ActionEvent action) {
addSuggestedExcludes(excludeTable);
excludeModel.fireTableDataChanged();
enableRestart();
} else if (command.equals(SET_COUNTERS)) {
setSetCounters();
}
}

Expand Down Expand Up @@ -589,15 +596,15 @@ protected void addFromClipboard(JTable table) {
} catch (IOException ioe) {
JOptionPane.showMessageDialog(this,
JMeterUtils.getResString("proxy_daemon_error_read_args") // $NON-NLS-1$
+ "\n" + ioe.getLocalizedMessage(), JMeterUtils.getResString("error_title"), // $NON-NLS-1$ $NON-NLS-2$
+ "\n" + ioe.getLocalizedMessage(), JMeterUtils.getResString("error_title"), // $NON-NLS-1$ $NON-NLS-2$
JOptionPane.ERROR_MESSAGE);
} catch (UnsupportedFlavorException ufe) {
JOptionPane.showMessageDialog(this,
JMeterUtils.getResString("proxy_daemon_error_not_retrieve") + SPACE // $NON-NLS-1$
+ DataFlavor.stringFlavor.getHumanPresentableName() + SPACE
+ JMeterUtils.getResString("proxy_daemon_error_from_clipboard") // $NON-NLS-1$
+ ufe.getLocalizedMessage(), JMeterUtils.getResString("error_title"), // $NON-NLS-1$
JOptionPane.ERROR_MESSAGE);
+ DataFlavor.stringFlavor.getHumanPresentableName() + SPACE
+ JMeterUtils.getResString("proxy_daemon_error_from_clipboard") // $NON-NLS-1$
+ ufe.getLocalizedMessage(), JMeterUtils.getResString("error_title"), // $NON-NLS-1$
JOptionPane.ERROR_MESSAGE);
}
}

Expand Down Expand Up @@ -633,11 +640,11 @@ private boolean startProxy() {
.append("</b>&nbsp;").append(JMeterUtils.getResString("proxy_daemon_msg_created_in_bin"));
sb.append("<br>").append(JMeterUtils.getResString("proxy_daemon_msg_install_as_in_doc")); // $NON-NLS-1$
sb.append("<br><b>").append(MessageFormat.format(
JMeterUtils.getResString("proxy_daemon_msg_check_expiration"),
ProxyControl.CERT_VALIDITY)) // $NON-NLS-1$
.append("</b><br>");
JMeterUtils.getResString("proxy_daemon_msg_check_expiration"),
ProxyControl.CERT_VALIDITY)) // $NON-NLS-1$
.append("</b><br>");
sb.append("<br>").append(JMeterUtils.getResString("proxy_daemon_msg_check_details"))
.append("<ul>"); // $NON-NLS-1$
.append("<ul>"); // $NON-NLS-1$
for(String detail : details) {
sb.append("<li>").append(detail).append("</li>");
}
Expand All @@ -656,10 +663,10 @@ private boolean startProxy() {
timer.start();
JOptionPane.showMessageDialog(this,
messageLabel,
JMeterUtils.getResString("proxy_daemon_msg_rootca_cert") + SPACE // $NON-NLS-1$
+ KeyToolUtils.ROOT_CACERT_CRT_PFX + SPACE
+ JMeterUtils.getResString("proxy_daemon_msg_created_in_bin"), // $NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
JMeterUtils.getResString("proxy_daemon_msg_rootca_cert") + SPACE // $NON-NLS-1$
+ KeyToolUtils.ROOT_CACERT_CRT_PFX + SPACE
+ JMeterUtils.getResString("proxy_daemon_msg_created_in_bin"), // $NON-NLS-1$
JOptionPane.INFORMATION_MESSAGE);
}
return true;
} catch (InvalidVariableException e) {
Expand Down Expand Up @@ -691,6 +698,17 @@ void enableRestart() {
}
}

void setSetCounters() {
if ((counterValue.getText().length() > 0) && NumberUtils.isParsable(counterValue.getText())) {
Proxy.setCounter(Integer.parseInt(counterValue.getText()));
} else {
JOptionPane.showMessageDialog(this,
//"Counter isn't a number value.", "Error on counter value", JOptionPane.WARNING_MESSAGE);
JMeterUtils.getResString("proxy_settings_counter_error_digits"), // $NON-NLS-1$
JMeterUtils.getResString("proxy_settings_counter_error_invalid_data"), // $NON-NLS-1$
JOptionPane.WARNING_MESSAGE);
}
}
/** {@inheritDoc} */
@Override
public void keyPressed(KeyEvent e) {
Expand Down Expand Up @@ -979,10 +997,11 @@ private JPanel createHTTPSamplerPanel() {
httpSampleNameFormat.setToolTipText(JMeterUtils.getResString("sample_naming_format_help"));

JLabel labelSetCounter = new JLabel(JMeterUtils.getResString("sample_creator_counter_value"));
JTextField counterValue = new JTextField(10);
counterValue = new JTextField(10);
labelSetCounter.setLabelFor(counterValue);
JButton buttonSetCounter = new JButton(JMeterUtils.getResString("sample_creator_set_counter"));
buttonSetCounter.addActionListener(e -> Proxy.setCounter(Integer.parseInt(counterValue.getText())));
buttonSetCounter.setActionCommand(SET_COUNTERS);
buttonSetCounter.addActionListener(this);
panel.add(labelSetCounter);
panel.add(counterValue);
panel.add(buttonSetCounter);
Expand Down

0 comments on commit e368513

Please sign in to comment.