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 / +64 lines)
Lines 29-34 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;
Lines 43-51 Link Here
43
import org.apache.jmeter.protocol.http.util.HTTPArgument;
44
import org.apache.jmeter.protocol.http.util.HTTPArgument;
44
import org.apache.jmeter.testelement.TestElement;
45
import org.apache.jmeter.testelement.TestElement;
45
import org.apache.jmeter.testelement.property.BooleanProperty;
46
import org.apache.jmeter.testelement.property.BooleanProperty;
47
import org.apache.jmeter.testelement.property.PropertyIterator;
46
import org.apache.jmeter.testelement.property.TestElementProperty;
48
import org.apache.jmeter.testelement.property.TestElementProperty;
47
import org.apache.jmeter.util.JMeterUtils;
49
import org.apache.jmeter.util.JMeterUtils;
48
import org.apache.jorphan.gui.JLabeledChoice;
50
import org.apache.jorphan.gui.JLabeledChoice;
51
import org.apache.jorphan.gui.JLabeledTextArea;
49
52
50
/**
53
/**
51
 * Basic URL / HTTP Request configuration:
54
 * Basic URL / HTTP Request configuration:
Lines 58-63 Link Here
58
61
59
    private static final long serialVersionUID = 240L;
62
    private static final long serialVersionUID = 240L;
60
63
64
    public static final String POST_BODY_RAW = "HTTPSampler.postBodyRaw"; // TODO - belongs elsewhere 
65
66
    private static final boolean POST_BODY_RAW_DEFAULT = false;
67
61
    private HTTPArgumentsPanel argsPanel;
68
    private HTTPArgumentsPanel argsPanel;
62
69
63
    private JTextField domain;
70
    private JTextField domain;
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
    // Tabbed pane that contains parameters and raw body
115
    private JTabbedPane postContentTabbedPane;
116
104
    public UrlConfigGui() {
117
    public UrlConfigGui() {
105
        this(true);
118
        this(true);
106
    }
119
    }
Lines 139-144 Link Here
139
        protocol.setText(""); // $NON-NLS-1$
152
        protocol.setText(""); // $NON-NLS-1$
140
        contentEncoding.setText(""); // $NON-NLS-1$
153
        contentEncoding.setText(""); // $NON-NLS-1$
141
        argsPanel.clear();
154
        argsPanel.clear();
155
        postBodyContent.setText("");// $NON-NLS-1$
156
        postContentTabbedPane.setSelectedIndex(0);
142
    }
157
    }
143
158
144
    public TestElement createTestElement() {
159
    public TestElement createTestElement() {
Lines 157-165 Link Here
157
     * @param element
172
     * @param element
158
     */
173
     */
159
    public void modifyTestElement(TestElement element) {
174
    public void modifyTestElement(TestElement element) {
160
        Arguments args = (Arguments) argsPanel.createTestElement();
175
        boolean useRaw = postContentTabbedPane.getSelectedIndex()==1;
161
176
        Arguments args;
162
        HTTPArgument.convertArgumentsToHTTP(args);
177
        if(useRaw) {
178
            args = new Arguments();
179
            HTTPArgument arg = new HTTPArgument("", postBodyContent.getText(), true);
180
            arg.setAlwaysEncoded(false);
181
            args.addArgument(arg);
182
        } else {
183
            args = (Arguments) argsPanel.createTestElement();
184
            HTTPArgument.convertArgumentsToHTTP(args);
185
        }
186
        element.setProperty(POST_BODY_RAW, useRaw, POST_BODY_RAW_DEFAULT);
163
        element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
187
        element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args));
164
        element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
188
        element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText());
165
        element.setProperty(HTTPSamplerBase.PORT, port.getText());
189
        element.setProperty(HTTPSamplerBase.PORT, port.getText());
Lines 185-191 Link Here
185
        }
209
        }
186
    }
210
    }
187
211
212
    // FIXME FACTOR WITH HTTPHC4Impl, HTTPHC3Impl
213
    // Just append all the parameter values, and use that as the post body
188
    /**
214
    /**
215
     * Compute Post body from arguments
216
     * @param arguments {@link Arguments}
217
     * @return {@link String}
218
     */
219
    private static final String computePostBody(Arguments arguments) {
220
        StringBuilder postBody = new StringBuilder();
221
        PropertyIterator args = arguments.iterator();
222
        while (args.hasNext()) {
223
            HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
224
            String value = arg.getValue();
225
            postBody.append(value);
226
        }
227
        return postBody.toString();
228
    }
229
230
    /**
189
     * Set the text, etc. in the UI.
231
     * Set the text, etc. in the UI.
190
     *
232
     *
191
     * @param el
233
     * @param el
Lines 193-199 Link Here
193
     */
235
     */
194
    public void configure(TestElement el) {
236
    public void configure(TestElement el) {
195
        setName(el.getName());
237
        setName(el.getName());
196
        argsPanel.configure((TestElement) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue());
238
        Arguments arguments = (Arguments) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue();
239
240
        boolean useRaw = el.getPropertyAsBoolean(POST_BODY_RAW, POST_BODY_RAW_DEFAULT);
241
        if(useRaw) {
242
            String postBody = computePostBody(arguments);
243
            postBodyContent.setText(postBody);   
244
            postContentTabbedPane.setSelectedIndex(1);
245
        } else {
246
            argsPanel.configure(arguments);
247
            postContentTabbedPane.setSelectedIndex(0);
248
        }
249
197
        domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN));
250
        domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN));
198
251
199
        String portString = el.getPropertyAsString(HTTPSamplerBase.PORT);
252
        String portString = el.getPropertyAsString(HTTPSamplerBase.PORT);
Lines 504-513 Link Here
504
        return panel;
557
        return panel;
505
    }
558
    }
506
559
507
    protected JPanel getParameterPanel() {
560
    protected JTabbedPane getParameterPanel() {
561
        postContentTabbedPane = new JTabbedPane();
508
        argsPanel = new HTTPArgumentsPanel();
562
        argsPanel = new HTTPArgumentsPanel();
509
563
        postBodyContent = new JLabeledTextArea(JMeterUtils.getResString("post_body_raw"));// $NON-NLS-1$
510
        return argsPanel;
564
        postContentTabbedPane.add(JMeterUtils.getResString("post_as_parameters"), argsPanel);// $NON-NLS-1$
565
        postContentTabbedPane.add(JMeterUtils.getResString("post_body"), postBodyContent);// $NON-NLS-1$
566
        postContentTabbedPane.addChangeListener(this);
567
        return postContentTabbedPane;
511
    }
568
    }
512
569
513
    // autoRedirects and followRedirects cannot both be selected
570
    // autoRedirects and followRedirects cannot both be selected

Return to bug 51861