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

(-)src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java (-11 / +103 lines)
Lines 29-38 Link Here
29
import javax.swing.JLabel;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
30
import javax.swing.JPanel;
31
import javax.swing.JPasswordField;
31
import javax.swing.JPasswordField;
32
import javax.swing.JTabbedPane;
32
import javax.swing.JTextField;
33
import javax.swing.JTextField;
33
import javax.swing.event.ChangeEvent;
34
import javax.swing.event.ChangeEvent;
34
import javax.swing.event.ChangeListener;
35
import javax.swing.event.ChangeListener;
35
36
37
import org.apache.commons.lang.StringUtils;
36
import org.apache.jmeter.config.Arguments;
38
import org.apache.jmeter.config.Arguments;
37
import org.apache.jmeter.config.ConfigTestElement;
39
import org.apache.jmeter.config.ConfigTestElement;
38
import org.apache.jmeter.gui.util.HorizontalPanel;
40
import org.apache.jmeter.gui.util.HorizontalPanel;
Lines 43-51 Link Here
43
import org.apache.jmeter.protocol.http.util.HTTPArgument;
45
import org.apache.jmeter.protocol.http.util.HTTPArgument;
44
import org.apache.jmeter.testelement.TestElement;
46
import org.apache.jmeter.testelement.TestElement;
45
import org.apache.jmeter.testelement.property.BooleanProperty;
47
import org.apache.jmeter.testelement.property.BooleanProperty;
48
import org.apache.jmeter.testelement.property.PropertyIterator;
46
import org.apache.jmeter.testelement.property.TestElementProperty;
49
import org.apache.jmeter.testelement.property.TestElementProperty;
47
import org.apache.jmeter.util.JMeterUtils;
50
import org.apache.jmeter.util.JMeterUtils;
48
import org.apache.jorphan.gui.JLabeledChoice;
51
import org.apache.jorphan.gui.JLabeledChoice;
52
import org.apache.jorphan.gui.JLabeledTextArea;
49
53
50
/**
54
/**
51
 * Basic URL / HTTP Request configuration:
55
 * Basic URL / HTTP Request configuration:
Lines 57-62 Link Here
57
public class UrlConfigGui extends JPanel implements ChangeListener {
61
public class UrlConfigGui extends JPanel implements ChangeListener {
58
62
59
    private static final long serialVersionUID = 240L;
63
    private static final long serialVersionUID = 240L;
64
    
65
    public static final String POST_BODY_RAW = "HTTPSampler.postBodyRaw"; // 
66
60
67
61
    private HTTPArgumentsPanel argsPanel;
68
    private HTTPArgumentsPanel argsPanel;
62
69
Lines 101-106 Link Here
101
    
108
    
102
    private final boolean showImplementation; // Set false for AJP
109
    private final boolean showImplementation; // Set false for AJP
103
110
111
    // Raw POST Body 
112
    private JLabeledTextArea postBodyContent;
113
114
    // Choice between Parameters and Raw body
115
    private JLabeledChoice postBodyMode;
116
117
    // Tabbed pane that contains parameters and raw body
118
    private JTabbedPane postContentTabbedPane;
119
104
    public UrlConfigGui() {
120
    public UrlConfigGui() {
105
        this(true);
121
        this(true);
106
    }
122
    }
Lines 139-144 Link Here
139
        protocol.setText(""); // $NON-NLS-1$
155
        protocol.setText(""); // $NON-NLS-1$
140
        contentEncoding.setText(""); // $NON-NLS-1$
156
        contentEncoding.setText(""); // $NON-NLS-1$
141
        argsPanel.clear();
157
        argsPanel.clear();
158
        postBodyContent.setText("");// $NON-NLS-1$
159
        postBodyMode.setSelectedIndex(0);
160
        postContentTabbedPane.setSelectedIndex(0);
142
    }
161
    }
143
162
144
    public TestElement createTestElement() {
163
    public TestElement createTestElement() {
Lines 157-166 Link Here
157
     * @param element
176
     * @param element
158
     */
177
     */
159
    public void modifyTestElement(TestElement element) {
178
    public void modifyTestElement(TestElement element) {
160
        Arguments args = (Arguments) argsPanel.createTestElement();
179
        
161
180
        if(postBodyMode.getSelectedIndex()==0)
162
        HTTPArgument.convertArgumentsToHTTP(args);
181
        {
163
        element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
182
            Arguments args = (Arguments) argsPanel.createTestElement();
183
            HTTPArgument.convertArgumentsToHTTP(args);
184
            element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
185
            element.setProperty(POST_BODY_RAW, false);
186
        }
187
        else
188
        {
189
            Arguments args = new Arguments();
190
            HTTPArgument arg = new HTTPArgument("", postBodyContent.getText(), true);
191
            arg.setAlwaysEncoded(false);
192
            args.addArgument(arg);
193
            element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
194
            element.setProperty(POST_BODY_RAW, true);
195
        }
164
        element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
196
        element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
165
        element.setProperty(HTTPSamplerBase.PORT, port.getText());
197
        element.setProperty(HTTPSamplerBase.PORT, port.getText());
166
        element.setProperty(HTTPSamplerBase.PROXYHOST, proxyHost.getText(),"");
198
        element.setProperty(HTTPSamplerBase.PROXYHOST, proxyHost.getText(),"");
Lines 184-189 Link Here
184
            element.setProperty(HTTPSamplerBase.IMPLEMENTATION, httpImplementation.getText(),"");
216
            element.setProperty(HTTPSamplerBase.IMPLEMENTATION, httpImplementation.getText(),"");
185
        }
217
        }
186
    }
218
    }
219
    
220
    // FIXME FACTOR WITH HTTPHC4Impl, HTTPHC3Impl
221
    // Just append all the parameter values, and use that as the post body
222
    /**
223
     * Compute Post body from arguments
224
     * @param arguments {@link Arguments}
225
     * @return {@link String}
226
     */
227
    private static final String computePostBody(Arguments arguments) {
228
        StringBuilder postBody = new StringBuilder();
229
        PropertyIterator args = arguments.iterator();
230
        while (args.hasNext()) {
231
            HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
232
            String value = arg.getValue();
233
            postBody.append(value);
234
        }
235
        return postBody.toString();
236
    }
187
237
188
    /**
238
    /**
189
     * Set the text, etc. in the UI.
239
     * Set the text, etc. in the UI.
Lines 193-199 Link Here
193
     */
243
     */
194
    public void configure(TestElement el) {
244
    public void configure(TestElement el) {
195
        setName(el.getName());
245
        setName(el.getName());
196
        argsPanel.configure((TestElement) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue());
246
        Arguments arguments = (Arguments) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue();
247
        
248
        if(el.getPropertyAsBoolean(POST_BODY_RAW, false)|| 
249
                (arguments.getArgumentCount()==1 && StringUtils.isEmpty(arguments.getArgument(0).getName())))
250
        {
251
            String postBody = computePostBody(arguments);
252
            postBodyContent.setText(postBody);   
253
            postBodyMode.setSelectedIndex(1);
254
        }
255
        else
256
        {
257
            argsPanel.configure(arguments);
258
            postBodyMode.setSelectedIndex(0);       
259
        }
260
        
197
        domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN));
261
        domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN));
198
262
199
        String portString = el.getPropertyAsString(HTTPSamplerBase.PORT);
263
        String portString = el.getPropertyAsString(HTTPSamplerBase.PORT);
Lines 227-232 Link Here
227
        }
291
        }
228
    }
292
    }
229
293
294
230
    private void init() {// called from ctor, so must not be overridable
295
    private void init() {// called from ctor, so must not be overridable
231
        this.setLayout(new BorderLayout());
296
        this.setLayout(new BorderLayout());
232
297
Lines 433-442 Link Here
433
            useMultipartForPost.setSelected(false);
498
            useMultipartForPost.setSelected(false);
434
499
435
            useBrowserCompatibleMultipartMode = new JCheckBox(JMeterUtils.getResString("use_multipart_mode_browser")); // $NON-NLS-1$
500
            useBrowserCompatibleMultipartMode = new JCheckBox(JMeterUtils.getResString("use_multipart_mode_browser")); // $NON-NLS-1$
436
            useBrowserCompatibleMultipartMode.setSelected(HTTPSamplerBase.BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT);
501
            useBrowserCompatibleMultipartMode.setSelected(HTTPSamplerBase.BROWSER_COMPATIBLE_MULTIPART_MODE_DEFAULT);            
437
438
        }
502
        }
439
503
        
440
        JPanel pathPanel = new JPanel(new BorderLayout(5, 0));
504
        JPanel pathPanel = new JPanel(new BorderLayout(5, 0));
441
        pathPanel.add(label, BorderLayout.WEST);
505
        pathPanel.add(label, BorderLayout.WEST);
442
        pathPanel.add(path, BorderLayout.CENTER);
506
        pathPanel.add(path, BorderLayout.CENTER);
Lines 495-513 Link Here
495
        if (notConfigOnly){
559
        if (notConfigOnly){
496
            panel.add(method);
560
            panel.add(method);
497
        }
561
        }
562
        
563
        postBodyMode = new JLabeledChoice(
564
                JMeterUtils.getResString("post_body_mode"), // $NON-NLS-1$
565
                new String[]{
566
                    JMeterUtils.getResString("post_as_parameters"), // $NON-NLS-1$
567
                    JMeterUtils.getResString("post_as_rawbody")});// $NON-NLS-1$
568
        postBodyMode.addChangeListener(this);
569
        
498
        panel.setMinimumSize(panel.getPreferredSize());
570
        panel.setMinimumSize(panel.getPreferredSize());
499
        panel.add(Box.createHorizontalStrut(5));
571
        panel.add(Box.createHorizontalStrut(5));
500
572
501
        panel.add(contentEncodingLabel);
573
        panel.add(contentEncodingLabel);
502
        panel.add(contentEncoding);
574
        panel.add(contentEncoding);
575
        panel.add(postBodyMode);
503
        panel.setMinimumSize(panel.getPreferredSize());
576
        panel.setMinimumSize(panel.getPreferredSize());
504
        return panel;
577
        return panel;
505
    }
578
    }
506
579
507
    protected JPanel getParameterPanel() {
580
    protected JTabbedPane getParameterPanel() {
581
        postContentTabbedPane = new JTabbedPane();
508
        argsPanel = new HTTPArgumentsPanel();
582
        argsPanel = new HTTPArgumentsPanel();
509
583
        postBodyContent = new JLabeledTextArea(JMeterUtils.getResString("post_body_raw"));// $NON-NLS-1$
510
        return argsPanel;
584
        postContentTabbedPane.add(JMeterUtils.getResString("post_as_parameters"), argsPanel);// $NON-NLS-1$
585
        postContentTabbedPane.add(JMeterUtils.getResString("post_body"), postBodyContent);// $NON-NLS-1$
586
        postContentTabbedPane.setEnabledAt(1, false);
587
        return postContentTabbedPane;
511
    }
588
    }
512
589
513
    // autoRedirects and followRedirects cannot both be selected
590
    // autoRedirects and followRedirects cannot both be selected
Lines 522-526 Link Here
522
                autoRedirects.setSelected(false);
599
                autoRedirects.setSelected(false);
523
            }
600
            }
524
        }
601
        }
602
        if(e.getSource() == postBodyMode)
603
        {
604
            if(postBodyMode.getSelectedIndex()==0)
605
            {
606
                postContentTabbedPane.setEnabledAt(0,true);
607
                postContentTabbedPane.setEnabledAt(1,false);                
608
                postContentTabbedPane.setSelectedIndex(0);
609
            }
610
            else
611
            {
612
                postContentTabbedPane.setEnabledAt(0,false);
613
                postContentTabbedPane.setEnabledAt(1,true);
614
                postContentTabbedPane.setSelectedIndex(1);
615
            }
616
        }
525
    }
617
    }
526
}
618
}
(-)src/core/org/apache/jmeter/resources/messages.properties (+5 lines)
Lines 1030-1035 Link Here
1030
web_server_client=Client implementation:
1030
web_server_client=Client implementation:
1031
web_server_domain=Server Name or IP\:
1031
web_server_domain=Server Name or IP\:
1032
web_server_port=Port Number\:
1032
web_server_port=Port Number\:
1033
post_as_parameters=Parameters
1034
post_as_rawbody=RAW Body
1035
post_body_mode=POST Body Mode\:
1036
post_body_raw=Raw Post Body
1037
post_body=Post Body
1033
web_testing2_source_ip=Source IP address:
1038
web_testing2_source_ip=Source IP address:
1034
web_testing2_title=HTTP Request HTTPClient
1039
web_testing2_title=HTTP Request HTTPClient
1035
web_testing_concurrent_download=Use concurrent pool. Size:
1040
web_testing_concurrent_download=Use concurrent pool. Size:

Return to bug 51861