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

(-)src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java (-7 / +168 lines)
Lines 27-38 Link Here
27
import javax.swing.BoxLayout;
27
import javax.swing.BoxLayout;
28
import javax.swing.JCheckBox;
28
import javax.swing.JCheckBox;
29
import javax.swing.JLabel;
29
import javax.swing.JLabel;
30
import javax.swing.JOptionPane;
30
import javax.swing.JPanel;
31
import javax.swing.JPanel;
31
import javax.swing.JPasswordField;
32
import javax.swing.JPasswordField;
33
import javax.swing.JTabbedPane;
32
import javax.swing.JTextField;
34
import javax.swing.JTextField;
33
import javax.swing.event.ChangeEvent;
35
import javax.swing.event.ChangeEvent;
34
import javax.swing.event.ChangeListener;
36
import javax.swing.event.ChangeListener;
35
37
38
import org.apache.commons.lang.StringUtils;
36
import org.apache.jmeter.config.Arguments;
39
import org.apache.jmeter.config.Arguments;
37
import org.apache.jmeter.config.ConfigTestElement;
40
import org.apache.jmeter.config.ConfigTestElement;
38
import org.apache.jmeter.gui.util.HorizontalPanel;
41
import org.apache.jmeter.gui.util.HorizontalPanel;
Lines 43-51 Link Here
43
import org.apache.jmeter.protocol.http.util.HTTPArgument;
46
import org.apache.jmeter.protocol.http.util.HTTPArgument;
44
import org.apache.jmeter.testelement.TestElement;
47
import org.apache.jmeter.testelement.TestElement;
45
import org.apache.jmeter.testelement.property.BooleanProperty;
48
import org.apache.jmeter.testelement.property.BooleanProperty;
49
import org.apache.jmeter.testelement.property.PropertyIterator;
46
import org.apache.jmeter.testelement.property.TestElementProperty;
50
import org.apache.jmeter.testelement.property.TestElementProperty;
47
import org.apache.jmeter.util.JMeterUtils;
51
import org.apache.jmeter.util.JMeterUtils;
48
import org.apache.jorphan.gui.JLabeledChoice;
52
import org.apache.jorphan.gui.JLabeledChoice;
53
import org.apache.jorphan.gui.JLabeledTextArea;
49
54
50
/**
55
/**
51
 * Basic URL / HTTP Request configuration:
56
 * Basic URL / HTTP Request configuration:
Lines 58-63 Link Here
58
63
59
    private static final long serialVersionUID = 240L;
64
    private static final long serialVersionUID = 240L;
60
65
66
    private static final int TAB_PARAMETERS = 0;
67
    private static final int TAB_RAW_BODY = 1;
68
    public static final String POST_BODY_RAW = "HTTPSampler.postBodyRaw"; // TODO - belongs elsewhere 
69
70
    private static final boolean POST_BODY_RAW_DEFAULT = false;
71
61
    private HTTPArgumentsPanel argsPanel;
72
    private HTTPArgumentsPanel argsPanel;
62
73
63
    private JTextField domain;
74
    private JTextField domain;
Lines 101-106 Link Here
101
    
112
    
102
    private final boolean showImplementation; // Set false for AJP
113
    private final boolean showImplementation; // Set false for AJP
103
114
115
    // Raw POST Body 
116
    private JLabeledTextArea postBodyContent;
117
118
    // Tabbed pane that contains parameters and raw body
119
    private JTabbedPane postContentTabbedPane;
120
121
    private int selectedTPIndex;
122
104
    public UrlConfigGui() {
123
    public UrlConfigGui() {
105
        this(true);
124
        this(true);
106
    }
125
    }
Lines 139-144 Link Here
139
        protocol.setText(""); // $NON-NLS-1$
158
        protocol.setText(""); // $NON-NLS-1$
140
        contentEncoding.setText(""); // $NON-NLS-1$
159
        contentEncoding.setText(""); // $NON-NLS-1$
141
        argsPanel.clear();
160
        argsPanel.clear();
161
        postBodyContent.setText("");// $NON-NLS-1$
162
        this.selectedTPIndex=TAB_PARAMETERS;
163
        postContentTabbedPane.setSelectedIndex(selectedTPIndex);
142
    }
164
    }
143
165
144
    public TestElement createTestElement() {
166
    public TestElement createTestElement() {
Lines 157-165 Link Here
157
     * @param element
179
     * @param element
158
     */
180
     */
159
    public void modifyTestElement(TestElement element) {
181
    public void modifyTestElement(TestElement element) {
160
        Arguments args = (Arguments) argsPanel.createTestElement();
182
        boolean useRaw = postContentTabbedPane.getSelectedIndex()==TAB_RAW_BODY;
161
183
        Arguments args;
162
        HTTPArgument.convertArgumentsToHTTP(args);
184
        if(useRaw) {
185
            args = new Arguments();
186
            HTTPArgument arg = new HTTPArgument("", postBodyContent.getText(), true);
187
            arg.setAlwaysEncoded(false);
188
            args.addArgument(arg);
189
        } else {
190
            args = (Arguments) argsPanel.createTestElement();
191
            HTTPArgument.convertArgumentsToHTTP(args);
192
        }
193
        element.setProperty(POST_BODY_RAW, useRaw, POST_BODY_RAW_DEFAULT);
163
        element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
194
        element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
164
        element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
195
        element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
165
        element.setProperty(HTTPSamplerBase.PORT, port.getText());
196
        element.setProperty(HTTPSamplerBase.PORT, port.getText());
Lines 185-190 Link Here
185
        }
216
        }
186
    }
217
    }
187
218
219
    // FIXME FACTOR WITH HTTPHC4Impl, HTTPHC3Impl
220
    // Just append all the parameter values, and use that as the post body
221
    /**
222
     * Compute Post body from arguments
223
     * @param arguments {@link Arguments}
224
     * @return {@link String}
225
     */
226
    private static final String computePostBody(Arguments arguments) {
227
        StringBuilder postBody = new StringBuilder();
228
        PropertyIterator args = arguments.iterator();
229
        while (args.hasNext()) {
230
            HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
231
            String value = arg.getValue();
232
            postBody.append(value);
233
        }
234
        return postBody.toString();
235
    }
236
188
    /**
237
    /**
189
     * Set the text, etc. in the UI.
238
     * Set the text, etc. in the UI.
190
     *
239
     *
Lines 193-199 Link Here
193
     */
242
     */
194
    public void configure(TestElement el) {
243
    public void configure(TestElement el) {
195
        setName(el.getName());
244
        setName(el.getName());
196
        argsPanel.configure((TestElement) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue());
245
        Arguments arguments = (Arguments) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue();
246
247
        boolean useRaw = el.getPropertyAsBoolean(POST_BODY_RAW, POST_BODY_RAW_DEFAULT);
248
        if(useRaw) {
249
            String postBody = computePostBody(arguments);
250
            postBodyContent.setText(postBody);   
251
            this.selectedTPIndex=TAB_RAW_BODY;
252
            postContentTabbedPane.setSelectedIndex(selectedTPIndex);
253
        } else {
254
            argsPanel.configure(arguments);
255
            this.selectedTPIndex=TAB_PARAMETERS;
256
            postContentTabbedPane.setSelectedIndex(this.selectedTPIndex);
257
        }
258
197
        domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN));
259
        domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN));
198
260
199
        String portString = el.getPropertyAsString(HTTPSamplerBase.PORT);
261
        String portString = el.getPropertyAsString(HTTPSamplerBase.PORT);
Lines 504-513 Link Here
504
        return panel;
566
        return panel;
505
    }
567
    }
506
568
507
    protected JPanel getParameterPanel() {
569
    protected JTabbedPane getParameterPanel() {
570
        postContentTabbedPane = new JTabbedPane();
508
        argsPanel = new HTTPArgumentsPanel();
571
        argsPanel = new HTTPArgumentsPanel();
509
572
        postBodyContent = new JLabeledTextArea(JMeterUtils.getResString("post_body_raw"));// $NON-NLS-1$
510
        return argsPanel;
573
        postContentTabbedPane.add(JMeterUtils.getResString("post_as_parameters"), argsPanel);// $NON-NLS-1$
574
        postContentTabbedPane.add(JMeterUtils.getResString("post_body"), postBodyContent);// $NON-NLS-1$
575
        postContentTabbedPane.addChangeListener(this);
576
        return postContentTabbedPane;
511
    }
577
    }
512
578
513
    // autoRedirects and followRedirects cannot both be selected
579
    // autoRedirects and followRedirects cannot both be selected
Lines 522-526 Link Here
522
                autoRedirects.setSelected(false);
588
                autoRedirects.setSelected(false);
523
            }
589
            }
524
        }
590
        }
591
        if(e.getSource() == postContentTabbedPane)
592
        {
593
            if(this.selectedTPIndex != postContentTabbedPane.getSelectedIndex())
594
            {
595
                if(noData()) {
596
                    // If there is no data, then switching between Parameters and Raw should be
597
                    // allowed with no further user interaction.
598
                    this.selectedTPIndex=postContentTabbedPane.getSelectedIndex();
599
                }
600
                else {
601
                    // If there is data in the Raw panel, then the user should be 
602
                    // prevented from switching (that would be easy to track). 
603
                    if(this.selectedTPIndex == TAB_RAW_BODY) {
604
                        postContentTabbedPane.setSelectedIndex(selectedTPIndex);    
605
                    }
606
                    else {
607
//                        If the Parameter data can be converted (i.e. no names), then I think we still
608
//                        need to warn the user that the Parameter data will be lost.
609
//                        Perhaps via a modal dialog that warns that the unselected tab will be cleared
610
//                        when the test plan is saved or the user switches to a different test element.
611
                        if(canConvertParameters()) {
612
                            Object[] options = {
613
                                    JMeterUtils.getResString("confirm"),
614
                                    JMeterUtils.getResString("cancel")};
615
                            int n = JOptionPane.showOptionDialog(this,
616
                                JMeterUtils.getResString("web_parameters_lost_message"),
617
                                JMeterUtils.getResString("warning"),
618
                                JOptionPane.YES_NO_CANCEL_OPTION,
619
                                JOptionPane.QUESTION_MESSAGE,
620
                                null,
621
                                options,
622
                                options[1]);
623
                            if(n == JOptionPane.YES_OPTION) {
624
                                convertParametersToRaw();
625
                                this.selectedTPIndex=postContentTabbedPane.getSelectedIndex();
626
                            }
627
                            else{
628
                                postContentTabbedPane.setSelectedIndex(selectedTPIndex);                    
629
                            }
630
                        }
631
                        else {
632
                            // If the Parameter data cannot be converted to Raw, then the user should be
633
                            // prevented from doing so raise an error dialog
634
                            JOptionPane.showConfirmDialog(this,
635
                                    JMeterUtils.getResString("web_cannot_convert_parameters_to_raw"), // $NON-NLS-1$
636
                                    JMeterUtils.getResString("warning"), // $NON-NLS-1$
637
                                    JOptionPane.DEFAULT_OPTION, 
638
                                    JOptionPane.ERROR_MESSAGE);
639
                            postContentTabbedPane.setSelectedIndex(selectedTPIndex);
640
                        }
641
                        
642
                        // FIXME Can you be explain a little more this ?
643
                        // In the meantime, the user can flip between tabs to check the conversion was
644
                        // what they expected.
645
                    }
646
                }
647
            }
648
        }
649
    }
650
651
    /**
652
     * Convert Parameters to Raw Body
653
     */
654
    private void convertParametersToRaw() {
655
        postBodyContent.setText(computePostBody((Arguments)argsPanel.createTestElement()));
656
    }
657
658
    /**
659
     * 
660
     * @return true if no argument has a name
661
     */
662
    private boolean canConvertParameters() {
663
        Arguments arguments = (Arguments)argsPanel.createTestElement();
664
        for (int i = 0; i < arguments.getArgumentCount(); i++) {
665
            if(!StringUtils.isEmpty(arguments.getArgument(i).getName()))
666
            {
667
                return false;
668
            }
669
        }
670
        return true;
671
    }
672
673
    /**
674
     * @return true if neither Parameters tab nor Raw Body tab contain data
675
     */
676
    private boolean noData() {
677
        if(selectedTPIndex == TAB_RAW_BODY)
678
        {
679
            return StringUtils.isEmpty(postBodyContent.getText().trim());
680
        }
681
        else
682
        {
683
            Arguments element = (Arguments)argsPanel.createTestElement();
684
            return element.getArgumentCount()==0;
685
        }
525
    }
686
    }
526
}
687
}
(-)src/core/org/apache/jmeter/resources/messages.properties (+7 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
web_parameters_lost_message=Switching to RAW Post body will convert parameters to raw body and loose\n parameters table when you select another node or save test plan, do you confirm ?
1034
web_cannot_convert_parameters_to_raw=Cannot convert parameters to RAW Post body because one of the parameters has a name
1035
confirm=Confirm
1036
post_as_parameters=Parameters
1037
post_as_rawbody=RAW Body
1038
post_body_raw=Raw Post Body
1039
post_body=Post Body
1033
web_testing2_source_ip=Source IP address:
1040
web_testing2_source_ip=Source IP address:
1034
web_testing2_title=HTTP Request HTTPClient
1041
web_testing2_title=HTTP Request HTTPClient
1035
web_testing_concurrent_download=Use concurrent pool. Size:
1042
web_testing_concurrent_download=Use concurrent pool. Size:

Return to bug 51861