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 ms...@apache.org on 2002/04/19 04:18:11 UTC
cvs commit: jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/config MultipartUrlConfig.java UrlConfig.java
mstover1 02/04/18 19:18:11
Added: src_1/org/apache/jmeter/protocol/ftp/config FtpConfig.java
src_1/org/apache/jmeter/protocol/ftp/config/gui
FtpConfigGui.java
src_1/org/apache/jmeter/protocol/ftp/control/gui
FtpTestSamplerGui.java
src_1/org/apache/jmeter/protocol/ftp/sampler FTPSampler.java
FtpClient.java
src_1/org/apache/jmeter/protocol/http/config
MultipartUrlConfig.java UrlConfig.java
Log:
Revision Changes Path
1.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/ftp/config/FtpConfig.java
Index: FtpConfig.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.ftp.config;
import org.apache.jmeter.config.*;
import org.apache.jmeter.util.JMeterUtils;
import java.util.Collection;
import java.io.*;
/**
* Title: JMeter
* Description:
* Copyright: Copyright (c) 2000
* Company: Apache
* @author Michael Stover
* @version 1.0
*/
public class FtpConfig extends ConfigTestElement implements Serializable
{
public static final String SERVER = "server";
public static final String FILENAME = "filename";
public FtpConfig()
{
}
public boolean isComplete()
{
if ((getServer() != null) &&
(getFilename() != null) &&
(!getServer().equals("")) &&
(!getFilename().equals("")))
{
return true;
}
else return false;
}
public void setServer(String newServer)
{
this.setProperty(SERVER,newServer);
}
public String getServer()
{
return (String)this.getProperty(SERVER);
}
public void setFilename(String newFilename)
{
this.setProperty(FILENAME,newFilename);
}
public String getFilename()
{
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.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/ftp/config/gui/FtpConfigGui.java
Index: FtpConfigGui.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.ftp.config.gui;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import org.apache.jmeter.gui.*;
import org.apache.jmeter.gui.util.VerticalLayout;
import org.apache.jmeter.protocol.ftp.config.*;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.config.gui.AbstractConfigGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.protocol.ftp.sampler.FTPSampler;
import org.apache.jmeter.config.ConfigTestElement;
/****************************************
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache
*
*@author Michael Stover
*@created $Date: 2002/04/19 02:18:11 $
*@version 1.0
***************************************/
public class FtpConfigGui extends AbstractConfigGui
{
private final static String SERVER = "server";
private final static String FILENAME = "filename";
private JTextField server = new JTextField(20);
private JTextField filename = new JTextField(20);
private boolean displayName = true;
private NamePanel namePanel;
/****************************************
* !ToDo (Constructor description)
***************************************/
public FtpConfigGui()
{
this(true);
}
public String getStaticLabel()
{
return JMeterUtils.getResString("ftp_sample_title");
}
public void setName(String name)
{
super.setName(name);
namePanel.setName(name);
}
public String getName()
{
return namePanel.getName();
}
public void configure(TestElement element)
{
setName((String)element.getProperty(TestElement.NAME));
server.setText((String)element.getProperty(FTPSampler.SERVER));
filename.setText((String)element.getProperty(FTPSampler.FILENAME));
}
public TestElement createTestElement()
{
ConfigTestElement element = new ConfigTestElement();
configureTestElement(element);
element.setProperty(FTPSampler.SERVER,server.getText());
element.setProperty(FTPSampler.FILENAME,filename.getText());
return element;
}
/****************************************
* !ToDo (Constructor description)
*
*@param displayName !ToDo (Parameter description)
***************************************/
public FtpConfigGui(boolean displayName)
{
this.displayName = displayName;
namePanel = new NamePanel();
setName(getStaticLabel());
init();
}
private JPanel createServerPanel()
{
JPanel serverPanel = new JPanel();
serverPanel.add(new JLabel(JMeterUtils.getResString("server")));
server.setName(SERVER);
serverPanel.add(server);
return serverPanel;
}
private JPanel createFilenamePanel()
{
JPanel filenamePanel = new JPanel();
filenamePanel.add(new JLabel(JMeterUtils.getResString("file_to_retrieve")));
filename.setName(FILENAME);
filenamePanel.add(filename);
return filenamePanel;
}
private void init()
{
this.setLayout(new VerticalLayout(1, VerticalLayout.LEFT));
if(displayName)
{
this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
// MAIN PANEL
JPanel mainPanel = new JPanel();
Border margin = new EmptyBorder(10, 10, 5, 10);
mainPanel.setBorder(margin);
mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
// TITLE
JLabel panelTitleLabel = new JLabel(JMeterUtils.getResString("ftp_sample_title"));
Font curFont = panelTitleLabel.getFont();
int curFontSize = curFont.getSize();
curFontSize += 4;
panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize));
mainPanel.add(panelTitleLabel);
// NAME
mainPanel.add(namePanel);
// LOOP
mainPanel.add(createServerPanel());
mainPanel.add(createFilenamePanel());
this.add(mainPanel);
}
else
{
this.add(createServerPanel());
this.add(createFilenamePanel());
}
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/ftp/control/gui/FtpTestSamplerGui.java
Index: FtpTestSamplerGui.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.ftp.control.gui;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import org.apache.jmeter.config.gui.LoginConfigGui;
import org.apache.jmeter.config.gui.LoginConfigGui;
import org.apache.jmeter.gui.*;
import org.apache.jmeter.gui.util.VerticalLayout;
import org.apache.jmeter.protocol.ftp.config.gui.FtpConfigGui;
import org.apache.jmeter.protocol.ftp.control.*;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.protocol.ftp.sampler.FTPSampler;
/****************************************
* Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
* Apache Foundation
*
*@author Michael Stover
*@created $Date: 2002/04/19 02:18:11 $
*@version 1.0
***************************************/
public class FtpTestSamplerGui extends AbstractSamplerGui
{
private LoginConfigGui loginPanel;
private FtpConfigGui ftpDefaultPanel;
/****************************************
* !ToDo (Constructor description)
***************************************/
public FtpTestSamplerGui()
{
init();
}
public void configure(TestElement element)
{
super.configure(element);
loginPanel.configure(element);
ftpDefaultPanel.configure(element);
}
public TestElement createTestElement()
{
FTPSampler sampler = new FTPSampler();
sampler.addTestElement(ftpDefaultPanel.createTestElement());
sampler.addTestElement(loginPanel.createTestElement());
this.configureTestElement(sampler);
return sampler;
}
public String getStaticLabel()
{
return JMeterUtils.getResString("ftp_testing_title");
}
private void init()
{
this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
// MAIN PANEL
JPanel mainPanel = new JPanel();
Border margin = new EmptyBorder(10, 10, 5, 10);
mainPanel.setBorder(margin);
mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
// TITLE
JLabel panelTitleLabel = new JLabel(JMeterUtils.getResString("ftp_testing_title"));
Font curFont = panelTitleLabel.getFont();
int curFontSize = curFont.getSize();
curFontSize += 4;
panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize));
mainPanel.add(panelTitleLabel);
// NAME
mainPanel.add(getNamePanel());
loginPanel = new LoginConfigGui(false);
ftpDefaultPanel = new FtpConfigGui(false);
//ftpDefaultPanel.setBorder(BorderFactory.createTitledBorder("Default Values"));
loginPanel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("login_config")));
mainPanel.add(getNamePanel());
mainPanel.add(ftpDefaultPanel);
mainPanel.add(loginPanel);
this.add(mainPanel);
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/ftp/sampler/FTPSampler.java
Index: FTPSampler.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.ftp.sampler;
import java.sql.*;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.config.*;
import org.apache.jmeter.protocol.ftp.config.*;
import org.apache.jmeter.samplers.Sampler;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.testelement.TestElement;
/************************************************************
* A sampler which understands FTP file requests
*
*@author $Author: mstover1 $
*@created $Date: 2002/04/19 02:18:11 $
*@version $Revision: 1.1 $
***********************************************************/
public class FTPSampler extends AbstractSampler
{
public final static String SERVER = "FTPSampler.server";
public final static String FILENAME = "FTPSampler.filename";
/************************************************************
* !ToDo (Constructor description)
***********************************************************/
public FTPSampler()
{
}
public void addCustomTestElement(TestElement element)
{
}
/************************************************************
* !ToDo (Method description)
*
*@param e !ToDo (Parameter description)
*@return !ToDo (Return description)
***********************************************************/
public SampleResult sample(Entry e)
{
SampleResult res = new SampleResult();
Connection con = null;
ResultSet rs = null;
Statement stmt = null;
boolean isSuccessful = false;
FtpConfig ftpConfig = (FtpConfig)e.getConfigElement(FtpConfig.class);
res.putValue(SampleResult.SAMPLE_LABEL,ftpConfig.getLabel());
LoginConfig loginConfig = (LoginConfig)e.getConfigElement(LoginConfig.class);
long start = System.currentTimeMillis();
try
{
// 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); // this should probably come from the setup dialog
String s = ftp.get(ftpConfig.getFilename());
res.putValue(SampleResult.TEXT_RESPONSE,s.getBytes());
// set the response code here somewhere
ftp.disconnect();
isSuccessful = true;
//System.out.println(s);
}
catch (java.net.ConnectException cex)
{
// 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().getBytes());
}
catch (Exception ex) {
// general exception
res.putValue(SampleResult.TEXT_RESPONSE, ex.toString().getBytes());
}
// 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));
return res;
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/ftp/sampler/FtpClient.java
Index: FtpClient.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.ftp.sampler;
import java.io.*;
import java.net.*;
/*
* Simple FTP client (non-passive transfers don't work yet)
* kind of a hack, lots of room for optimizations
*/
/**
* Description of the Class
*
*@author mike
*@created August 31, 2001
*/
public class FtpClient
{
File f = new File("e:\\");
OutputStream out;
BufferedReader in;
Socket s;
boolean passive = false;
static int port = 21;
static int dataPort = 4096;
/**
* Constructor for the FtpClient object
*/
public FtpClient()
{
}
/**
* set passive mode
*
*@param flag The new Passive value
*/
public void setPassive(boolean flag)
{
passive = flag;
}
/**
* get a file from the server
*
*@return The Response value
*@exception IOException Description of Exception
*/
public String getResponse() throws IOException
{
StringBuffer response = new StringBuffer();
String line = in.readLine();
response.append(line);
//System.out.println("#" + line + "#");
while (line.charAt(3) == '-')
{
line = in.readLine();
response.append("\n");
response.append(line);
//System.out.println("#" + line + "#");
}
//System.out.println("return response");
return response.toString();
}
/**
* get a file from the server
*
*@param file Description of Parameter
*@return Description of the Returned Value
*@exception Exception Description of Exception
*/
public String get(String file) throws Exception
{
send("SYST");
getResponse();
send("PWD");
getResponse();
send("TYPE I");
getResponse();
String data = "";
if (!passive)
{
dataPort++;
int upper = getUpper(dataPort);
int lower = getLower(dataPort);
String ip = InetAddress.getLocalHost().getHostAddress().replace('.', ',');
String port = ip + "," + upper + "," + lower;
System.out.println("port:" + port);
send("PORT " + port);
getResponse();
dataGrabber grab = new dataGrabber(ip, dataPort);
while (!grab.isPortCreated())
{
}
send("RETR " + file);
String response = in.readLine();
System.out.println(response);
System.out.println(dataPort);
data = "FTP client - File Not Found";
if (!response.startsWith("5"))
{
while (!grab.isDone())
{
}
data = grab.getData();
}
}
else
{
send("PASV");
String port = getResponse();
while (!port.startsWith("227"))
{
port = getResponse();
}
int start = port.indexOf('(');
int end = port.indexOf(')');
port = port.substring(start + 1, end);
int a = port.indexOf(',');
int b = port.indexOf(',', a + 1);
int c = port.indexOf(',', b + 1);
int d = port.indexOf(',', c + 1);
int e = port.indexOf(',', d + 1);
String ip = port.substring(0, a) + "." + port.substring(a + 1, b) + "." + port.substring(b + 1, c) + "." + port.substring(c + 1, d);
int upper = Integer.parseInt(port.substring(d + 1, e));
int lower = Integer.parseInt(port.substring(e + 1));
int dataPort = getPort(upper, lower);
send("RETR " + file);
dataGrabber grab = new dataGrabber(ip, dataPort);
getResponse();
while (!grab.isDone())
{
}
data = grab.getData();
}
return data;
}
/**
* connect to server
*
*@param host Description of Parameter
*@param username Description of Parameter
*@param password Description of Parameter
*@exception Exception Description of Exception
*/
public void connect(String host, String username, String password) throws Exception
{
InetAddress addr = InetAddress.getByName(host);
s = new Socket(addr, port);
out = s.getOutputStream();
InputStreamReader isr = new InputStreamReader(s.getInputStream());
in = new BufferedReader(isr);
//System.out.println(in.readLine());
send("USER " + username);
//System.out.println(getResponse());
send("PASS " + password);
//System.out.println(getResponse());
//System.out.println("Done connecting");
}
/**
* disconnect from the server
*/
public void disconnect()
{
try
{
send("QUIT");
getResponse();
}
catch (Exception e)
{
System.out.println("FTP client - " + e.toString());
}
try
{
in.close();
out.close();
s.close();
}
catch (Exception e)
{
System.out.println("FTP client - " + e.toString());
}
}
/**
* send a command to the server
*
*@param command Description of Parameter
*@exception IOException Description of Exception
*/
public void send(String command) throws IOException
{
//System.out.println("#" + command + "#");
for (int i = 0; i < command.length(); i++)
{
out.write(command.charAt(i));
}
out.write('\r');
out.write('\n');
out.flush();
}
/**
* Gets the Port attribute of the FtpClient class
*
*@param upper Description of Parameter
*@param lower Description of Parameter
*@return The Port value
*/
public static int getPort(int upper, int lower)
{
return upper * 256 + lower;
}
/**
* Gets the Upper attribute of the FtpClient class
*
*@param port Description of Parameter
*@return The Upper value
*/
public static int getUpper(int port)
{
return port / 256;
}
/**
* Gets the Lower attribute of the FtpClient class
*
*@param port Description of Parameter
*@return The Lower value
*/
public static int getLower(int port)
{
return port % 256;
}
/**
* grabs the data from the dataport
*
*@author mike
*@created August 31, 2001
*/
public class dataGrabber implements Runnable
{
StringBuffer buffer = new StringBuffer();
Socket s;
boolean done = false;
boolean portCreated = false;
String host = "";
int port = 22;
/**
* Constructor for the dataGrabber object
*
*@param host Description of Parameter
*@param port Description of Parameter
*@exception Exception Description of Exception
*/
public dataGrabber(String host, int port) throws Exception
{
this.host = host;
this.port = port;
new Thread((Runnable) this).start();
}
/**
* Gets the Done attribute of the dataGrabber object
*
*@return The Done value
*/
public boolean isDone()
{
return done;
}
/**
* Gets the Data attribute of the dataGrabber object
*
*@return The Data value
*/
public String getData()
{
return buffer.toString();
}
/**
* Gets the PortCreated attribute of the dataGrabber object
*
*@return The PortCreated value
*/
public boolean isPortCreated()
{
return portCreated;
}
/**
* Main processing method for the dataGrabber object
*/
public void run()
{
try
{
if (passive)
{
s = new Socket(host, port);
}
else
{
System.out.println("creating socket on " + port);
ServerSocket server = new ServerSocket(port);
System.out.println("accepting...");
portCreated = true;
s = server.accept();
System.out.println("accepted");
}
}
catch (Exception e)
{
}
try
{
InputStream in = s.getInputStream();
BufferedInputStream dataIn = new BufferedInputStream(in);
int bufferSize = 4096;
byte[] inputBuffer = new byte[bufferSize];
int i = 0;
while ((i = dataIn.read(inputBuffer, 0, bufferSize)) != -1)
{
buffer.append((char) i);
}
dataIn.close();
s.close();
}
catch (Exception e)
{
System.out.println("FTP client: dataGrabber - " + e.toString());
}
done = true;
}
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/config/MultipartUrlConfig.java
Index: MultipartUrlConfig.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.http.config;
import java.io.*;
import org.apache.jmeter.config.ConfigElement;
import org.apache.jmeter.util.JMeterUtils;
/**
* Title: JMeter
* Description:
* Copyright: Copyright (c) 2000
* Company: Apache
* @author Michael Stover
* @version 1.0
*/
public class MultipartUrlConfig extends UrlConfig implements Serializable
{
public static String MULTIPART_FORM = "multipart/form-data";
private static String FILENAME = "filename";
private static String FIELDNAME = "fieldname";
private static String MIMETYPE = "mimetype";
private static String BOUNDARY = "boundary";
public MultipartUrlConfig()
{
super();
}
public MultipartUrlConfig(String boundary)
{
setBoundary(boundary);
}
public void setBoundary(String boundary)
{
setProperty(BOUNDARY,boundary);
}
public String getBoundary()
{
return (String)this.getProperty(BOUNDARY);
}
public String getClassLabel()
{
return "HTTP Multipart Request Defaults";
}
/**
* !ToDo (Method description)
*
*@return !ToDo (Return description)
*/
public Object clone()
{
MultipartUrlConfig newConfig = new MultipartUrlConfig();
configureClone(newConfig);
return newConfig;
}
public void setFilename(String filename)
{
setProperty(FILENAME,filename);
}
public String getFilename()
{
return (String)this.getProperty(FILENAME);
}
public void setFileFieldName(String name)
{
setProperty(FIELDNAME,name);
}
public String getFileFieldName()
{
return (String)this.getProperty(FIELDNAME);
}
public void setMimeType(String type)
{
setProperty(MIMETYPE,type);
}
public String getMimeType()
{
return (String)this.getProperty(MIMETYPE);
}
public InputStream getFileStream() throws IOException
{
return new BufferedInputStream(new FileInputStream(getFilename()));
}
/**
* This method allows a proxy server to send over the raw text from a browser's
* output stream to be parsed and stored correctly into the UrlConfig object.
*/
public void parseArguments(String queryString)
{
String[] parts = JMeterUtils.split(queryString,"--"+getBoundary());
for (int i = 0; i < parts.length; i++)
{
if(parts[i].indexOf("filename=") > -1)
{
int index = parts[i].indexOf("name=\"")+6;
String name = parts[i].substring(index,parts[i].indexOf("\"",index));
index = parts[i].indexOf("filename=\"")+10;
String filename = parts[i].substring(index,parts[i].indexOf("\"",index));
index = parts[i].indexOf("\n",index);
index = parts[i].indexOf(":",index)+1;
String mimetype = parts[i].substring(index,parts[i].indexOf("\n",index)).trim();
this.setFileFieldName(name);
this.setFilename(filename);
this.setMimeType(mimetype);
}
else if(parts[i].indexOf("name=") > -1)
{
int index = parts[i].indexOf("name=\"")+6;
String name = parts[i].substring(index,parts[i].indexOf("\"",index));
index = parts[i].indexOf("\n",index)+2;
String value = parts[i].substring(index).trim();
this.addArgument(name,value);
}
}
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/protocol/http/config/UrlConfig.java
Index: UrlConfig.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.protocol.http.config;
import java.util.*;
import java.net.*;
import org.apache.jmeter.config.*;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.util.JMeterUtils;
import java.io.*;
/**
* Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
* Apache Foundation
*
* This class defines the default properties for an HTTP Request element. So,
* if you do not specify a value for an HTTP Request field, JMeter uses
* the value you specify here.
*
*@author Michael Stover
*@created $Date: 2002/04/19 02:18:11 $
*@version $Revision: 1.1 $
*/
public class UrlConfig extends AbstractTestElement implements Serializable
{
/**
* Description of the Field
*/
public final static String DOMAIN = "domain";
/**
* Description of the Field
*/
public final static String PORT = "port";
/**
* Description of the Field
*/
public final static String PATH = "path";
/**
* Description of the Field
*/
public final static String METHOD = "method";
/**
* Description of the Field
*/
public final static String ARGUMENTS = "arguments";
/**
* Description of the Field
*/
public final static String POST = "POST";
/**
* Description of the Field
*/
public final static String PROTOCOL = "PROTOCOL";
/**
* Description of the Field
*/
public final static String GET = "GET";
/**
* Constructor for the UrlConfig object
*/
public UrlConfig()
{
this.setProperty(ARGUMENTS, new Arguments());
}
public void setArguments(Arguments args)
{
setProperty(ARGUMENTS,args);
}
/**
* Sets the Method attribute of the UrlConfig object
*
*@param meth The new Method value
*/
public void setMethod(String meth)
{
setProperty(METHOD, meth);
}
/**
* Sets the Protocol attribute of the UrlConfig object
*
*@param protocol The new Protocol value
*/
public void setProtocol(String protocol)
{
setProperty(PROTOCOL, protocol);
}
public void removeArguments()
{
setProperty(ARGUMENTS,new Arguments());
}
/**
* Sets the Port attribute of the UrlConfig object
*
*@param port The new Port value
*/
public void setPort(int port)
{
setProperty(PORT, new Integer(port));
if (port == 0)
{
removeProperty(PORT);
}
}
/**
* Sets the Path attribute of the UrlConfig object
*
*@param path The new Path value
*/
public void setPath(String path)
{
int index = path.indexOf("?");
if (index >= 0)
{
String queryString = path.substring(index + 1);
setProperty(PATH, path.substring(0, index));
parseArguments(queryString);
}
else
{
setProperty(PATH, path);
}
}
public void addArgument(String name,String value)
{
Arguments args = this.getArguments();
args.addArgument(name,value);
}
/**
* Sets the Domain attribute of the UrlConfig object
*
*@param domain The new Domain value
*/
public void setDomain(String domain)
{
setProperty(DOMAIN, domain);
}
/**
* !ToDoo (Method description)
*
*@return !ToDo (Return description)
*@exception MalformedURLException !ToDo (Exception description)
*/
public URL getUrl() throws MalformedURLException
{
String pathAndQuery = null;
if (this.getMethod().equals(this.GET) && getQueryString().length() > 0)
{
pathAndQuery = this.getPath() + "?" + getQueryString();
}
else
{
pathAndQuery = this.getPath();
}
if (!pathAndQuery.startsWith("/"))
{
pathAndQuery = "/" + pathAndQuery;
}
if (getPort() == 0)
{
return new URL(getProtocol(), getDomain(), pathAndQuery);
}
else
{
return new URL(getProtocol(), (String) getProperty(DOMAIN), getPort(),
pathAndQuery);
}
}
/**
* Gets the Port attribute of the UrlConfig object
*
*@return The Port value
*/
public int getPort()
{
Object port = getProperty(PORT);
if (port == null)
{
removeProperty(PORT);
return 0;
}
else if (port instanceof Integer)
{
return ((Integer) port).intValue();
}
else if (port instanceof String)
{
Integer intPort = new Integer((String) port);
setProperty(PORT, intPort);
return intPort.intValue();
}
return 0;
}
/**
* Gets the Protocol attribute of the UrlConfig object
*
*@return The Protocol value
*/
public String getProtocol()
{
String protocol = (String) getProperty(PROTOCOL);
return protocol;
}
/**
* Gets the Path attribute of the UrlConfig object
*
*@return the path if it exists; otherwise, return a single forward slash
*/
public String getPath()
{
String path = (String)getProperty(PATH);
if (path == null)
{
path = "/";
}
return path;
}
/**
* Gets the Domain attribute of the UrlConfig object
*
*@return The Domain value
*/
public String getDomain()
{
return (String) getProperty(DOMAIN);
}
/**
* Gets the Method attribute of the UrlConfig object
*
*@return The Method value
*/
public String getMethod()
{
return (String) getProperty(METHOD);
}
/**
* Gets the Arguments attribute of the UrlConfig object
*
*@return The Arguments value
*/
public Arguments getArguments()
{
return (Arguments) getProperty(this.ARGUMENTS);
}
/**
* Gets the QueryString attribute of the UrlConfig object
*
*@return The QueryString value
*/
public String getQueryString()
{
StringBuffer buf = new StringBuffer();
Iterator iter = getArguments().iterator();
boolean first = true;
while (iter.hasNext())
{
Argument item = (Argument) iter.next();
if (!first)
{
buf.append("&");
}
else
{
first = false;
}
buf.append(URLEncoder.encode(item.getName()) + "=" + URLEncoder.encode((String)item.getValue()));
}
return buf.toString();
}
/**
* Gets the Complete attribute of the UrlConfig object
*
*@return The Complete value
*/
public boolean isComplete()
{
boolean isGood = false;
try
{
this.getUrl();
isGood = true;
}
catch (Exception ex)
{
}
return isGood;
}
/**
* This method allows a proxy server to send over the raw text from a browser's
* output stream to be parsed and stored correctly into the UrlConfig object.
*/
public void parseArguments(String queryString)
{
String[] args = JMeterUtils.split(queryString, "&");
for (int i = 0; i < args.length; i++)
{
int index = args[i].indexOf("=");
if(index > -1)
{
String name = args[i].substring(0,index);
String value = args[i].substring(index + 1);
// In JDK 1.2, the decode() method has a throws clause:
// "throws Exception". In JDK 1.3, the method does not have
// a throws clause. So, in order to be JDK 1.2 compliant,
// we need to add a try/catch around the method call.
try
{
addArgument(name, URLDecoder.decode(value));
}
catch (Exception e)
{
System.out.println("UrlConfig:parseArguments(): Unable to parse argument=[" + value + "]");
System.out.println("UrlConfig:parseArguments(): queryString=[" + queryString + "]");
}
}
}
}
public static UrlConfig createConfig(String contentType)
{
if(contentType != null && contentType.startsWith(MultipartUrlConfig.MULTIPART_FORM))
{
return new MultipartUrlConfig(contentType.substring(contentType.indexOf("oundary=")+8));
}
else
{
return new UrlConfig();
}
}
public static class Test extends junit.framework.TestCase
{
public Test(String name)
{
super(name);
}
public void testMakingUrl() throws Exception
{
UrlConfig config = new UrlConfig();
config.setProtocol("http");
config.setMethod(GET);
config.addArgument("param1","value1");
config.setPath("/index.html");
config.setDomain("www.apache.org");
assertEquals("http://www.apache.org/index.html?param1=value1",config.getUrl().toString());
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>