You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by jb...@apache.org on 2001/12/12 23:01:50 UTC

cvs commit: jakarta-jmeter/src/org/apache/jmeter/protocol/ftp/sampler FTPSampler.java

jboutcher    01/12/12 14:01:50

  Modified:    src/org/apache/jmeter/protocol/ftp/config FtpConfig.java
               src/org/apache/jmeter/protocol/ftp/sampler FTPSampler.java
  Log:
  fix of bug 5088 - FTP Sampler issues when exceptions occur on connect
  
  Revision  Changes    Path
  1.9       +11 -0     jakarta-jmeter/src/org/apache/jmeter/protocol/ftp/config/FtpConfig.java
  
  Index: FtpConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/ftp/config/FtpConfig.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FtpConfig.java	2001/11/09 18:29:50	1.8
  +++ FtpConfig.java	2001/12/12 22:01:50	1.9
  @@ -144,4 +144,15 @@
   	{
   		return (String)this.getProperty(FILENAME);
   	}
  +
  +    /**
  +     * Returns a formatted string label describing this sampler
  +     * Example output:
  +     *      ftp://ftp.nowhere.com/pub/README.txt
  +     *
  +     * @return a formatted string label describing this sampler
  +     */
  +    public String getLabel() {
  +        return ("ftp://" + this.getServer() + "/" + this.getFilename());
  +    }
   }
  
  
  
  1.9       +29 -12    jakarta-jmeter/src/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java
  
  Index: FTPSampler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FTPSampler.java	2001/08/16 23:36:56	1.8
  +++ FTPSampler.java	2001/12/12 22:01:50	1.9
  @@ -52,7 +52,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  - package org.apache.jmeter.protocol.ftp.sampler;
  +package org.apache.jmeter.protocol.ftp.sampler;
   
   import java.sql.*;
   import org.apache.jmeter.util.JMeterUtils;
  @@ -65,14 +65,15 @@
   /************************************************************
    *  A sampler which understands FTP file requests
    *
  - *@author     $Author: mstover1 $
  - *@created    $Date: 2001/08/16 23:36:56 $
  - *@version    $Revision: 1.8 $
  + *@author     $Author: jboutcher $
  + *@created    $Date: 2001/12/12 22:01:50 $
  + *@version    $Revision: 1.9 $
    ***********************************************************/
   
   public class FTPSampler implements Sampler
   {
   
  +
   	/************************************************************
   	 *  !ToDo (Constructor description)
   	 ***********************************************************/
  @@ -92,31 +93,47 @@
   		Connection con = null;
   		ResultSet rs = null;
   		Statement stmt = null;
  +        boolean isSuccessful = false;
   		FtpConfig ftpConfig = (FtpConfig)e.getConfigElement(FtpConfig.class);
  -		LoginConfig loginConfig = (LoginConfig)e.getConfigElement(LoginConfig.class);
  +        res.putValue(SampleResult.SAMPLE_LABEL,ftpConfig.getLabel());
  +        LoginConfig loginConfig = (LoginConfig)e.getConfigElement(LoginConfig.class);
   		long start = System.currentTimeMillis();
   		try
   		{
  -			System.out.println("Connecting to "+ftpConfig.getServer()+" trying to get "+ftpConfig.getFilename());
  -			System.out.println("Username = "+loginConfig.getUsername());
  +            // removed the next two lines - System.out.println is a resource DOG, and putting this in the middle
  +            // of a timed operation skews the results big time. -- jkb
  +//			System.out.println("Connecting to "+ftpConfig.getServer()+" trying to get "+ftpConfig.getFilename());
  +//			System.out.println("Username = "+loginConfig.getUsername());
   			FtpClient ftp = new FtpClient();
   			ftp.connect(ftpConfig.getServer(), loginConfig.getUsername(),
   					loginConfig.getPassword());
  -			ftp.setPassive(true);
  +			ftp.setPassive(true); // this should probably come from the setup dialog
   			String s = ftp.get(ftpConfig.getFilename());
   			res.putValue(SampleResult.TEXT_RESPONSE,s);
  -			res.putValue(SampleResult.SAMPLE_LABEL,ftpConfig.getServer()+"/"+ftpConfig.getFilename());
  +            // set the response code here somewhere
   			ftp.disconnect();
  +            isSuccessful = true;
   			//System.out.println(s);
   		}
  -		catch (Exception ex)
  +		catch (java.net.ConnectException cex)
   		{
  -			//System.out.println(ex.toString());
  +            // java.net.ConnectException -- 502 error code?
  +            // in the future, possibly define and place error codes into the
  +            // result so we know exactly what happened.
  +            res.putValue(SampleResult.TEXT_RESPONSE, cex.toString());
   		}
  -		// Calculate response time
  +        catch (Exception ex) {
  +            // general exception
  +            res.putValue(SampleResult.TEXT_RESPONSE, ex.toString());
  +        }
  +
  +        // Calculate response time
   		long end = System.currentTimeMillis();
  +        res.setTime(end - start);
  +
  +        // Set if we were successful or not
  +        res.putValue(SampleResult.SUCCESS, new Boolean(isSuccessful));
   
  -		res.setTime(end - start);
   		return res;
   	}
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>