Author: jfrederic.clere(a)jboss.com
Date: 2010-03-05 11:30:48 -0500 (Fri, 05 Mar 2010)
New Revision: 1397
Modified:
sandbox/clients/CometTest.java
sandbox/clients/CometTestSSL.java
Log:
Improve the sessionid checks.
Modified: sandbox/clients/CometTest.java
===================================================================
--- sandbox/clients/CometTest.java 2010-03-05 00:36:32 UTC (rev 1396)
+++ sandbox/clients/CometTest.java 2010-03-05 16:30:48 UTC (rev 1397)
@@ -33,6 +33,7 @@
Exception ex = null;
int max = 0;
boolean failed = true;
+ String lastPartialSess = null;
/**
*
* Usage:
@@ -104,7 +105,7 @@
writechunk(os, "Testing...");
String res = readchunk(in);
String cursess = readsess(res);
- if (sess != null && cursess.compareTo(sess) != 0) {
+ if (sess != null && (cursess == null ||
sess.compareTo(cursess) != 0)) {
System.out.println("Session changed: " + cursess +
" " + sess);
break;
}
@@ -133,10 +134,15 @@
while (len == -1) {
try {
data = in.readLine();
+ // System.out.println("DATA (len): " + data);
len = Integer.valueOf(data, 16);
- // System.out.println("Got: " + len);
} catch (Exception ex) {
System.out.println("Ex: " + ex);
+ } finally {
+ if (len == 0) {
+ System.out.println("End chunk");
+ throw new Exception("End chunk");
+ }
}
}
len++; // For the CR...
@@ -147,19 +153,21 @@
while (recv != len) {
int i = in.read(buf, offset, len-offset);
recv = recv + i;
+ // System.out.println("DATA: " + recv + ":" +
len);
offset = recv;
}
data = new String(buf);
// System.out.println("DATA: " + recv + " : " +
data);
+ // System.out.println("DATA: " + recv);
return data;
}
- static String readsess(String in)
+ static String getsess(String in)
{
String data = null;
int start = in.indexOf('[');
if (start != -1) {
- int end = in.indexOf(']');
- if (end != -1) {
+ int end = in.indexOf(']');
+ if (end != -1) {
if (end > start) {
data = in.substring(start+1, end);
} else {
@@ -171,9 +179,35 @@
}
}
}
- }
+ }
}
- // System.out.println("SESSION: " + data);
return data;
}
+ String readsess(String input)
+ {
+ String data = null;
+ String in = input;
+
+ data = getsess(in);
+ if (data == null) {
+ /* A small chunk without a complete sessionid */
+ if (this.lastPartialSess == null)
+ this.lastPartialSess = input;
+ else
+ this.lastPartialSess = this.lastPartialSess + input;
+ in = this.lastPartialSess;
+ data = getsess(in);
+ }
+ /* Store the last part of session (for the next "small" chunk)
*/
+ if (data != null) {
+ int start = in.lastIndexOf("["+data+"]");
+ if (start>=0)
+ this.lastPartialSess = in.substring(start);
+ else
+ this.lastPartialSess = null;
+ }
+ if (data == null)
+ System.out.println("SESSION not found in: " + in);
+ return data;
+ }
}
Modified: sandbox/clients/CometTestSSL.java
===================================================================
--- sandbox/clients/CometTestSSL.java 2010-03-05 00:36:32 UTC (rev 1396)
+++ sandbox/clients/CometTestSSL.java 2010-03-05 16:30:48 UTC (rev 1397)
@@ -57,6 +57,7 @@
if (args.length != 1)
{
System.err.println("missing command line arguments");
+ System.err.println("CometTestSSL URL");
System.exit(1);
}
@@ -72,6 +73,7 @@
comet[i].join();
if (comet[i].failed) {
System.err.println("Test failed! " + comet[i].ex);
+ comet[i].ex.printStackTrace();
System.exit(1);
}
}
Show replies by date