1 18 19 package org.apache.jmeter.protocol.http.config.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Component ; 23 import java.awt.FlowLayout ; 24 25 import javax.swing.BorderFactory ; 26 import javax.swing.Box ; 27 import javax.swing.ButtonGroup ; 28 import javax.swing.JCheckBox ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JRadioButton ; 32 import javax.swing.JTextField ; 33 34 import org.apache.jmeter.config.Arguments; 35 import org.apache.jmeter.config.ConfigTestElement; 36 import org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel; 37 import org.apache.jmeter.protocol.http.sampler.HTTPSampler; 38 import org.apache.jmeter.protocol.http.util.HTTPArgument; 39 import org.apache.jmeter.testelement.AbstractTestElement; 40 import org.apache.jmeter.testelement.TestElement; 41 import org.apache.jmeter.testelement.property.BooleanProperty; 42 import org.apache.jmeter.testelement.property.TestElementProperty; 43 import org.apache.jmeter.util.JMeterUtils; 44 45 46 50 public class UrlConfigGui extends JPanel 51 { 52 protected HTTPArgumentsPanel argsPanel; 53 private static String DOMAIN = "domain"; 54 private static String PORT = "port"; 55 private static String PROTOCOL = "protocol"; 56 private static String PATH = "path"; 57 private static String FOLLOW_REDIRECTS = "follow_redirects"; 58 private static String AUTO_REDIRECTS = "auto_redirects"; 59 private static String USE_KEEPALIVE = "use_keepalive"; 60 61 private JTextField domain; 62 private JTextField port; 63 private JTextField protocol; 64 private JTextField path; 65 private JCheckBox followRedirects; 66 private JCheckBox autoRedirects; 67 private JCheckBox useKeepAlive; 68 private JRadioButton post; 69 private JRadioButton get; 70 71 public UrlConfigGui() 72 { 73 init(); 74 } 75 76 protected void configureTestElement(TestElement mc) 77 { 78 mc.setProperty(TestElement.NAME, getName()); 79 mc.setProperty(TestElement.GUI_CLASS, this.getClass().getName()); 80 mc.setProperty(TestElement.TEST_CLASS, mc.getClass().getName()); 81 } 82 83 public void clear() 84 { 85 domain.setText(""); 86 followRedirects.setSelected(true); 87 autoRedirects.setSelected(false); 88 get.setSelected(true); 89 path.setText(""); 90 port.setText(""); 91 protocol.setText(""); 92 useKeepAlive.setSelected(true); 93 argsPanel.clear(); 94 95 } 96 97 public TestElement createTestElement() 98 { 99 ConfigTestElement element = new ConfigTestElement(); 100 101 this.configureTestElement(element); 102 Arguments args = (Arguments) argsPanel.createTestElement(); 103 104 HTTPArgument.convertArgumentsToHTTP(args); 105 element.setProperty( 106 new TestElementProperty(HTTPSampler.ARGUMENTS, args)); 107 element.setProperty(HTTPSampler.DOMAIN, domain.getText()); 108 element.setProperty(HTTPSampler.PORT, port.getText()); 109 element.setProperty(HTTPSampler.PROTOCOL, protocol.getText()); 110 element.setProperty(HTTPSampler.METHOD, 111 (post.isSelected() ? "POST" : "GET")); 112 element.setProperty(HTTPSampler.PATH, path.getText()); 113 element.setProperty(new BooleanProperty(HTTPSampler.FOLLOW_REDIRECTS, 114 followRedirects.isSelected())); 115 element.setProperty(new BooleanProperty(HTTPSampler.AUTO_REDIRECTS, 116 autoRedirects.isSelected())); 117 element.setProperty(new BooleanProperty(HTTPSampler.USE_KEEPALIVE, 118 useKeepAlive.isSelected())); 119 return element; 120 } 121 122 139 144 public void configure(TestElement el) 145 { 146 setName(el.getPropertyAsString(TestElement.NAME)); 147 argsPanel.configure( 148 (TestElement) el 149 .getProperty(HTTPSampler.ARGUMENTS) 150 .getObjectValue()); 151 domain.setText(el.getPropertyAsString(HTTPSampler.DOMAIN)); 152 153 String portString = (String ) el.getPropertyAsString(HTTPSampler.PORT); 154 155 if (portString.equals("" + HTTPSampler.UNSPECIFIED_PORT)) 157 { 158 port.setText(""); 159 } 160 else 161 { 162 port.setText(portString); 163 } 164 protocol.setText(el.getPropertyAsString(HTTPSampler.PROTOCOL)); 165 if ("POST".equals(el.getPropertyAsString(HTTPSampler.METHOD))) 166 { 167 post.setSelected(true); 168 get.setSelected(false); 169 } 170 else 171 { 172 get.setSelected(true); 173 post.setSelected(false); 174 } 175 path.setText(el.getPropertyAsString(HTTPSampler.PATH)); 176 followRedirects.setSelected( 177 ((AbstractTestElement) el).getPropertyAsBoolean( 178 HTTPSampler.FOLLOW_REDIRECTS)); 179 180 autoRedirects.setSelected( 181 ((AbstractTestElement) el).getPropertyAsBoolean( 182 HTTPSampler.AUTO_REDIRECTS)); 183 useKeepAlive.setSelected( 184 ((AbstractTestElement) el).getPropertyAsBoolean( 185 HTTPSampler.USE_KEEPALIVE)); 186 } 187 188 protected void init() 189 { 190 this.setLayout(new BorderLayout ()); 191 192 JPanel webServerPanel = new JPanel (); 193 194 webServerPanel.setLayout(new BorderLayout ()); 195 webServerPanel.setBorder( 196 BorderFactory.createTitledBorder( 197 BorderFactory.createEtchedBorder(), 198 JMeterUtils.getResString("web_server"))); 199 webServerPanel.add(getDomainPanel(), BorderLayout.NORTH); 200 webServerPanel.add(getPortPanel(), BorderLayout.WEST); 201 202 JPanel webRequestPanel = new JPanel (); 203 204 webRequestPanel.setLayout(new BorderLayout ()); 205 webRequestPanel.setBorder( 206 BorderFactory.createTitledBorder( 207 BorderFactory.createEtchedBorder(), 208 JMeterUtils.getResString("web_request"))); 209 JPanel northPanel = new JPanel (new BorderLayout ()); 210 211 northPanel.add(getProtocolAndMethodPanel(), BorderLayout.NORTH); 212 northPanel.add(getPathPanel(), BorderLayout.SOUTH); 213 webServerPanel.add(northPanel, BorderLayout.SOUTH); 214 webRequestPanel.add(getParameterPanel(), BorderLayout.CENTER); 215 216 this.add(webServerPanel, BorderLayout.NORTH); 217 this.add(webRequestPanel, BorderLayout.CENTER); 218 } 219 220 protected JPanel getPortPanel() 221 { 222 port = new JTextField (6); 223 port.setName(PORT); 224 225 JLabel label = new JLabel (JMeterUtils.getResString("web_server_port")); 226 label.setLabelFor(port); 227 228 JPanel panel = new JPanel (new BorderLayout (5, 0)); 229 panel.add(label, BorderLayout.WEST); 230 panel.add(port, BorderLayout.CENTER); 231 232 return panel; 233 } 234 235 protected JPanel getDomainPanel() 236 { 237 domain = new JTextField (20); 238 domain.setName(DOMAIN); 239 240 JLabel label = 241 new JLabel (JMeterUtils.getResString("web_server_domain")); 242 label.setLabelFor(domain); 243 244 JPanel panel = new JPanel (new BorderLayout (5, 0)); 245 panel.add(label, BorderLayout.WEST); 246 panel.add(domain, BorderLayout.CENTER); 247 return panel; 248 } 249 250 257 protected Component getPathPanel() 258 { 259 path = new JTextField (15); 260 path.setName(PATH); 261 262 JLabel label = new JLabel (JMeterUtils.getResString("path")); 263 label.setLabelFor(path); 264 265 autoRedirects = 266 new JCheckBox (JMeterUtils.getResString("follow_redirects_auto")); 267 autoRedirects.setName(AUTO_REDIRECTS); 268 autoRedirects.setSelected(false); 270 followRedirects = 271 new JCheckBox (JMeterUtils.getResString("follow_redirects")); 272 followRedirects.setName(FOLLOW_REDIRECTS); 273 followRedirects.setSelected(true); 274 275 useKeepAlive = new JCheckBox (JMeterUtils.getResString("use_keepalive")); 276 useKeepAlive.setName(USE_KEEPALIVE); 277 useKeepAlive.setSelected(true); 278 279 JPanel panel = new JPanel (new FlowLayout (FlowLayout.LEFT)); 280 panel.add(label); 281 panel.add(Box.createHorizontalStrut(5)); 282 panel.add(path); 283 panel.add(Box.createHorizontalStrut(10)); 284 panel.add(autoRedirects); 285 panel.add(followRedirects); 286 panel.add(Box.createHorizontalStrut(5)); 287 panel.add(useKeepAlive); 288 panel.setMinimumSize(panel.getPreferredSize()); 289 return panel; 290 } 291 292 protected JPanel getProtocolAndMethodPanel() 293 { 294 protocol = new JTextField (4); 296 protocol.setName(PROTOCOL); 297 298 JLabel protocolLabel = new JLabel (JMeterUtils.getResString("protocol")); 299 protocolLabel.setLabelFor(protocol); 300 301 ButtonGroup methodButtonGroup = new ButtonGroup (); 303 304 get = new JRadioButton (JMeterUtils.getResString("url_config_get")); 305 methodButtonGroup.add(get); 306 307 post = new JRadioButton (JMeterUtils.getResString("url_config_post")); 308 methodButtonGroup.add(post); 309 post.setSelected(true); 310 311 JLabel methodLabel = new JLabel (JMeterUtils.getResString("method")); 312 313 314 JPanel panel = new JPanel (new FlowLayout (FlowLayout.LEFT)); 315 316 panel.add(protocolLabel); 317 panel.add(protocol); 318 panel.add(Box.createHorizontalStrut(5)); 319 320 panel.add(methodLabel); 321 panel.add(get); 322 panel.add(post); 323 panel.setMinimumSize(panel.getPreferredSize()); 324 return panel; 325 } 326 327 protected JPanel getParameterPanel() 328 { 329 argsPanel = new HTTPArgumentsPanel(); 330 331 return argsPanel; 332 } 333 } 334 | Popular Tags |