Author: sebb
Date: Wed Oct 22 18:33:30 2008
New Revision: 707243

URL: http://svn.apache.org/viewvc?rev=707243&view=rev
Log:
Add classname field to TCP Sampler GUIs

Modified:
    jakarta/jmeter/trunk/docs/images/screenshots/tcpsampler.png
    jakarta/jmeter/trunk/docs/images/screenshots/tcpsamplerconfig.png
    
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java
    
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/images/screenshots/tcpsampler.png
    jakarta/jmeter/trunk/xdocs/images/screenshots/tcpsamplerconfig.png
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/docs/images/screenshots/tcpsampler.png
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/docs/images/screenshots/tcpsampler.png?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/docs/images/screenshots/tcpsamplerconfig.png
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/docs/images/screenshots/tcpsamplerconfig.png?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
Binary files - no diff available.

Modified: 
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties 
(original)
+++ 
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties 
Wed Oct 22 18:33:30 2008
@@ -778,6 +778,7 @@
 table_visualizer_success=Success
 table_visualizer_thread_name=Thread Name
 table_visualizer_warning=Warning
+tcp_classname=TCPClient classname\:
 tcp_config_title=TCP Sampler Config
 tcp_nodelay=Set NoDelay
 tcp_port=Port Number\:

Modified: 
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/config/gui/TCPConfigGui.java
 Wed Oct 22 18:33:30 2008
@@ -32,21 +32,11 @@
 import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.JLabeledTextField;
 
 public class TCPConfigGui extends AbstractConfigGui {
-    private final static String SERVER = "server"; //$NON-NLS-1$
 
-    private final static String RE_USE_CONNECTION = "reUseConnection"; 
//$NON-NLS-1$
-
-    private final static String PORT = "port"; //$NON-NLS-1$
-
-    // NOTUSED yet private final static String FILENAME = "filename";
-    // //$NON-NLS-1$
-    private final static String TIMEOUT = "timeout"; //$NON-NLS-1$
-
-    private final static String NODELAY = "nodelay"; //$NON-NLS-1$
-
-    private final static String REQUEST = "request"; //$NON-NLS-1$
+    private JLabeledTextField classname;
 
     private JTextField server;
 
@@ -78,6 +68,8 @@
 
     public void configure(TestElement element) {
         super.configure(element);
+        // N.B. this will be a config element, so we cannot use the getXXX() 
methods
+        classname.setText(element.getPropertyAsString(TCPSampler.CLASSNAME));
         server.setText(element.getPropertyAsString(TCPSampler.SERVER));
         // Default to original behaviour, i.e. re-use connection
         
reUseConnection.setSelected(element.getPropertyAsBoolean(TCPSampler.RE_USE_CONNECTION,true));
@@ -101,6 +93,8 @@
      */
     public void modifyTestElement(TestElement element) {
         configureTestElement(element);
+        // N.B. this will be a config element, so we cannot use the setXXX() 
methods
+        element.setProperty(TCPSampler.CLASSNAME, classname.getText(), "");
         element.setProperty(TCPSampler.SERVER, server.getText());
         element.setProperty(TCPSampler.RE_USE_CONNECTION, 
reUseConnection.isSelected());
         element.setProperty(TCPSampler.PORT, port.getText());
@@ -116,6 +110,7 @@
     public void clearGui() {
         super.clearGui();
 
+        classname.setText(""); //$NON-NLS-1$
         server.setText(""); //$NON-NLS-1$
         port.setText(""); //$NON-NLS-1$
         timeout.setText(""); //$NON-NLS-1$
@@ -128,7 +123,6 @@
         JLabel label = new JLabel(JMeterUtils.getResString("tcp_timeout")); // 
$NON-NLS-1$
 
         timeout = new JTextField(10);
-        timeout.setName(TIMEOUT);
         label.setLabelFor(timeout);
 
         JPanel timeoutPanel = new JPanel(new BorderLayout(5, 0));
@@ -141,7 +135,6 @@
         JLabel label = new JLabel(JMeterUtils.getResString("tcp_nodelay")); // 
$NON-NLS-1$
 
         setNoDelay = new JCheckBox();
-        setNoDelay.setName(NODELAY);
         label.setLabelFor(setNoDelay);
 
         JPanel nodelayPanel = new JPanel(new BorderLayout(5, 0));
@@ -154,7 +147,6 @@
         JLabel label = new JLabel(JMeterUtils.getResString("server")); // 
$NON-NLS-1$
 
         server = new JTextField(10);
-        server.setName(SERVER);
         label.setLabelFor(server);
 
         JPanel serverPanel = new JPanel(new BorderLayout(5, 0));
@@ -167,7 +159,6 @@
         JLabel label = new 
JLabel(JMeterUtils.getResString("reuseconnection")); //$NON-NLS-1$
 
         reUseConnection = new JCheckBox("", true);
-        reUseConnection.setName(RE_USE_CONNECTION);
         label.setLabelFor(reUseConnection);
 
         JPanel closePortPanel = new JPanel(new BorderLayout(5, 0));
@@ -180,7 +171,6 @@
         JLabel label = new JLabel(JMeterUtils.getResString("tcp_port")); 
//$NON-NLS-1$
 
         port = new JTextField(10);
-        port.setName(PORT);
         label.setLabelFor(port);
 
         JPanel PortPanel = new JPanel(new BorderLayout(5, 0));
@@ -193,7 +183,6 @@
         JLabel reqLabel = new 
JLabel(JMeterUtils.getResString("tcp_request_data")); // $NON-NLS-1$
         requestData = new JTextArea(3, 0);
         requestData.setLineWrap(true);
-        requestData.setName(REQUEST);
         reqLabel.setLabelFor(requestData);
 
         JPanel reqDataPanel = new JPanel(new BorderLayout(5, 0));
@@ -227,9 +216,12 @@
         }
 
         VerticalPanel mainPanel = new VerticalPanel();
-        mainPanel.add(createServerPanel());
+        classname = new 
JLabeledTextField(JMeterUtils.getResString("tcp_classname"));
+        mainPanel.add(classname);
+        final JPanel serverPanel = createServerPanel();
+        serverPanel.add(createPortPanel(), BorderLayout.EAST);
+        mainPanel.add(serverPanel);
         mainPanel.add(createClosePortPanel());
-        mainPanel.add(createPortPanel());
         mainPanel.add(createTimeoutPanel());
         mainPanel.add(createNoDelayPanel());
         mainPanel.add(createRequestPanel());

Modified: 
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
 Wed Oct 22 18:33:30 2008
@@ -49,6 +49,7 @@
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
+    //++ JMX file constants - do not change
     public static final String SERVER = "TCPSampler.server"; //$NON-NLS-1$
 
     public static final String PORT = "TCPSampler.port"; //$NON-NLS-1$
@@ -64,6 +65,7 @@
     public static final String REQUEST = "TCPSampler.request"; //$NON-NLS-1$
 
     public static final String RE_USE_CONNECTION = 
"TCPSampler.reUseConnection"; //$NON-NLS-1$
+    //-- JMX file constants - do not change
 
     private static final String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap
 
@@ -75,11 +77,11 @@
     // JMeterUtils.getPropDefault("tcp.status.regex","");
 
     // Otherwise, the response is scanned for these strings
-    private static final String STATUS_PREFIX = 
JMeterUtils.getPropDefault("tcp.status.prefix", "");
+    private static final String STATUS_PREFIX = 
JMeterUtils.getPropDefault("tcp.status.prefix", ""); //$NON-NLS-1$
 
-    private static final String STATUS_SUFFIX = 
JMeterUtils.getPropDefault("tcp.status.suffix", "");
+    private static final String STATUS_SUFFIX = 
JMeterUtils.getPropDefault("tcp.status.suffix", ""); //$NON-NLS-1$
 
-    private static final String STATUS_PROPERTIES = 
JMeterUtils.getPropDefault("tcp.status.properties", "");
+    private static final String STATUS_PROPERTIES = 
JMeterUtils.getPropDefault("tcp.status.properties", ""); //$NON-NLS-1$
 
     private static final Properties statusProps = new Properties();
 
@@ -87,22 +89,21 @@
 
     static {
         boolean hsp = false;
-        log.debug("Protocol Handler name=" + getClassname());
-        log.debug("Status prefix=" + STATUS_PREFIX);
-        log.debug("Status suffix=" + STATUS_SUFFIX);
-        log.debug("Status properties=" + STATUS_PROPERTIES);
+        log.debug("Status prefix=" + STATUS_PREFIX); //$NON-NLS-1$
+        log.debug("Status suffix=" + STATUS_SUFFIX); //$NON-NLS-1$
+        log.debug("Status properties=" + STATUS_PROPERTIES); //$NON-NLS-1$
         if (STATUS_PROPERTIES.length() > 0) {
             File f = new File(STATUS_PROPERTIES);
             FileInputStream fis = null;
             try {
                 fis = new FileInputStream(f);
                 statusProps.load(fis);
-                log.debug("Successfully loaded properties");
+                log.debug("Successfully loaded properties"); //$NON-NLS-1$
                 hsp = true;
             } catch (FileNotFoundException e) {
-                log.debug("Property file not found");
+                log.debug("Property file not found"); //$NON-NLS-1$
             } catch (IOException e) {
-                log.debug("Property file error " + e.toString());
+                log.debug("Property file error " + e.toString()); //$NON-NLS-1$
             } finally {
                 JOrphanUtils.closeQuietly(fis);
             }
@@ -120,9 +121,7 @@
     private transient TCPClient protocolHandler;
 
     public TCPSampler() {
-        log.debug("Created " + this);
-        protocolHandler = getProtocol();
-        log.debug("Using Protocol Handler: " + 
protocolHandler.getClass().getName());
+        log.debug("Created " + this); //$NON-NLS-1$
     }
 
     private String getError() {
@@ -177,8 +176,8 @@
         return getPropertyAsString(SERVER);
     }
 
-    public void setReUseConnection(String newServer) {
-        this.setProperty(RE_USE_CONNECTION, newServer);
+    public void setReUseConnection(String reuse) {
+        this.setProperty(RE_USE_CONNECTION, reuse);
     }
 
     public boolean isReUseConnection() {
@@ -225,6 +224,18 @@
         return getPropertyAsBoolean(NODELAY);
     }
 
+    public void setClassname(String classname) {
+        this.setProperty(CLASSNAME, classname, ""); //$NON-NLS-1$ 
+    }
+
+    public String getClassname() {
+        String clazz = getPropertyAsString(CLASSNAME,"");
+        if (clazz==null || clazz.length()==0){
+            clazz = JMeterUtils.getPropDefault("tcp.handler", 
"TCPClientImpl"); //$NON-NLS-1$ $NON-NLS-2$            
+        }
+        return clazz;
+    }
+
     /**
      * Returns a formatted string label describing this sampler Example output:
      * Tcp://Tcp.nowhere.com/pub/README.txt
@@ -232,15 +243,10 @@
      * @return a formatted string label describing this sampler
      */
     public String getLabel() {
-        return ("tcp://" + this.getServer() + ":" + 
this.getPort());//$NON-NLS-1$
+        return ("tcp://" + this.getServer() + ":" + 
this.getPort());//$NON-NLS-1$ $NON-NLS-2$
     }
 
-    private static String getClassname() {
-        String className = JMeterUtils.getPropDefault("tcp.handler", 
"TCPClientImpl");
-        return className;
-    }
-
-    private static final String protoPrefix = 
"org.apache.jmeter.protocol.tcp.sampler.";
+    private static final String protoPrefix = 
"org.apache.jmeter.protocol.tcp.sampler."; //$NON-NLS-1$
 
     private Class getClass(String className) {
         Class c = null;
@@ -250,7 +256,7 @@
             try {
                 c = Class.forName(protoPrefix + className, false, 
Thread.currentThread().getContextClassLoader());
             } catch (ClassNotFoundException e1) {
-                log.error("Could not find protocol class " + className);
+                log.error("Could not find protocol class '" + className+"'"); 
//$NON-NLS-1$
             }
         }
         return c;
@@ -260,13 +266,16 @@
     private TCPClient getProtocol() {
         TCPClient TCPClient = null;
         Class javaClass = getClass(getClassname());
+        if (javaClass == null){
+            return null;
+        }
         try {
             TCPClient = (TCPClient) javaClass.newInstance();
             if (log.isDebugEnabled()) {
-                log.debug(this + "Created: " + getClassname() + "@" + 
Integer.toHexString(TCPClient.hashCode()));
+                log.debug(this + "Created: " + getClassname() + "@" + 
Integer.toHexString(TCPClient.hashCode())); //$NON-NLS-1$
             }
         } catch (Exception e) {
-            log.error(this + " Exception creating: " + getClassname(), e);
+            log.error(this + " Exception creating: " + getClassname(), e); 
//$NON-NLS-1$
         }
         return TCPClient;
     }
@@ -276,15 +285,17 @@
         log.debug(getLabel() + " " + getFilename() + " " + getUsername() + " " 
+ getPassword());
         SampleResult res = new SampleResult();
         boolean isSuccessful = false;
-        res.setSampleLabel(getName());// Use the test element name for the
-                                        // label
-        res.setSamplerData("Host: " + getServer() + " Port: " + getPort());
+        res.setSampleLabel(getName());// Use the test element name for the 
label
+        res.setSamplerData("Host: " + getServer() + " Port: " + getPort()); 
//$NON-NLS-1$ $NON-NLS-2$
         res.sampleStart();
         try {
             Socket sock = getSocket();
             if (sock == null) {
-                res.setResponseCode("500");
+                res.setResponseCode("500"); //$NON-NLS-1$
                 res.setResponseMessage(getError());
+            } else if (protocolHandler == null){
+                res.setResponseCode("500"); //$NON-NLS-1$
+                res.setResponseMessage("Protocol handler not found");          
      
             } else {
                 InputStream is = sock.getInputStream();
                 OutputStream os = sock.getOutputStream();
@@ -296,7 +307,7 @@
                 res.setResponseData(in.getBytes());
                 res.setDataType(SampleResult.TEXT);
                 res.setResponseCodeOK();
-                res.setResponseMessage("OK");
+                res.setResponseMessage("OK"); //$NON-NLS-1$
                 isSuccessful = true;
                 // Reset the status code if the message contains one
                 if (STATUS_PREFIX.length() > 0) {
@@ -307,12 +318,12 @@
                         res.setResponseCode(rc);
                         isSuccessful = checkResponseCode(rc);
                         if (haveStatusProps) {
-                            res.setResponseMessage(statusProps.getProperty(rc, 
"Status code not found in properties"));
+                            res.setResponseMessage(statusProps.getProperty(rc, 
"Status code not found in properties")); //$NON-NLS-1$
                         } else {
                             res.setResponseMessage("No status property file");
                         }
                     } else {
-                        res.setResponseCode("999");
+                        res.setResponseCode("999"); //$NON-NLS-1$
                         res.setResponseMessage("Status value not found");
                         isSuccessful = false;
                     }
@@ -320,7 +331,7 @@
             }
         } catch (IOException ex) {
             log.debug("", ex);
-            res.setResponseCode("500");
+            res.setResponseCode("500"); //$NON-NLS-1$
             res.setResponseMessage(ex.toString());
             closeSocket();
         } finally {
@@ -343,18 +354,21 @@
      * @return whether this represents success or not
      */
     private boolean checkResponseCode(String rc) {
-        if (rc.compareTo("400") >= 0 && rc.compareTo("499") <= 0) {
+        if (rc.compareTo("400") >= 0 && rc.compareTo("499") <= 0) { 
//$NON-NLS-1$ $NON-NLS-2$
             return false;
         }
-        if (rc.compareTo("500") >= 0 && rc.compareTo("599") <= 0) {
+        if (rc.compareTo("500") >= 0 && rc.compareTo("599") <= 0) { 
//$NON-NLS-1$ $NON-NLS-2$
             return false;
         }
         return true;
     }
 
     public void threadStarted() {
-        log.debug("Thread Started");
-    }
+        log.debug("Thread Started"); //$NON-NLS-1$
+        protocolHandler = getProtocol();
+        log.debug("Using Protocol Handler: " +  //$NON-NLS-1$
+                (protocolHandler == null ? "NONE" : 
protocolHandler.getClass().getName())); //$NON-NLS-1$
+}
 
     private void closeSocket() {
         Map cp = (Map) tp.get();
@@ -364,13 +378,13 @@
             try {
                 con.close();
             } catch (IOException e) {
-                log.warn("Error closing socket "+e);
+                log.warn("Error closing socket "+e); //$NON-NLS-1$
             }
         }
     }
 
     public void threadFinished() {
-        log.debug("Thread Finished");
+        log.debug("Thread Finished"); //$NON-NLS-1$
         closeSocket();
     }
 }

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Wed Oct 22 18:33:30 2008
@@ -153,6 +153,7 @@
 <li>Allow If Controller to use variable expressions (not just Javascript)</li>
 <li>Bug 45903 - allow Assertions to apply to sub-samples</li>
 <li>Trim spaces from While Controller condition before comparing against LAST, 
blank or false</li>
+<li>Add classname field to TCP Sampler GUIs</li>
 </ul>
 
 <h3>Non-functional changes</h3>

Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/tcpsampler.png
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/tcpsampler.png?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/tcpsamplerconfig.png
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/tcpsamplerconfig.png?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
Binary files - no diff available.

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=707243&r1=707242&r2=707243&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Wed Oct 22 
18:33:30 2008
@@ -965,8 +965,7 @@
 </p>
 </component>
 
-<component name="TCP Sampler" index="&sect-num;.1.12"  width="596" 
height="347" screenshot="tcpsampler.png">
-<note>ALPHA CODE</note>
+<component name="TCP Sampler" index="&sect-num;.1.12"  width="477" 
height="343" screenshot="tcpsampler.png">
        <description>
                <p>
                The TCP Sampler opens a TCP/IP connection to the specified 
server.
@@ -1018,9 +1017,10 @@
 </description>
 <properties>
   <property name="Name" required="">Descriptive name for this element that is 
shown in the tree.</property>
+  <property name="TCPClient classname" required="No">Name of the TCPClient 
class. Defaults to the property tcp.handler, failing that 
TCPClientImpl.</property>
   <property name="ServerName or IP" required="Yes">Name or IP of TCP 
server</property>
-  <property name="Re-use connection" required="Yes">If selected, the 
connection is kept open. Otherwise it is closed when the data has been 
read.</property>
   <property name="Port Number" required="Yes">Port to be used</property>
+  <property name="Re-use connection" required="Yes">If selected, the 
connection is kept open. Otherwise it is closed when the data has been 
read.</property>
   <property name="Timeout (milliseconds)" required="No">Timeout for 
replies</property>
   <property name="Set Nodelay" required="No">Should the nodelay property be 
set?</property>
   <property name="Text to Send" required="Yes">Text to be sent</property>
@@ -2714,8 +2714,7 @@
 
 </component>
 
-<component name="TCP Sampler Config" index="&sect-num;.4.12"  width="645" 
height="256" screenshot="tcpsamplerconfig.png">
-       <note>ALPHA CODE</note>
+<component name="TCP Sampler Config" index="&sect-num;.4.12"  width="476" 
height="272" screenshot="tcpsamplerconfig.png">
 <description>
         <p>
        The TCP Sampler Config provides default data for the TCP Sampler
@@ -2723,8 +2722,10 @@
 </description>
 <properties>
   <property name="Name" required="">Descriptive name for this element that is 
shown in the tree.</property>
+  <property name="TCPClient classname" required="No">Name of the TCPClient 
class. Defaults to the property tcp.handler, failing that 
TCPClientImpl.</property>
   <property name="ServerName or IP" required="">Name or IP of TCP 
server</property>
   <property name="Port Number" required="">Port to be used</property>
+  <property name="Re-use connection" required="Yes">If selected, the 
connection is kept open. Otherwise it is closed when the data has been 
read.</property>
   <property name="Timeout (milliseconds)" required="">Timeout for 
replies</property>
   <property name="Set Nodelay" required="">Should the nodelay property be 
set?</property>
   <property name="Text to Send" required="">Text to be sent</property>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to