tusharbhatia 01/08/16 11:17:56
Modified: src/org/apache/jmeter/protocol/http/sampler HTTPSampler.java
src/org/apache/jmeter/reporters Filer.java
src/org/apache/jmeter/save/handlers FilerHandler.java
src/org/apache/jmeter/visualizers FileVisualizer.java
Log:
View of submitted data for Http submits. autoFlush and viewSubmitData property
added to Filer, visualizer and handler.
Revision Changes Path
1.21 +29 -25
jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
Index: HTTPSampler.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- HTTPSampler.java 2001/08/15 10:45:33 1.20
+++ HTTPSampler.java 2001/08/16 18:17:56 1.21
@@ -6,7 +6,7 @@
* companies.
*
* All rights reserved
- * $Header:
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
1.20 2001/08/15 10:45:33 neth Exp $
+ * $Header:
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
1.21 2001/08/16 18:17:56 tusharbhatia Exp $
*/
package org.apache.jmeter.protocol.http.sampler;
@@ -21,6 +21,7 @@
import org.apache.jmeter.config.*;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.samplers.HttpSampleResult;
import org.apache.jmeter.samplers.Entry;
import org.apache.log4j.*;
@@ -30,8 +31,8 @@
* HTTP requests, including cookies and authentication.
*
*@author Michael Stover
- *@created $Date: 2001/08/15 10:45:33 $
- *@version $Revision: 1.20 $
+ *@created $Date: 2001/08/16 18:17:56 $
+ *@version $Revision: 1.21 $
*/
public class HTTPSampler implements Sampler
{
@@ -83,9 +84,9 @@
protected static String encoding = "iso-8859-1";
- protected static final String NON_HTTP_RESPONSE_CODE =
+ protected static final String NON_HTTP_RESPONSE_CODE =
"Non HTTP response code";
- protected static final String NON_HTTP_RESPONSE_MESSAGE =
+ protected static final String NON_HTTP_RESPONSE_MESSAGE =
"Non HTTP response message";
private static Category catClass = Category.getInstance(
@@ -169,14 +170,14 @@
}
/**
- * This method will setup <code>HttpURLConnection</code> to handle post using
+ * This method will setup <code>HttpURLConnection</code> to handle post using
* <code>sendPostData</code> method if the URL request is actually a html
form
* that needs to be posted
*
* @param redirected does <code>HttpURLConnection</code> allow
redirection
* @param url contains query string for POST
* @param conn <HttpURLConnection> of the URL request
- * @exception IOException if
+ * @exception IOException if
*/
protected void writeToStream(boolean redirected, UrlConfig url,
HttpURLConnection conn) throws IOException
{
@@ -199,10 +200,10 @@
* Extracts all the required cookies for that particular URL request and
set them
* in the <code>HttpURLConnection</code> passed in
*
- * @param conn <code>HttpUrlConnection</code> which
represents the
+ * @param conn <code>HttpUrlConnection</code> which
represents the
* URL request
* @param u <code>URL</code> of the URL request
- * @param cookieManager the <code>CookieManager</code> containing all
the
+ * @param cookieManager the <code>CookieManager</code> containing all
the
* cookies for this <code>UrlConfig</code>
*/
private void setConnectionCookie(HttpURLConnection conn, URL u, CookieManager
cookieManager)
@@ -221,10 +222,10 @@
* Extracts all the required headers for that particular URL request and
set them
* in the <code>HttpURLConnection</code> passed in
*
- * @param conn <code>HttpUrlConnection</code> which
represents the
+ * @param conn <code>HttpUrlConnection</code> which
represents the
* URL request
* @param u <code>URL</code> of the URL request
- * @param headerManager the <code>HeaderManager</code> containing all
the
+ * @param headerManager the <code>HeaderManager</code> containing all
the
* cookies for this <code>UrlConfig</code>
*/
private void setConnectionHeaders(HttpURLConnection conn, URL u, HeaderManager
headerManager)
@@ -245,13 +246,13 @@
}
/**
- * Extracts all the required authorization for that particular URL request
and set
+ * Extracts all the required authorization for that particular URL request
and set
* them in the <code>HttpURLConnection</code> passed in
*
- * @param conn <code>HttpUrlConnection</code> which
represents the
+ * @param conn <code>HttpUrlConnection</code> which
represents the
* URL request
* @param u <code>URL</code> of the URL request
- * @param authManager the <code>AuthManager</code> containing all
the
+ * @param authManager the <code>AuthManager</code> containing all the
* cookies for this <code>UrlConfig</code>
*/
private void setConnectionAuthorization(HttpURLConnection conn, URL u,
AuthManager authManager)
@@ -285,7 +286,7 @@
responseCode = ((HttpURLConnection) conn).getResponseCode();
errorLevel = responseCode / 100;
message = ((HttpURLConnection) conn).getResponseMessage();
- res.putValue(this.RESPONSE_CODE,
+ res.putValue(this.RESPONSE_CODE,
String.valueOf(responseCode));
res.putValue(this.RESPONSE_MESSAGE,
message);
@@ -293,9 +294,9 @@
catch (Exception e2)
{
res.putValue(this.TEXT_RESPONSE, e2.toString());
- res.putValue(this.RESPONSE_CODE,
+ res.putValue(this.RESPONSE_CODE,
NON_HTTP_RESPONSE_CODE);
- res.putValue(this.RESPONSE_MESSAGE,
+ res.putValue(this.RESPONSE_MESSAGE,
NON_HTTP_RESPONSE_MESSAGE);
res.setTime(System.currentTimeMillis() - time);
res.putValue(SampleResult.SUCCESS, new Boolean(false));
@@ -311,7 +312,7 @@
* that the "Location" value needs to be followed to get the resultant page.
*
* @param conn connection
- * @param u
+ * @param u
* @exception MalformedURLException if URL is not understood
*/
private void redirectUrl(HttpURLConnection conn, URL u, UrlConfig urlConfig)
throws MalformedURLException
@@ -340,7 +341,7 @@
}
/**
- * Samples <code>Entry</code> passed in and stores the result in
+ * Samples <code>Entry</code> passed in and stores the result in
* <code>SampleResult</code>
*
* @param e <code>Entry</code> to be sampled
@@ -351,14 +352,17 @@
{
catClass.debug("Start : sample2");
long time;
- SampleResult res = new SampleResult();
+ SampleResult res = new HttpSampleResult();
UrlConfig url = getUrlConfig(e);
-
+
URL u = null;
try
{
u = url.getUrl();
res.putValue(Sampler.SAMPLE_LABEL, u.toString());
+ // specify the data to the result.
+ res.putValue(HttpSampleResult.DATA, url);
+
System.out.println("Sampling url: " + u);
if(catClass.isDebugEnabled())
{
@@ -400,9 +404,9 @@
{
ex.printStackTrace();
res.setTime((long) 0);
- res.putValue(this.RESPONSE_CODE,
+ res.putValue(this.RESPONSE_CODE,
NON_HTTP_RESPONSE_CODE);
- res.putValue(this.RESPONSE_MESSAGE,
+ res.putValue(this.RESPONSE_MESSAGE,
NON_HTTP_RESPONSE_MESSAGE);
res.putValue(this.TEXT_RESPONSE, ex.toString());
res.putValue(SampleResult.SUCCESS, new Boolean(false));
@@ -415,10 +419,10 @@
* From the <code>HttpURLConnection</code>, store all the "set-cookie"
key-pair
* values in the cookieManager of the <code>UrlConfig</code>
*
- * @param conn <code>HttpUrlConnection</code> which
represents the
+ * @param conn <code>HttpUrlConnection</code> which
represents the
* URL request
* @param u <code>URL</code> of the URL request
- * @param cookieManager the <code>CookieManager</code> containing all
the
+ * @param cookieManager the <code>CookieManager</code> containing all
the
* cookies for this <code>UrlConfig</code>
*/
private void saveConnectionCookies(HttpURLConnection conn, URL u,
CookieManager cookieManager)
1.10 +169 -162 jakarta-jmeter/src/org/apache/jmeter/reporters/Filer.java
Index: Filer.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/reporters/Filer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Filer.java 2001/08/09 18:48:51 1.9
+++ Filer.java 2001/08/16 18:17:56 1.10
@@ -75,171 +75,178 @@
public class Filer implements JMeterComponentModel,SampleListener,Saveable
{
- private String name;
- private FileVisualizer listener;
+ private String name;
+ private FileVisualizer listener;
- private boolean verbose = true;
- private boolean append = true;
- private boolean open = false;
- private String file;
- private PrintWriter stream;
-
- // if set to true, the file will flush each time a sample is recorded.
- // required for non-gui testing. Will be added to GUI in a little bit.
- private boolean autoFlush = false;
-
- public Filer()
- {
- }
-
- public void setListener(FileVisualizer l)
- {
- listener = l;
- }
-
- public Class getGuiClass()
- {
- return org.apache.jmeter.visualizers.FileVisualizer.class;
- }
-
- public boolean getAppend()
- {
- return append;
- }
-
- public void addJMeterComponent(JMeterComponentModel child)
- {
- }
-
- public void setAppend(boolean a)
- {
- append = a;
- }
-
- public void setVerbose(boolean v)
- {
- verbose = v;
- }
-
- public boolean getVerbose()
- {
- return verbose;
- }
-
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public Collection getAddList()
- {
- return null;
- }
- public String getClassLabel()
- {
- return "File Reporter";
- }
-
- public void uncompile()
- {
-
- }
-
- public Class getTagHandlerClass()
- {
- return org.apache.jmeter.save.handlers.FilerHandler.class;
- }
-
- public void sampleStarted(SampleEvent e)
- {
- }
-
- public void sampleStopped(SampleEvent e)
- {
- }
-
- public void sampleOccurred(SampleEvent e)
- {
- recordSample(e.getResult());
- if(open && autoFlush)
- flush();
- if(listener != null)
- {
- listener.updateGui();
- }
- }
-
- private void recordSample(SampleResult sampleResult)
- {
- long sample = sampleResult.getTime();
- if (open) {
- if (verbose) {
-
stream.println(sampleResult.getValue(SampleResult.SAMPLE_LABEL) + " " + sample);
- } else {
- stream.println(sample);
- }
- }
- }
-
- public void open(){
- try
- {
- this.stream = new PrintWriter(new
BufferedOutputStream(new FileOutputStream(this.file, this.append)), false);
- if (verbose) {
- this.stream.println("\n# Sample data created by " +
-
JMeterUtils.getJMeterProperties().getProperty("version"));
- this.stream.println("\n# URL
Milliseconds\n");
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- this.open = true;
- }
-
- public void flush() {
- try
- {
- this.stream.flush();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
-
-
- }
-
- public void close() {
- this.open = false;
- try
- {
- this.stream.flush();
- this.stream.close();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
-
-
- }
-
- public String getFile()
- {
- return file;
- }
+ private boolean verbose = true;
+ private boolean append = true;
+ private boolean open = false;
+ private String file;
+ private PrintWriter stream;
+
+ // if set to true, the file will flush each time a sample is recorded.
+ // required for non-gui testing. Will be added to GUI in a little bit.
+ private boolean autoFlush = false;
+ // Set viewSubmitData to true to allow the submitted data to be captured from the
sample result.
+ // currently works only for HttpSampleResult (and HttpSampler, HttpSamplerFull)
+ private boolean viewSubmitData = false;
+
+ public Filer(){
+ }
+
+ public void setListener(FileVisualizer l){
+ listener = l;
+ }
+
+ public Class getGuiClass(){
+ return org.apache.jmeter.visualizers.FileVisualizer.class;
+ }
+
+ public boolean getAppend()
+ {
+ return append;
+ }
+
+ public void addJMeterComponent(JMeterComponentModel child)
+ {
+ }
+
+ public void setAppend(boolean a)
+ {
+ append = a;
+ }
+
+ public void setVerbose(boolean v){
+ verbose = v;
+ }
+
+ public boolean getVerbose()
+ {
+ return verbose;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+ public Collection getAddList()
+ {
+ return null;
+ }
+ public String getClassLabel()
+ {
+ return "File Reporter";
+ }
+
+ public void uncompile()
+ {
+
+ }
+
+ public Class getTagHandlerClass()
+ {
+ return org.apache.jmeter.save.handlers.FilerHandler.class;
+ }
+
+ public void sampleStarted(SampleEvent e)
+ {
+ }
+
+ public void sampleStopped(SampleEvent e)
+ {
+ }
+
+ public void sampleOccurred(SampleEvent e)
+ {
+ recordSample(e.getResult());
+ if(open && autoFlush)
+ flush();
+ if(listener != null)
+ {
+ listener.updateGui();
+ }
+ }
+
+ private void recordSample(SampleResult sampleResult)
+ {
+ long sample = sampleResult.getTime();
+ String data = (String)sampleResult.getValue(HttpSampleResult.DATA);
+ if (open) {
+ if (verbose) {
+ stream.print(sampleResult.getValue(SampleResult.SAMPLE_LABEL) + " " +
sample);
+ if(data != null)
+ stream.println(HttpSampleResult.DATA_SEPARATOR + data);
+ else
+ stream.println("");
+ } else {
+ stream.println(sample);
+ }
+ }
+ }
+
+ public void open(){
+ try
+ {
+ this.stream = new PrintWriter(new BufferedOutputStream(new
FileOutputStream(this.file, this.append)), false);
+ if (verbose) {
+ this.stream.println("\n# Sample data created by " +
JMeterUtils.getJMeterProperties().getProperty("version"));
+ if(viewSubmitData)
+ this.stream.println("\n# URL Milliseconds
Data\n");
+ else
+ this.stream.println("\n# URL Milliseconds\n");
+ }
+ this.open = true;
+ }catch (Exception ex){
+ ex.printStackTrace();
+ }
+ }
+ public void flush() {
+ try{
+ this.stream.flush();
+ }catch (Exception ex){
+ ex.printStackTrace();
+ }
+ }
+
+ public void close() {
+ try{
+ if(this.open){
+ this.stream.flush();
+ this.stream.close();
+ }
+ }catch (Exception ex){
+ ex.printStackTrace();
+ }
+ this.open = false;
+ }
+
+ public String getFile()
+ {
+ return file;
+ }
- public void setFile(String file) {
+ public void setFile(String file) {
this.file = file;
- }
+ }
- public void setAutoFlush(boolean value) {
- this.autoFlush = value;
- }
+ public void setAutoFlush(boolean value) {
+ this.autoFlush = value;
+ }
+
+ public boolean getAutoFlush(){
+ return autoFlush;
+ }
+
+ public boolean getViewSubmitData(){
+ return viewSubmitData;
+ }
+
+ public void setViewSubmitData(boolean value){
+ this.viewSubmitData = value;
+ }
}
1.4 +13 -0
jakarta-jmeter/src/org/apache/jmeter/save/handlers/FilerHandler.java
Index: FilerHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/save/handlers/FilerHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FilerHandler.java 2001/07/26 00:34:50 1.3
+++ FilerHandler.java 2001/08/16 18:17:56 1.4
@@ -34,6 +34,10 @@
out.write(""+save.getVerbose());
out.write("\" append=\"");
out.write(""+save.getAppend());
+ out.write("\" autoFlush=\"");
+ out.write("" + save.getAutoFlush());
+ out.write("\" viewSubmitData=\"");
+ out.write("" + save.getViewSubmitData());
out.write("\" file=\"");
out.write(JMeterHandler.convertToXML(save.getFile()));
out.write("\"/>");
@@ -46,6 +50,15 @@
model.setFile(atts.getValue("file"));
model.setVerbose(atts.getValue("verbose").equals("true") ? true
:false);
model.setAppend(atts.getValue("append").equals("true") ? true :false);
+ String data = atts.getValue("viewSubmitData");
+ if(data == null) // check for backward compatibility
+ data = "";
+ model.setViewSubmitData(data.equals("true"));
+ data = atts.getValue("autoFlush");
+ if(data == null)
+ data = "";
+ model.setAutoFlush(data.equals("true"));
+
}
public String getPrimaryTagName()
1.20 +44 -81
jakarta-jmeter/src/org/apache/jmeter/visualizers/FileVisualizer.java
Index: FileVisualizer.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/visualizers/FileVisualizer.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- FileVisualizer.java 2001/07/26 00:34:52 1.19
+++ FileVisualizer.java 2001/08/16 18:17:56 1.20
@@ -140,7 +140,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version $Revision: 1.19 $ $Date: 2001/07/26 00:34:52 $
+ * @version $Revision: 1.20 $ $Date: 2001/08/16 18:17:56 $
*/
@@ -156,7 +156,7 @@
JFileChooser fileChooser;
- JCheckBox appendCheck, verboseCheck;
+ JCheckBox appendCheck, verboseCheck, autoFlushCheck, viewSubmitDataCheck;
JComboBox fileList;
@@ -256,27 +256,30 @@
verboseCheck = new JCheckBox("Verbose Output", model.getVerbose());
-
verboseCheck.addActionListener(this);
-
c.gridx = 1;
-
g.setConstraints(verboseCheck, c);
-
filePanel.add(verboseCheck);
+ autoFlushCheck = new JCheckBox("Auto Flush",
model.getAutoFlush());
+ autoFlushCheck.addActionListener(this);
+ c.gridx = 2;
+ g.setConstraints(autoFlushCheck, c);
+ filePanel.add(autoFlushCheck);
+
+ viewSubmitDataCheck = new JCheckBox("Submit Data",
model.getViewSubmitData());
+ viewSubmitDataCheck.addActionListener(this);
+ c.gridx = 3;
+ g.setConstraints(viewSubmitDataCheck, c);
+ filePanel.add(viewSubmitDataCheck);
+ viewSubmitDataCheck.setEnabled(model.getVerbose());
-
+ c.gridy = 2;
openButton = new JButton("Open");
-
openButton.addActionListener(this);
-
openButton.setEnabled(true);
-
c.gridx = 2;
-
g.setConstraints(openButton, c);
-
filePanel.add(openButton);
@@ -338,15 +341,10 @@
{
browseButton.setEnabled(false);
-
openButton.setEnabled(false);
-
flushButton.setEnabled(true);
-
closeButton.setEnabled(true);
-
model.open();
-
}
@@ -354,17 +352,11 @@
public void close()
{
-
browseButton.setEnabled(true);
-
openButton.setEnabled(true);
-
flushButton.setEnabled(false);
-
closeButton.setEnabled(false);
-
model.close();
-
}
@@ -372,15 +364,10 @@
public void setFile(String file)
{
-
fileList.removeItem(file);
-
fileList.addItem(file);
-
fileList.getEditor().setItem(file);
-
model.setFile(file);
-
}
@@ -396,63 +383,39 @@
public void actionPerformed(ActionEvent e) {
try {
-
JComponent c = (JComponent) e.getSource();
-
if(c == fileList) {
-
- setFile((String) fileList.getSelectedItem());
-
- } else if (c == appendCheck) {
-
- model.setAppend(appendCheck.isSelected());
-
- } else if (c == browseButton) {
-
- /*
-
- int retval = fileChooser.showOpenDialog(this);
-
- if (retval == JFileChooser.APPROVE_OPTION) {
-
- this.file =
fileChooser.getSelectedFile().toString();
-
- */
-
- File tmp = FileDialoger.promptToOpenFile().getSelectedFile();
-
- if( tmp != null ) {
-
- setFile(tmp.toString());
-
- }
-
- } else if (c == openButton) {
-
- open();
-
- } else if (c == flushButton) {
-
- model.flush();
-
- } else if (c == closeButton) {
-
- close();
-
- } else if (c == verboseCheck) {
-
- model.setVerbose(verboseCheck.isSelected());
-
- } else {
-
- // do nothing!
-
- }
-
+ setFile((String) fileList.getSelectedItem());
+ } else if (c == appendCheck) {
+ model.setAppend(appendCheck.isSelected());
+ }else if (c == browseButton) {
+ File tmp =
FileDialoger.promptToOpenFile().getSelectedFile();
+ if( tmp != null ) {
+ setFile(tmp.toString());
+ }
+ } else if (c == openButton) {
+ open();
+ } else if (c == flushButton) {
+ model.flush();
+ } else if (c == closeButton) {
+ close();
+ } else if (c == verboseCheck) {
+ model.setVerbose(verboseCheck.isSelected());
+ if(!verboseCheck.isSelected()){
+ viewSubmitDataCheck.setSelected(false);
+ model.setViewSubmitData(false);
+ viewSubmitDataCheck.setEnabled(false);
+ }else
+ viewSubmitDataCheck.setEnabled(true);
+ } else if(c == viewSubmitDataCheck){
+ model.setViewSubmitData(viewSubmitDataCheck.isSelected());
+ } else if(c == autoFlushCheck){
+ model.setAutoFlush(autoFlushCheck.isSelected());
+ } else {
+ // do nothing!
+ }
} catch (Exception ex) {
-
JOptionPane.showMessageDialog(this, ex, "Error",
JOptionPane.ERROR_MESSAGE);
-
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]