View | Details | Raw Unified | Return to bug 62212
Collapse All | Expand All

(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 812-817 Link Here
812
proxy_general_settings=Global Settings
812
proxy_general_settings=Global Settings
813
proxy_headers=Capture HTTP Headers
813
proxy_headers=Capture HTTP Headers
814
proxy_pause_http_sampler=Create new transaction after request (ms)\:
814
proxy_pause_http_sampler=Create new transaction after request (ms)\:
815
proxy_recorder_dialog=Recorder\: Transactions Control
815
proxy_regex=Regex matching
816
proxy_regex=Regex matching
816
proxy_sampler_settings=HTTP Sampler settings
817
proxy_sampler_settings=HTTP Sampler settings
817
proxy_sampler_type=Type\:
818
proxy_sampler_type=Type\:
(-)src/core/org/apache/jmeter/resources/messages_fr.properties (+1 lines)
Lines 801-806 Link Here
801
proxy_general_settings=Param\u00E8tres g\u00E9n\u00E9raux
801
proxy_general_settings=Param\u00E8tres g\u00E9n\u00E9raux
802
proxy_headers=Capturer les ent\u00EAtes HTTP
802
proxy_headers=Capturer les ent\u00EAtes HTTP
803
proxy_pause_http_sampler=Cr\u00E9er une nouvelle transaction apr\u00E8s la requ\u00EAte (ms) \:
803
proxy_pause_http_sampler=Cr\u00E9er une nouvelle transaction apr\u00E8s la requ\u00EAte (ms) \:
804
proxy_recorder_dialog=Enregistreur\: Contr\u00f4le des transactions
804
proxy_regex=Correspondance des variables par regex ?
805
proxy_regex=Correspondance des variables par regex ?
805
proxy_sampler_settings=Param\u00E8tres Echantillon HTTP
806
proxy_sampler_settings=Param\u00E8tres Echantillon HTTP
806
proxy_sampler_type=Type \:
807
proxy_sampler_type=Type \:
(-)src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java (-5 / +15 lines)
Lines 214-219 Link Here
214
    private JButton start;
214
    private JButton start;
215
    private JButton restart;
215
    private JButton restart;
216
216
217
    private RecorderDialog recorderDialog;
218
217
    //+ action names
219
    //+ action names
218
    private static final String ACTION_STOP = "stop"; // $NON-NLS-1$
220
    private static final String ACTION_STOP = "stop"; // $NON-NLS-1$
219
221
Lines 222-228 Link Here
222
    private static final String ACTION_RESTART = "restart"; // $NON-NLS-1$
224
    private static final String ACTION_RESTART = "restart"; // $NON-NLS-1$
223
225
224
    // This is applied to fields that should cause a restart when changed
226
    // This is applied to fields that should cause a restart when changed
225
    private static final String ENABLE_RESTART = "enable_restart"; // $NON-NLS-1$
227
    static final String ENABLE_RESTART = "enable_restart"; // $NON-NLS-1$
226
228
227
    private static final String ADD_INCLUDE = "add_include"; // $NON-NLS-1$
229
    private static final String ADD_INCLUDE = "add_include"; // $NON-NLS-1$
228
230
Lines 238-248 Link Here
238
240
239
    private static final String ADD_SUGGESTED_EXCLUDES = "exclude_suggested";
241
    private static final String ADD_SUGGESTED_EXCLUDES = "exclude_suggested";
240
    
242
    
241
    private static final String HTTP_SAMPLER_NAMING_MODE = "proxy_http_sampler_naming_mode"; // $NON-NLS-1$
243
    static final String HTTP_SAMPLER_NAMING_MODE = "proxy_http_sampler_naming_mode"; // $NON-NLS-1$
242
244
243
    private static final String PREFIX_HTTP_SAMPLER_NAME = "proxy_prefix_http_sampler_name"; // $NON-NLS-1$
245
    static final String PREFIX_HTTP_SAMPLER_NAME = "proxy_prefix_http_sampler_name"; // $NON-NLS-1$
244
246
245
    private static final String PROXY_PAUSE_HTTP_SAMPLER = "proxy_pause_http_sampler"; // $NON-NLS-1$
247
    static final String PROXY_PAUSE_HTTP_SAMPLER = "proxy_pause_http_sampler"; // $NON-NLS-1$
246
    //- action names
248
    //- action names
247
249
248
    // Resource names for column headers
250
    // Resource names for column headers
Lines 257-262 Link Here
257
        super();
259
        super();
258
        log.debug("Creating ProxyControlGui");
260
        log.debug("Creating ProxyControlGui");
259
        init();
261
        init();
262
        this.recorderDialog = new RecorderDialog(this);
260
    }
263
    }
261
264
262
    /** {@inheritDoc} */
265
    /** {@inheritDoc} */
Lines 420-430 Link Here
420
            stop.setEnabled(false);
423
            stop.setEnabled(false);
421
            start.setEnabled(true);
424
            start.setEnabled(true);
422
            restart.setEnabled(false);
425
            restart.setEnabled(false);
426
            recorderDialog.setVisible(false);
423
        } else if (command.equals(ACTION_START)) {
427
        } else if (command.equals(ACTION_START)) {
424
            startProxy();
428
            startProxy();
429
            recorderDialog.setVisible(true);
425
        } else if (command.equals(ACTION_RESTART)) {
430
        } else if (command.equals(ACTION_RESTART)) {
426
            model.stopProxy();
431
            model.stopProxy();
427
            startProxy();
432
            startProxy();
433
            recorderDialog.setVisible(true);
428
        } else if (command.equals(ENABLE_RESTART)){
434
        } else if (command.equals(ENABLE_RESTART)){
429
            enableRestart();
435
            enableRestart();
430
        } else if (command.equals(ADD_EXCLUDE)) {
436
        } else if (command.equals(ADD_EXCLUDE)) {
Lines 616-622 Link Here
616
        }
622
        }
617
    }
623
    }
618
624
619
    private void enableRestart() {
625
    void enableRestart() {
620
        if (stop.isEnabled()) {
626
        if (stop.isEnabled()) {
621
            restart.setEnabled(true);
627
            restart.setEnabled(true);
622
        }
628
        }
Lines 1165-1168 Link Here
1165
        MenuFactory.addFileMenu(pop);
1171
        MenuFactory.addFileMenu(pop);
1166
        return pop;
1172
        return pop;
1167
    }
1173
    }
1174
    
1175
    ProxyControl getRecorderModel() {
1176
        return model;
1177
    }
1168
}
1178
}
(-)src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/RecorderDialog.java (+220 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.protocol.http.proxy.gui;
20
21
import java.awt.BorderLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ItemEvent;
26
import java.awt.event.ItemListener;
27
import java.awt.event.KeyEvent;
28
import java.awt.event.KeyListener;
29
30
import javax.swing.AbstractAction;
31
import javax.swing.Action;
32
import javax.swing.ActionMap;
33
import javax.swing.BorderFactory;
34
import javax.swing.DefaultComboBoxModel;
35
import javax.swing.InputMap;
36
import javax.swing.JComboBox;
37
import javax.swing.JComponent;
38
import javax.swing.JDialog;
39
import javax.swing.JFrame;
40
import javax.swing.JLabel;
41
import javax.swing.JOptionPane;
42
import javax.swing.JPanel;
43
import javax.swing.JRootPane;
44
import javax.swing.JTextField;
45
46
import org.apache.jmeter.gui.action.KeyStrokes;
47
import org.apache.jmeter.util.JMeterUtils;
48
49
/**
50
 * Dialog for Recorder
51
 */
52
public class RecorderDialog extends JDialog implements ItemListener, KeyListener { // NOSONAR
53
54
55
    /**
56
     * 
57
     */
58
    private static final long serialVersionUID = 931790497924069705L;
59
60
    /**
61
     * Add a prefix/transaction name to HTTP sample name recorded
62
     */
63
    private JTextField prefixHTTPSampleName;
64
65
    private JTextField proxyPauseHTTPSample;
66
67
    /**
68
     * To choose between a prefix or a transaction name
69
     */
70
    private JComboBox<String> httpSampleNamingMode;
71
72
    private ProxyControlGui recorderGui;
73
74
    public RecorderDialog(ProxyControlGui controlGui) {
75
        super((JFrame) null, JMeterUtils.getResString("proxy_recorder_dialog"), false); //$NON-NLS-1$
76
        this.recorderGui = controlGui;
77
        this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
78
        this.setResizable(false);
79
        init();
80
    }
81
82
    @Override
83
    protected JRootPane createRootPane() {
84
        JRootPane rootPane = new JRootPane();
85
        // Hide Window on ESC
86
        Action escapeAction = new AbstractAction("ESCAPE") {
87
88
            private static final long serialVersionUID = -6543764044868772971L;
89
90
            @Override
91
            public void actionPerformed(ActionEvent actionEvent) {
92
                setVisible(false);
93
            }
94
        };
95
        
96
        ActionMap actionMap = rootPane.getActionMap();
97
        actionMap.put(escapeAction.getValue(Action.NAME), escapeAction);
98
        InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
99
        inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
100
101
        return rootPane;
102
    }
103
104
    private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
105
        this.getContentPane().setLayout(new BorderLayout(10,10));
106
107
        DefaultComboBoxModel<String> choice = new DefaultComboBoxModel<>();
108
        choice.addElement(JMeterUtils.getResString("sample_name_prefix")); // $NON-NLS-1$
109
        choice.addElement(JMeterUtils.getResString("sample_name_transaction")); // $NON-NLS-1$
110
        httpSampleNamingMode = new JComboBox<>(choice);
111
        httpSampleNamingMode.setName(ProxyControlGui.HTTP_SAMPLER_NAMING_MODE);
112
        httpSampleNamingMode.addItemListener(this);
113
        
114
        prefixHTTPSampleName = new JTextField(20);
115
        prefixHTTPSampleName.addKeyListener(this);
116
        prefixHTTPSampleName.setName(ProxyControlGui.PREFIX_HTTP_SAMPLER_NAME);
117
118
        proxyPauseHTTPSample = new JTextField(10);
119
        proxyPauseHTTPSample.addKeyListener(this);
120
        proxyPauseHTTPSample.setName(ProxyControlGui.PROXY_PAUSE_HTTP_SAMPLER);
121
122
        proxyPauseHTTPSample.setActionCommand(ProxyControlGui.ENABLE_RESTART);
123
        JLabel labelProxyPause = new JLabel(JMeterUtils.getResString("proxy_pause_http_sampler")); // $NON-NLS-1$
124
        labelProxyPause.setLabelFor(proxyPauseHTTPSample);
125
              
126
        GridBagLayout gridBagLayout = new GridBagLayout();
127
        GridBagConstraints gbc = new GridBagConstraints();
128
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
129
        gbc.fill = GridBagConstraints.NONE;
130
        gbc.gridheight = 1;
131
        gbc.gridwidth = 1;
132
        gbc.gridx = 0;
133
        gbc.gridy = 0;
134
        gbc.weightx = 1;
135
        gbc.weighty = 1;
136
        JPanel panel = new JPanel(gridBagLayout);
137
        panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
138
                JMeterUtils.getResString("proxy_sampler_settings"))); // $NON-NLS-1$
139
        panel.add(httpSampleNamingMode, gbc.clone());
140
        gbc.gridx++;
141
        gbc.weightx = 3;
142
        gbc.fill=GridBagConstraints.HORIZONTAL;
143
        panel.add(prefixHTTPSampleName, gbc.clone());
144
        gbc.gridx = 0;
145
        gbc.gridy++;
146
        panel.add(labelProxyPause, gbc.clone());
147
        gbc.gridx++;
148
        gbc.weightx = 3;
149
        gbc.fill = GridBagConstraints.HORIZONTAL;
150
        panel.add(proxyPauseHTTPSample, gbc.clone());
151
152
        this.getContentPane().add(panel, BorderLayout.NORTH);
153
        this.pack();
154
        this.setLocation(5, 10);
155
        prefixHTTPSampleName.requestFocusInWindow();
156
    }
157
158
    
159
160
    /* (non-Javadoc)
161
     * @see java.awt.Dialog#setVisible(boolean)
162
     */
163
    @Override
164
    public void setVisible(boolean b) {
165
        super.setVisible(b);
166
        prefixHTTPSampleName.requestFocusInWindow();
167
        httpSampleNamingMode.setSelectedIndex(recorderGui.getRecorderModel().getHTTPSampleNamingMode());
168
        proxyPauseHTTPSample.setText(recorderGui.getRecorderModel().getProxyPauseHTTPSample());
169
        setAlwaysOnTop(b);
170
    }
171
172
    @Override
173
    public void itemStateChanged(ItemEvent e) {
174
        if (e.getSource() instanceof JComboBox) {
175
            JComboBox combo = (JComboBox) e.getSource();
176
            if(ProxyControlGui.HTTP_SAMPLER_NAMING_MODE.equals(combo.getName())){
177
                recorderGui.getRecorderModel().setHTTPSampleNamingMode(httpSampleNamingMode.getSelectedIndex());
178
            }
179
        }
180
        else {
181
            recorderGui.enableRestart();
182
        }
183
    }
184
185
    /** {@inheritDoc} */
186
    @Override
187
    public void keyPressed(KeyEvent e) {
188
        // NOOP
189
    }
190
191
    /** {@inheritDoc} */
192
    @Override
193
    public void keyTyped(KeyEvent e) {
194
        // NOOP
195
    }
196
197
    /** {@inheritDoc} */
198
    @Override
199
    public void keyReleased(KeyEvent e) {
200
        String fieldName = e.getComponent().getName();
201
        if(fieldName.equals(ProxyControlGui.PREFIX_HTTP_SAMPLER_NAME)) {
202
            recorderGui.getRecorderModel().setPrefixHTTPSampleName(prefixHTTPSampleName.getText());
203
        } else if(fieldName.equals(ProxyControlGui.PROXY_PAUSE_HTTP_SAMPLER)) {
204
            try {
205
                Long.parseLong(proxyPauseHTTPSample.getText());
206
            } catch (NumberFormatException nfe) {
207
                int length = proxyPauseHTTPSample.getText().length();
208
                if (length > 0) {
209
                    JOptionPane.showMessageDialog(this, JMeterUtils.getResString("proxy_settings_pause_error_digits"), // $NON-NLS-1$
210
                            JMeterUtils.getResString("proxy_settings_pause_error_invalid_data"), // $NON-NLS-1$
211
                            JOptionPane.WARNING_MESSAGE);
212
                    // Drop the last character:
213
                    proxyPauseHTTPSample.setText(proxyPauseHTTPSample.getText().substring(0, length - 1));
214
                }
215
            }
216
            recorderGui.getRecorderModel().setProxyPauseHTTPSample(proxyPauseHTTPSample.getText());
217
            recorderGui.enableRestart();
218
        }
219
    }
220
}

Return to bug 62212