forked from andredigenova/Java-WebSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutobahnClientTest.java
More file actions
163 lines (144 loc) · 4.67 KB
/
AutobahnClientTest.java
File metadata and controls
163 lines (144 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.nio.ByteBuffer;
import org.java_websocket.WebSocket;
import org.java_websocket.WebSocketImpl;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_17;
import org.java_websocket.framing.FrameBuilder;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ServerHandshake;
public class AutobahnClientTest extends WebSocketClient {
public AutobahnClientTest( Draft d , URI uri ) {
super( uri, d );
}
/**
* @param args
*/
public static void main( String[] args ) {
System.out.println( "Testutility to profile/test this implementation using the Autobahn suit.\n" );
System.out.println( "Type 'r <casenumber>' to run a testcase. Example: r 1" );
System.out.println( "Type 'r <first casenumber> <last casenumber>' to run a testcase. Example: r 1 295" );
System.out.println( "Type 'u' to update the test results." );
System.out.println( "Type 'ex' to terminate the program." );
System.out.println( "During sequences of cases the debugoutput will be turned of." );
System.out.println( "You can now enter in your commands:" );
try {
BufferedReader sysin = new BufferedReader( new InputStreamReader( System.in ) );
/*First of the thinks a programmer might want to change*/
Draft d = new Draft_17();
String clientname = "tootallnate/websocket";
String protocol = "ws";
String host = "localhost";
int port = 9001;
String serverlocation = protocol + "://" + host + ":" + port;
String line = "";
AutobahnClientTest e;
URI uri = null;
String perviousline = "";
String nextline = null;
Integer start = null;
Integer end = null;
while ( !line.contains( "ex" ) ) {
try {
if( nextline != null ) {
line = nextline;
nextline = null;
WebSocketImpl.DEBUG = false;
} else {
System.out.print( ">" );
line = sysin.readLine();
WebSocketImpl.DEBUG = true;
}
if( line.equals( "l" ) ) {
line = perviousline;
}
String[] spl = line.split( " " );
if( line.startsWith( "r" ) ) {
if( spl.length == 3 ) {
start = new Integer( spl[ 1 ] );
end = new Integer( spl[ 2 ] );
}
if( start != null && end != null ) {
if( start > end ) {
start = null;
end = null;
} else {
nextline = "r " + start;
start++;
if( spl.length == 3 )
continue;
}
}
uri = URI.create( serverlocation + "/runCase?case=" + spl[ 1 ] + "&agent=" + clientname );
} else if( line.startsWith( "u" ) ) {
WebSocketImpl.DEBUG = false;
uri = URI.create( serverlocation + "/updateReports?agent=" + clientname );
} else if( line.startsWith( "d" ) ) {
try {
d = (Draft) Class.forName( "Draft_" + spl[ 1 ] ).getConstructor().newInstance();
} catch ( Exception ex ) {
System.out.println( "Could not change draft" + ex );
}
}
if( uri == null ) {
System.out.println( "Do not understand the input." );
continue;
}
System.out.println( "//////////////////////Exec: " + uri.getQuery() );
e = new AutobahnClientTest( d, uri );
Thread t = new Thread( e );
t.start();
try {
t.join();
} catch ( InterruptedException e1 ) {
e1.printStackTrace();
} finally {
e.close();
}
} catch ( ArrayIndexOutOfBoundsException e1 ) {
System.out.println( "Bad Input r 1, u 1, d 10, ex" );
} catch ( IllegalArgumentException e2 ) {
e2.printStackTrace();
}
}
} catch ( ArrayIndexOutOfBoundsException e ) {
System.out.println( "Missing server uri" );
} catch ( IllegalArgumentException e ) {
e.printStackTrace();
System.out.println( "URI should look like ws://localhost:8887 or wss://echo.websocket.org" );
} catch ( IOException e ) {
e.printStackTrace(); // for System.in reader
}
System.exit( 0 );
}
@Override
public void onMessage( String message ) {
send( message );
}
@Override
public void onMessage( ByteBuffer blob ) {
getConnection().send( blob );
}
@Override
public void onError( Exception ex ) {
System.out.println( "Error: " );
ex.printStackTrace();
}
@Override
public void onOpen( ServerHandshake handshake ) {
}
@Override
public void onClose( int code, String reason, boolean remote ) {
System.out.println( "Closed: " + code + " " + reason );
}
@Override
public void onWebsocketMessageFragment( WebSocket conn, Framedata frame ) {
FrameBuilder builder = (FrameBuilder) frame;
builder.setTransferemasked( true );
getConnection().sendFrame( frame );
}
}