KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > config > gui > UrlConfigGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java,v 1.16.2.2 2004/05/20 15:23:12 mstover1 Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.http.config.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.awt.FlowLayout JavaDoc;
24
25 import javax.swing.BorderFactory JavaDoc;
26 import javax.swing.Box JavaDoc;
27 import javax.swing.ButtonGroup JavaDoc;
28 import javax.swing.JCheckBox JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.JRadioButton JavaDoc;
32 import javax.swing.JTextField JavaDoc;
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 /**
47  * @author Michael Stover
48  * @version $Revision: 1.16.2.2 $
49  */

50 public class UrlConfigGui extends JPanel JavaDoc
51 {
52     protected HTTPArgumentsPanel argsPanel;
53     private static String JavaDoc DOMAIN = "domain";
54     private static String JavaDoc PORT = "port";
55     private static String JavaDoc PROTOCOL = "protocol";
56     private static String JavaDoc PATH = "path";
57     private static String JavaDoc FOLLOW_REDIRECTS = "follow_redirects";
58     private static String JavaDoc AUTO_REDIRECTS = "auto_redirects";
59     private static String JavaDoc USE_KEEPALIVE = "use_keepalive";
60
61     private JTextField JavaDoc domain;
62     private JTextField JavaDoc port;
63     private JTextField JavaDoc protocol;
64     private JTextField JavaDoc path;
65     private JCheckBox JavaDoc followRedirects;
66     private JCheckBox JavaDoc autoRedirects;
67     private JCheckBox JavaDoc useKeepAlive;
68     private JRadioButton JavaDoc post;
69     private JRadioButton JavaDoc 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 // Does not appear to be used
123
// public void configureSampler(HTTPSampler sampler)
124
// {
125
// sampler.setArguments((Arguments) argsPanel.createTestElement());
126
// sampler.setDomain(domain.getText());
127
// sampler.setProtocol(protocol.getText());
128
// sampler.setPath(path.getText());
129
// sampler.setFollowRedirects(followRedirects.isSelected());
130
// sampler.setDelegateRedirects(autoRedirects.isSelected());
131
// sampler.setUseKeepAlive(useKeepAlive.isSelected());
132
// if (port.getText().length() > 0)
133
// {
134
// sampler.setPort(Integer.parseInt(port.getText()));
135
// }
136
// sampler.setMethod((post.isSelected() ? "POST" : "GET"));
137
// }
138

139     /**
140      * Set the text, etc. in the UI.
141      *
142      * @param el contains the data to be displayed
143      */

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 JavaDoc portString = (String JavaDoc) el.getPropertyAsString(HTTPSampler.PORT);
154
155         // Only display the port number if it is meaningfully specified
156
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 JavaDoc());
191
192         JPanel JavaDoc webServerPanel = new JPanel JavaDoc();
193
194         webServerPanel.setLayout(new BorderLayout JavaDoc());
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 JavaDoc webRequestPanel = new JPanel JavaDoc();
203
204         webRequestPanel.setLayout(new BorderLayout JavaDoc());
205         webRequestPanel.setBorder(
206             BorderFactory.createTitledBorder(
207                 BorderFactory.createEtchedBorder(),
208                 JMeterUtils.getResString("web_request")));
209         JPanel JavaDoc northPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
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 JavaDoc getPortPanel()
221     {
222         port = new JTextField JavaDoc(6);
223         port.setName(PORT);
224
225         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("web_server_port"));
226         label.setLabelFor(port);
227
228         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
229         panel.add(label, BorderLayout.WEST);
230         panel.add(port, BorderLayout.CENTER);
231
232         return panel;
233     }
234
235     protected JPanel JavaDoc getDomainPanel()
236     {
237         domain = new JTextField JavaDoc(20);
238         domain.setName(DOMAIN);
239
240         JLabel JavaDoc label =
241             new JLabel JavaDoc(JMeterUtils.getResString("web_server_domain"));
242         label.setLabelFor(domain);
243         
244         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
245         panel.add(label, BorderLayout.WEST);
246         panel.add(domain, BorderLayout.CENTER);
247         return panel;
248     }
249
250     /**
251      * This method defines the Panel for the HTTP path, 'Follow Redirects' and
252      * 'Use KeepAlive' elements.
253      *
254      * @return JPanel The Panel for the path, 'Follow Redirects' and
255      * 'Use KeepAlive' elements.
256      */

257     protected Component JavaDoc getPathPanel()
258     {
259         path = new JTextField JavaDoc(15);
260         path.setName(PATH);
261
262         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("path"));
263         label.setLabelFor(path);
264
265         autoRedirects =
266             new JCheckBox JavaDoc(JMeterUtils.getResString("follow_redirects_auto"));
267         autoRedirects.setName(AUTO_REDIRECTS);
268         autoRedirects.setSelected(false);// will be reset by configure(TestElement)
269

270         followRedirects =
271             new JCheckBox JavaDoc(JMeterUtils.getResString("follow_redirects"));
272         followRedirects.setName(FOLLOW_REDIRECTS);
273         followRedirects.setSelected(true);
274
275         useKeepAlive = new JCheckBox JavaDoc(JMeterUtils.getResString("use_keepalive"));
276         useKeepAlive.setName(USE_KEEPALIVE);
277         useKeepAlive.setSelected(true);
278
279         JPanel JavaDoc panel = new JPanel JavaDoc(new FlowLayout JavaDoc(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 JavaDoc getProtocolAndMethodPanel()
293     {
294         // PROTOCOL
295
protocol = new JTextField JavaDoc(4);
296         protocol.setName(PROTOCOL);
297
298         JLabel JavaDoc protocolLabel = new JLabel JavaDoc(JMeterUtils.getResString("protocol"));
299         protocolLabel.setLabelFor(protocol);
300
301         // METHOD
302
ButtonGroup JavaDoc methodButtonGroup = new ButtonGroup JavaDoc();
303
304         get = new JRadioButton JavaDoc(JMeterUtils.getResString("url_config_get"));
305         methodButtonGroup.add(get);
306
307         post = new JRadioButton JavaDoc(JMeterUtils.getResString("url_config_post"));
308         methodButtonGroup.add(post);
309         post.setSelected(true);
310
311         JLabel JavaDoc methodLabel = new JLabel JavaDoc(JMeterUtils.getResString("method"));
312
313
314         JPanel JavaDoc panel = new JPanel JavaDoc(new FlowLayout JavaDoc(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 JavaDoc getParameterPanel()
328     {
329         argsPanel = new HTTPArgumentsPanel();
330
331         return argsPanel;
332     }
333 }
334
Popular Tags