66import net .tootallnate .websocket .Draft ;
77import net .tootallnate .websocket .WebSocket ;
88import net .tootallnate .websocket .WebSocketClient ;
9- import net .tootallnate .websocket .drafts .Draft_10 ;
109import net .tootallnate .websocket .drafts .Draft_17 ;
1110
12-
1311public class AutobahnClientTest extends WebSocketClient {
1412
15- public AutobahnClientTest ( Draft d , URI uri ) {
16- super ( d , uri );
13+ public AutobahnClientTest ( Draft d , URI uri ) {
14+ super ( uri , d );
1715 }
1816 /**
1917 * @param args
2018 */
2119 public static void main ( String [] args ) {
22- System .out .println ("Testutility to profile/test this implementation using the Autobahn suit.\n " );
23- System .out .println ("Type 'r <casenumber>' to run a testcase. Example: r 1" );
24- System .out .println ("Type 'r <first casenumber> <last casenumber>' to run a testcase. Example: r 1 295" );
25- System .out .println ("Type 'u' to update the test results." );
26- System .out .println ("Type 'ex' to terminate the program." );
27- System .out .println ("During sequences of cases the debugoutput will be turned of." );
28-
29- System .out .println ("You can now enter in your commands:" );
30-
20+ System .out .println ( "Testutility to profile/test this implementation using the Autobahn suit.\n " );
21+ System .out .println ( "Type 'r <casenumber>' to run a testcase. Example: r 1" );
22+ System .out .println ( "Type 'r <first casenumber> <last casenumber>' to run a testcase. Example: r 1 295" );
23+ System .out .println ( "Type 'u' to update the test results." );
24+ System .out .println ( "Type 'ex' to terminate the program." );
25+ System .out .println ( "During sequences of cases the debugoutput will be turned of." );
26+
27+ System .out .println ( "You can now enter in your commands:" );
28+
3129 try {
32- BufferedReader sysin = new BufferedReader ( new InputStreamReader ( System .in ) );
33-
30+ BufferedReader sysin = new BufferedReader ( new InputStreamReader ( System .in ) );
3431
3532 /*First of the thinks a programmer might want to change*/
3633 Draft d = new Draft_17 ();
37- String clientname = "Client " ;
38-
39- String protocol = "ws" ;
40- String host = "localhost" ;
34+ String clientname = "tootallnate/websocket " ;
35+
36+ String protocol = "ws" ;
37+ String host = "localhost" ;
4138 int port = 9001 ;
42-
43- String serverlocation = protocol + "://" + host + ":" + port ;
39+
40+ String serverlocation = protocol + "://" + host + ":" + port ;
4441 String line = "" ;
45- AutobahnClientTest e ;
42+ AutobahnClientTest e ;
4643 URI uri = null ;
4744 String perviousline = "" ;
4845 String nextline = null ;
49- Integer start = null ;
46+ Integer start = null ;
5047 Integer end = null ;
51-
52- while ( !line .contains ( "ex" ) ){
48+
49+ while ( !line .contains ( "ex" ) ) {
5350 try {
54- if (nextline != null ) {
51+ if ( nextline != null ) {
5552 line = nextline ;
5653 nextline = null ;
5754 WebSocket .DEBUG = false ;
58- }
59- else {
60- System .out .print (">" );
55+ } else {
56+ System .out .print ( ">" );
6157 line = sysin .readLine ();
6258 WebSocket .DEBUG = true ;
6359 }
64- if (line .equals ( "l" )) {
60+ if ( line .equals ( "l" ) ) {
6561 line = perviousline ;
6662 }
6763 String [] spl = line .split ( " " );
68- if (line .startsWith ( "r" )) {
69- if ( spl .length == 3 ) {
70- start = new Integer ( spl [1 ] );
71- end = new Integer ( spl [2 ] );
64+ if ( line .startsWith ( "r" ) ) {
65+ if ( spl .length == 3 ) {
66+ start = new Integer ( spl [ 1 ] );
67+ end = new Integer ( spl [ 2 ] );
7268 }
73- if ( start != null && end != null ){
74- if (start > end ) {
69+ if ( start != null && end != null ) {
70+ if ( start > end ) {
7571 start = null ;
7672 end = null ;
77- }
78- else {
79- nextline = "r " +start ;
73+ } else {
74+ nextline = "r " + start ;
8075 start ++;
8176 if ( spl .length == 3 )
8277 continue ;
8378 }
8479 }
85- uri = URI .create ( serverlocation +"/runCase?case=" +spl [1 ]+"&agent=" +clientname );
86-
87- }
88- else if (line .startsWith ( "u" )){
89- uri = URI .create ( serverlocation +"/updateReports?agent=" +clientname );
90- }
91- else if (line .startsWith ( "d" )){
80+ uri = URI .create ( serverlocation + "/runCase?case=" + spl [ 1 ] + "&agent=" + clientname );
81+
82+ } else if ( line .startsWith ( "u" ) ) {
83+ uri = URI .create ( serverlocation + "/updateReports?agent=" + clientname );
84+ } else if ( line .startsWith ( "d" ) ) {
9285 try {
93- d = ( Draft ) Class .forName ( "Draft_" + spl [1 ] ).getConstructor ( ).newInstance ( );
94- } catch ( Exception ex ) {
95- System .out .println ( "Could not change draft" + ex );
86+ d = (Draft ) Class .forName ( "Draft_" + spl [ 1 ] ).getConstructor ().newInstance ();
87+ } catch ( Exception ex ) {
88+ System .out .println ( "Could not change draft" + ex );
9689 }
9790 }
98- if ( uri == null ) {
99- System .out .println ("Do not understand the input." );
91+ if ( uri == null ) {
92+ System .out .println ( "Do not understand the input." );
10093 continue ;
10194 }
102- System .out .println ("//////////////////////Exec: " + uri .getQuery ());
103- e = new AutobahnClientTest ( d , uri );
95+ System .out .println ( "//////////////////////Exec: " + uri .getQuery () );
96+ e = new AutobahnClientTest ( d , uri );
10497 Thread t = new Thread ( e );
10598 t .start ();
10699 try {
107- t .join (5000 );
100+ t .join ( 15000 );
101+
108102 } catch ( InterruptedException e1 ) {
109103 e1 .printStackTrace ();
104+ } finally {
105+ e .close ();
110106 }
111107 } catch ( ArrayIndexOutOfBoundsException e1 ) {
112- System .out .println ("Bad Input r 1, u 1, d 10, ex" );
113- }
114- catch (IllegalArgumentException e2 ) {
108+ System .out .println ( "Bad Input r 1, u 1, d 10, ex" );
109+ } catch ( IllegalArgumentException e2 ) {
115110 e2 .printStackTrace ();
116111 }
117-
112+
118113 }
119114 } catch ( ArrayIndexOutOfBoundsException e ) {
120- System .out .println ("Missing server uri" );
121- }
122- catch (IllegalArgumentException e ) {
115+ System .out .println ( "Missing server uri" );
116+ } catch ( IllegalArgumentException e ) {
123117 e .printStackTrace ();
124- System .out .println ("URI should look like ws://localhost:8887 or wss://echo.websocket.org" );
118+ System .out .println ( "URI should look like ws://localhost:8887 or wss://echo.websocket.org" );
125119 } catch ( IOException e ) {
126120 e .printStackTrace ();
127121 }
@@ -132,32 +126,33 @@ else if(line.startsWith( "d" )){
132126 public void onMessage ( String message ) {
133127 try {
134128 send ( message );
135- } catch ( IOException e ) {
129+ } catch ( InterruptedException e ) {
136130 e .printStackTrace ();
137131 }
138-
132+
139133 }
140-
134+
141135 @ Override
142- public void onMessage ( WebSocket conn , byte [] blob ) {
136+ public void onMessage ( WebSocket conn , byte [] blob ) {
143137 try {
144138 conn .send ( blob );
145- } catch ( IOException e ) {
139+ } catch ( InterruptedException e ) {
146140 e .printStackTrace ();
147141 }
148142 }
149143
150144 @ Override
151145 public void onError ( Exception ex ) {
152- System .out .println ("Error: " +ex .toString ());
146+ System .out .println ( "Error: " );
147+ ex .printStackTrace ();
153148 }
154-
149+
155150 @ Override
156- public void onOpen ( ) {
151+ public void onOpen () {
157152 }
158-
153+
159154 @ Override
160- public void onClose ( ) {
155+ public void onClose () {
161156 }
162-
157+
163158}
0 commit comments