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 |
|
68 |
private static final int TAB_RAW_BODY = 1; |
69 |
|
61 |
private HTTPArgumentsPanel argsPanel; |
70 |
private HTTPArgumentsPanel argsPanel; |
62 |
|
71 |
|
63 |
private JTextField domain; |
72 |
private JTextField domain; |
Lines 101-117
Link Here
|
101 |
|
110 |
|
102 |
private final boolean showImplementation; // Set false for AJP |
111 |
private final boolean showImplementation; // Set false for AJP |
103 |
|
112 |
|
|
|
113 |
// Raw POST Body |
114 |
private JLabeledTextArea postBodyContent; |
115 |
|
116 |
// Tabbed pane that contains parameters and raw body |
117 |
private ValidationTabbedPane postContentTabbedPane; |
118 |
|
119 |
private boolean showRawBodyPane; |
120 |
|
104 |
public UrlConfigGui() { |
121 |
public UrlConfigGui() { |
105 |
this(true); |
122 |
this(true); |
106 |
} |
123 |
} |
107 |
|
124 |
|
108 |
public UrlConfigGui(boolean value) { |
125 |
/** |
109 |
this(value, true); |
126 |
* @param showSamplerFields |
|
|
127 |
*/ |
128 |
public UrlConfigGui(boolean showSamplerFields) { |
129 |
this(showSamplerFields, true, true); |
110 |
} |
130 |
} |
111 |
|
131 |
|
112 |
public UrlConfigGui(boolean showSamplerFields, boolean showImplementation) { |
132 |
/** |
|
|
133 |
* @param showSamplerFields |
134 |
* @param showImplementation Show HTTP Implementation |
135 |
* @param showRawBodyPane |
136 |
*/ |
137 |
public UrlConfigGui(boolean showSamplerFields, boolean showImplementation, boolean showRawBodyPane) { |
113 |
notConfigOnly=showSamplerFields; |
138 |
notConfigOnly=showSamplerFields; |
114 |
this.showImplementation = showImplementation; |
139 |
this.showImplementation = showImplementation; |
|
|
140 |
this.showRawBodyPane = showRawBodyPane; |
115 |
init(); |
141 |
init(); |
116 |
} |
142 |
} |
117 |
|
143 |
|
Lines 139-144
Link Here
|
139 |
protocol.setText(""); // $NON-NLS-1$ |
165 |
protocol.setText(""); // $NON-NLS-1$ |
140 |
contentEncoding.setText(""); // $NON-NLS-1$ |
166 |
contentEncoding.setText(""); // $NON-NLS-1$ |
141 |
argsPanel.clear(); |
167 |
argsPanel.clear(); |
|
|
168 |
if(showRawBodyPane) { |
169 |
postBodyContent.setText("");// $NON-NLS-1$ |
170 |
} |
171 |
postContentTabbedPane.setSelectedIndex(TAB_PARAMETERS, false); |
142 |
} |
172 |
} |
143 |
|
173 |
|
144 |
public TestElement createTestElement() { |
174 |
public TestElement createTestElement() { |
Lines 157-165
Link Here
|
157 |
* @param element |
187 |
* @param element |
158 |
*/ |
188 |
*/ |
159 |
public void modifyTestElement(TestElement element) { |
189 |
public void modifyTestElement(TestElement element) { |
160 |
Arguments args = (Arguments) argsPanel.createTestElement(); |
190 |
boolean useRaw = postContentTabbedPane.getSelectedIndex()==TAB_RAW_BODY; |
161 |
|
191 |
Arguments args; |
162 |
HTTPArgument.convertArgumentsToHTTP(args); |
192 |
if(useRaw) { |
|
|
193 |
args = new Arguments(); |
194 |
HTTPArgument arg = new HTTPArgument("", postBodyContent.getText(), true); |
195 |
arg.setAlwaysEncoded(false); |
196 |
args.addArgument(arg); |
197 |
} else { |
198 |
args = (Arguments) argsPanel.createTestElement(); |
199 |
HTTPArgument.convertArgumentsToHTTP(args); |
200 |
} |
201 |
element.setProperty(HTTPSamplerBase.POST_BODY_RAW, useRaw, HTTPSamplerBase.POST_BODY_RAW_DEFAULT); |
163 |
element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args)); |
202 |
element.setProperty(new TestElementProperty(HTTPSamplerBase.ARGUMENTS, args)); |
164 |
element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText()); |
203 |
element.setProperty(HTTPSamplerBase.DOMAIN, domain.getText()); |
165 |
element.setProperty(HTTPSamplerBase.PORT, port.getText()); |
204 |
element.setProperty(HTTPSamplerBase.PORT, port.getText()); |
Lines 185-190
Link Here
|
185 |
} |
224 |
} |
186 |
} |
225 |
} |
187 |
|
226 |
|
|
|
227 |
// FIXME FACTOR WITH HTTPHC4Impl, HTTPHC3Impl |
228 |
// Just append all the parameter values, and use that as the post body |
229 |
/** |
230 |
* Compute Post body from arguments |
231 |
* @param arguments {@link Arguments} |
232 |
* @return {@link String} |
233 |
*/ |
234 |
private static final String computePostBody(Arguments arguments) { |
235 |
StringBuilder postBody = new StringBuilder(); |
236 |
PropertyIterator args = arguments.iterator(); |
237 |
while (args.hasNext()) { |
238 |
HTTPArgument arg = (HTTPArgument) args.next().getObjectValue(); |
239 |
String value = arg.getValue(); |
240 |
postBody.append(value); |
241 |
} |
242 |
return postBody.toString(); |
243 |
} |
244 |
|
188 |
/** |
245 |
/** |
189 |
* Set the text, etc. in the UI. |
246 |
* Set the text, etc. in the UI. |
190 |
* |
247 |
* |
Lines 193-199
Link Here
|
193 |
*/ |
250 |
*/ |
194 |
public void configure(TestElement el) { |
251 |
public void configure(TestElement el) { |
195 |
setName(el.getName()); |
252 |
setName(el.getName()); |
196 |
argsPanel.configure((TestElement) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue()); |
253 |
Arguments arguments = (Arguments) el.getProperty(HTTPSamplerBase.ARGUMENTS).getObjectValue(); |
|
|
254 |
|
255 |
boolean useRaw = el.getPropertyAsBoolean(HTTPSamplerBase.POST_BODY_RAW, HTTPSamplerBase.POST_BODY_RAW_DEFAULT); |
256 |
if(useRaw) { |
257 |
String postBody = computePostBody(arguments); |
258 |
postBodyContent.setText(postBody); |
259 |
postContentTabbedPane.setSelectedIndex(TAB_RAW_BODY, false); |
260 |
} else { |
261 |
argsPanel.configure(arguments); |
262 |
postContentTabbedPane.setSelectedIndex(TAB_PARAMETERS, false); |
263 |
} |
264 |
|
197 |
domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN)); |
265 |
domain.setText(el.getPropertyAsString(HTTPSamplerBase.DOMAIN)); |
198 |
|
266 |
|
199 |
String portString = el.getPropertyAsString(HTTPSamplerBase.PORT); |
267 |
String portString = el.getPropertyAsString(HTTPSamplerBase.PORT); |
Lines 504-515
Link Here
|
504 |
return panel; |
572 |
return panel; |
505 |
} |
573 |
} |
506 |
|
574 |
|
507 |
protected JPanel getParameterPanel() { |
575 |
protected JTabbedPane getParameterPanel() { |
|
|
576 |
postContentTabbedPane = new ValidationTabbedPane(); |
508 |
argsPanel = new HTTPArgumentsPanel(); |
577 |
argsPanel = new HTTPArgumentsPanel(); |
509 |
|
578 |
postContentTabbedPane.add(JMeterUtils.getResString("post_as_parameters"), argsPanel);// $NON-NLS-1$ |
510 |
return argsPanel; |
579 |
if(showRawBodyPane) { |
|
|
580 |
postBodyContent = new JLabeledTextArea(JMeterUtils.getResString("post_body_raw"));// $NON-NLS-1$ |
581 |
postContentTabbedPane.add(JMeterUtils.getResString("post_body"), postBodyContent);// $NON-NLS-1$ |
582 |
} |
583 |
return postContentTabbedPane; |
511 |
} |
584 |
} |
512 |
|
585 |
|
|
|
586 |
/** |
587 |
* |
588 |
*/ |
589 |
class ValidationTabbedPane extends JTabbedPane{ |
590 |
|
591 |
/** |
592 |
* |
593 |
*/ |
594 |
private static final long serialVersionUID = 7014311238367882880L; |
595 |
|
596 |
/* (non-Javadoc) |
597 |
* @see javax.swing.JTabbedPane#setSelectedIndex(int) |
598 |
*/ |
599 |
@Override |
600 |
public void setSelectedIndex(int index) { |
601 |
setSelectedIndex(index, true); |
602 |
} |
603 |
/** |
604 |
* Apply some check rules if check is true |
605 |
*/ |
606 |
public void setSelectedIndex(int index, boolean check) { |
607 |
int oldSelectedIndex = getSelectedIndex(); |
608 |
if(!check || oldSelectedIndex==-1) { |
609 |
super.setSelectedIndex(index); |
610 |
} |
611 |
else if(index != this.getSelectedIndex()) |
612 |
{ |
613 |
if(noData(getSelectedIndex())) { |
614 |
// If there is no data, then switching between Parameters and Raw should be |
615 |
// allowed with no further user interaction. |
616 |
argsPanel.clear(); |
617 |
postBodyContent.setText(""); |
618 |
super.setSelectedIndex(index); |
619 |
} |
620 |
else { |
621 |
if(oldSelectedIndex == TAB_RAW_BODY) { |
622 |
// If RAW data and Parameters match we allow switching |
623 |
if(postBodyContent.getText().equals(computePostBody((Arguments)argsPanel.createTestElement()).trim())) { |
624 |
super.setSelectedIndex(index); |
625 |
} |
626 |
else { |
627 |
// If there is data in the Raw panel, then the user should be |
628 |
// prevented from switching (that would be easy to track). |
629 |
JOptionPane.showConfirmDialog(this, |
630 |
JMeterUtils.getResString("web_cannot_switch_tab"), // $NON-NLS-1$ |
631 |
JMeterUtils.getResString("warning"), // $NON-NLS-1$ |
632 |
JOptionPane.DEFAULT_OPTION, |
633 |
JOptionPane.ERROR_MESSAGE); |
634 |
return; |
635 |
} |
636 |
} |
637 |
else { |
638 |
// If the Parameter data can be converted (i.e. no names), we |
639 |
// warn the user that the Parameter data will be lost. |
640 |
if(canConvertParameters()) { |
641 |
Object[] options = { |
642 |
JMeterUtils.getResString("confirm"), |
643 |
JMeterUtils.getResString("cancel")}; |
644 |
int n = JOptionPane.showOptionDialog(this, |
645 |
JMeterUtils.getResString("web_parameters_lost_message"), |
646 |
JMeterUtils.getResString("warning"), |
647 |
JOptionPane.YES_NO_CANCEL_OPTION, |
648 |
JOptionPane.QUESTION_MESSAGE, |
649 |
null, |
650 |
options, |
651 |
options[1]); |
652 |
if(n == JOptionPane.YES_OPTION) { |
653 |
convertParametersToRaw(); |
654 |
super.setSelectedIndex(index); |
655 |
} |
656 |
else{ |
657 |
return; |
658 |
} |
659 |
} |
660 |
else { |
661 |
// If the Parameter data cannot be converted to Raw, then the user should be |
662 |
// prevented from doing so raise an error dialog |
663 |
JOptionPane.showConfirmDialog(this, |
664 |
JMeterUtils.getResString("web_cannot_convert_parameters_to_raw"), // $NON-NLS-1$ |
665 |
JMeterUtils.getResString("warning"), // $NON-NLS-1$ |
666 |
JOptionPane.DEFAULT_OPTION, |
667 |
JOptionPane.ERROR_MESSAGE); |
668 |
return; |
669 |
} |
670 |
} |
671 |
} |
672 |
} |
673 |
} |
674 |
} |
513 |
// autoRedirects and followRedirects cannot both be selected |
675 |
// autoRedirects and followRedirects cannot both be selected |
514 |
public void stateChanged(ChangeEvent e) { |
676 |
public void stateChanged(ChangeEvent e) { |
515 |
if (e.getSource() == autoRedirects){ |
677 |
if (e.getSource() == autoRedirects){ |
Lines 523-526
Link Here
|
523 |
} |
685 |
} |
524 |
} |
686 |
} |
525 |
} |
687 |
} |
|
|
688 |
|
689 |
|
690 |
/** |
691 |
* Convert Parameters to Raw Body |
692 |
*/ |
693 |
void convertParametersToRaw() { |
694 |
postBodyContent.setText(computePostBody((Arguments)argsPanel.createTestElement())); |
695 |
} |
696 |
|
697 |
/** |
698 |
* |
699 |
* @return true if no argument has a name |
700 |
*/ |
701 |
boolean canConvertParameters() { |
702 |
Arguments arguments = (Arguments)argsPanel.createTestElement(); |
703 |
for (int i = 0; i < arguments.getArgumentCount(); i++) { |
704 |
if(!StringUtils.isEmpty(arguments.getArgument(i).getName())) { |
705 |
return false; |
706 |
} |
707 |
} |
708 |
return true; |
709 |
} |
710 |
|
711 |
/** |
712 |
* @return true if neither Parameters tab nor Raw Body tab contain data |
713 |
*/ |
714 |
boolean noData(int oldSelectedIndex) { |
715 |
if(oldSelectedIndex == TAB_RAW_BODY) { |
716 |
return StringUtils.isEmpty(postBodyContent.getText().trim()); |
717 |
} |
718 |
else { |
719 |
Arguments element = (Arguments)argsPanel.createTestElement(); |
720 |
return StringUtils.isEmpty(computePostBody(element)); |
721 |
} |
722 |
} |
526 |
} |
723 |
} |