This is an automated email from the ASF dual-hosted git repository. milamber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jmeter.git
commit 45eff09fac544600e87134ebc434d387a823d254 Author: Milamber <[email protected]> AuthorDate: Tue May 9 18:37:13 2023 +0100 Fix NumberFormatException when counter is empty or not a digit on Proxy Settings panel --- .../apache/jmeter/resources/messages.properties | 2 + .../apache/jmeter/resources/messages_fr.properties | 2 + .../protocol/http/proxy/gui/ProxyControlGui.java | 50 +++++++++++++++------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties index dc93ac77c1..535e175cd2 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages.properties @@ -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 diff --git a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties index 5a68c3ebd5..fe279153c6 100644 --- a/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties +++ b/src/core/src/main/resources/org/apache/jmeter/resources/messages_fr.properties @@ -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. diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java index 5b7e776d09..e5e99f8b0b 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java @@ -63,6 +63,7 @@ import javax.swing.SwingUtilities; 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; @@ -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; @@ -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$ @@ -410,7 +415,7 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp 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()); @@ -499,6 +504,8 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp addSuggestedExcludes(excludeTable); excludeModel.fireTableDataChanged(); enableRestart(); + } else if (command.equals(SET_COUNTERS)) { + setSetCounters(); } } @@ -589,15 +596,15 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp } 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); } } @@ -633,11 +640,11 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp .append("</b> ").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>"); } @@ -656,10 +663,10 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp 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) { @@ -691,6 +698,16 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp } } + void setSetCounters() { + if ((counterValue.getText().length() > 0) && NumberUtils.isParsable(counterValue.getText())) { + Proxy.setCounter(Integer.parseInt(counterValue.getText())); + } else { + JOptionPane.showMessageDialog(this, + 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) { @@ -979,10 +996,11 @@ public class ProxyControlGui extends LogicControllerGui implements JMeterGUIComp 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);
