File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
main/java/com/ning/http/client/websocket
test/java/com/ning/http/client/websocket Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ public final void onSuccess(WebSocket webSocket) {
106
106
@ Override
107
107
public final void onFailure (Throwable t ) {
108
108
for (WebSocketListener w : l ) {
109
- if (!ok .get ()) {
109
+ if (!ok .get () && webSocket != null ) {
110
110
webSocket .addMessageListener (w );
111
111
}
112
112
w .onError (t );
Original file line number Diff line number Diff line change 22
22
import java .util .concurrent .atomic .AtomicReference ;
23
23
24
24
import static org .testng .Assert .assertEquals ;
25
+ import static org .testng .Assert .assertTrue ;
26
+ import static org .testng .Assert .fail ;
25
27
26
28
public abstract class TextMessageTest extends AbstractBasicTest {
27
29
@@ -100,6 +102,36 @@ public void onError(Throwable t) {
100
102
assertEquals (text .get (), "OnOpen" );
101
103
}
102
104
105
+ @ Test (timeOut = 60000 )
106
+ public void onEmptyListenerTest () throws Throwable {
107
+ AsyncHttpClient c = getAsyncHttpClient (new AsyncHttpClientConfig .Builder ().build ());
108
+
109
+ WebSocket websocket = null ;
110
+ try {
111
+ websocket = c .prepareGet (getTargetUrl ())
112
+ .execute (new WebSocketUpgradeHandler .Builder ().build ()).get ();
113
+ } catch (Throwable t ) {
114
+ fail ();
115
+ }
116
+ assertTrue (websocket != null );
117
+ }
118
+
119
+ @ Test (timeOut = 60000 )
120
+ public void onFailureTest () throws Throwable {
121
+ AsyncHttpClient c = getAsyncHttpClient (new AsyncHttpClientConfig .Builder ().build ());
122
+ final AtomicReference <String > text = new AtomicReference <String >("" );
123
+
124
+ WebSocket websocket = null ;
125
+ Throwable t = null ;
126
+ try {
127
+ websocket = c .prepareGet ("ws://abcdefg" )
128
+ .execute (new WebSocketUpgradeHandler .Builder ().build ()).get ();
129
+ } catch (Throwable t2 ) {
130
+ t = t2 ;
131
+ }
132
+ assertTrue (t != null );
133
+ }
134
+
103
135
@ Test (timeOut = 60000 )
104
136
public void onTimeoutCloseTest () throws Throwable {
105
137
AsyncHttpClient c = getAsyncHttpClient (new AsyncHttpClientConfig .Builder ().build ());
You can’t perform that action at this time.
0 commit comments