sebb 2004/06/10 08:21:15
Modified: src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag:
rel-2_0 TCPSampler.java
Log:
Added: status extraction; property file for translation statuses
Revision Changes Path
No revision
No revision
1.5.2.3 +85 -7
jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java
Index: TCPSampler.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -u -r1.5.2.2 -r1.5.2.3
--- TCPSampler.java 2 Apr 2004 22:56:50 -0000 1.5.2.2
+++ TCPSampler.java 10 Jun 2004 15:21:14 -0000 1.5.2.3
@@ -18,6 +18,9 @@
package org.apache.jmeter.protocol.tcp.sampler;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,6 +30,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import org.apache.jmeter.config.ConfigTestElement;
@@ -61,6 +65,38 @@
private static Set allSockets = new HashSet();// Keep track of connections to
allow close
+ // If set, this is the regex that is used to extract the status from the
response
+ //NOT implemented yet private final static String STATUS_REGEX =
JMeterUtils.getPropDefault("tcp.status.regex","");
+
+ // Otherwise, the response is scanned for these strings
+ private final static String STATUS_PREFIX =
JMeterUtils.getPropDefault("tcp.status.prefix","");
+ private final static String STATUS_SUFFIX =
JMeterUtils.getPropDefault("tcp.status.suffix","");
+
+ private final static String STATUS_PROPERTIES =
JMeterUtils.getPropDefault("tcp.status.properties","");
+ private final static Properties statusProps = new Properties();
+ private static boolean haveStatusProps = false;
+
+ static
+ {
+ log.info("Protocol Handler name="+getClassname());
+ log.info("Status prefix="+STATUS_PREFIX);
+ log.info("Status suffix="+STATUS_SUFFIX);
+ log.info("Status properties="+STATUS_PROPERTIES);
+ if (STATUS_PROPERTIES.length()>0)
+ {
+ File f = new File(STATUS_PROPERTIES);
+ try {
+ statusProps.load(new FileInputStream(f));
+ log.info("Successfully loaded properties");
+ haveStatusProps = true;
+ } catch (FileNotFoundException e) {
+ log.info("Property file not found");
+ } catch (IOException e) {
+ log.info("Property file error "+e.toString());
+ }
+ }
+ }
+
/** the cache of TCP Connections */
private static ThreadLocal tp = new ThreadLocal(){
protected Object initialValue(){
@@ -74,6 +110,8 @@
{
log.debug("Created "+this);
protocolHandler=getProtocol();
+ log.debug("Using Protocol Handler: "
+ +protocolHandler.getClass().getName());
}
private String getError(){
@@ -196,7 +234,7 @@
return ("tcp://" + this.getServer() + ":" + this.getPort());//$NON-NLS-1$
}
- private String getClassname()
+ private static String getClassname()
{
String className =
JMeterUtils.getPropDefault("tcp.handler","TCPClientImpl");
return className;
@@ -276,6 +314,33 @@
res.setResponseCode("200");
res.setResponseMessage("OK");
isSuccessful = true;
+ //Reset the status code if the message contains one
+ if (STATUS_PREFIX.length() > 0)
+ {
+ int i = in.indexOf(STATUS_PREFIX);
+ int j = in.indexOf(STATUS_SUFFIX,i+STATUS_PREFIX.length());
+ if (i != -1 && j > i)
+ {
+ String rc = in.substring(i+STATUS_PREFIX.length(),j);
+ res.setResponseCode(rc);
+ isSuccessful = checkResponseCode(rc);
+ if (haveStatusProps)
+ {
+ res.setResponseMessage(
+
statusProps.getProperty(rc,"Status code not found in properties"));
+ }
+ else
+ {
+ res.setResponseMessage("No status property
file");
+ }
+ }
+ else
+ {
+ res.setResponseCode("999");
+ res.setResponseMessage("Status value not found");
+ isSuccessful=false;
+ }
+ }
}
}
catch (Exception ex)
@@ -294,7 +359,23 @@
return res;
}
- private void disconnectAll(){
+ /**
+ * @param rc response code
+ * @return whether this represents success or not
+ */
+ private boolean checkResponseCode(String rc) {
+ if (rc.compareTo("400")>=0 && rc.compareTo("499")<=0)
+ {
+ return false;
+ }
+ if (rc.compareTo("500")>=0 && rc.compareTo("599")<=0)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private void disconnectAll(){
synchronized (allSockets)
{
Iterator i = allSockets.iterator();
@@ -322,8 +403,6 @@
public void testStarted() // Only called once per class?
{
log.debug(this+" test started");
- // TODO Auto-generated method stub
-
}
/* (non-Javadoc)
@@ -333,7 +412,6 @@
{
log.debug(this+" test ended");
disconnectAll();
-
}
/* (non-Javadoc)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]