13
13
*/
14
14
package com .ning .http .client .providers .netty .handler ;
15
15
16
- import static com .ning .http .client .providers .netty .ws .WebSocketUtils .getAcceptKey ;
17
- import static org .jboss .netty .handler .codec .http .HttpResponseStatus .SWITCHING_PROTOCOLS ;
18
-
19
- import org .jboss .netty .buffer .ChannelBuffer ;
20
- import org .jboss .netty .channel .Channel ;
21
- import org .jboss .netty .handler .codec .http .HttpChunk ;
22
- import org .jboss .netty .handler .codec .http .HttpHeaders ;
23
- import org .jboss .netty .handler .codec .http .HttpResponse ;
24
- import org .jboss .netty .handler .codec .http .websocketx .BinaryWebSocketFrame ;
25
- import org .jboss .netty .handler .codec .http .websocketx .CloseWebSocketFrame ;
26
- import org .jboss .netty .handler .codec .http .websocketx .PingWebSocketFrame ;
27
- import org .jboss .netty .handler .codec .http .websocketx .PongWebSocketFrame ;
28
- import org .jboss .netty .handler .codec .http .websocketx .TextWebSocketFrame ;
29
- import org .jboss .netty .handler .codec .http .websocketx .WebSocketFrame ;
30
-
31
16
import com .ning .http .client .AsyncHandler .STATE ;
32
17
import com .ning .http .client .AsyncHttpClientConfig ;
33
18
import com .ning .http .client .HttpResponseHeaders ;
44
29
import com .ning .http .client .providers .netty .response .NettyResponseStatus ;
45
30
import com .ning .http .client .providers .netty .ws .NettyWebSocket ;
46
31
import com .ning .http .client .ws .WebSocketUpgradeHandler ;
32
+ import org .jboss .netty .buffer .ChannelBuffer ;
33
+ import org .jboss .netty .channel .Channel ;
34
+ import org .jboss .netty .handler .codec .http .HttpChunk ;
35
+ import org .jboss .netty .handler .codec .http .HttpHeaders ;
36
+ import org .jboss .netty .handler .codec .http .HttpResponse ;
37
+ import org .jboss .netty .handler .codec .http .websocketx .BinaryWebSocketFrame ;
38
+ import org .jboss .netty .handler .codec .http .websocketx .CloseWebSocketFrame ;
39
+ import org .jboss .netty .handler .codec .http .websocketx .PingWebSocketFrame ;
40
+ import org .jboss .netty .handler .codec .http .websocketx .PongWebSocketFrame ;
41
+ import org .jboss .netty .handler .codec .http .websocketx .TextWebSocketFrame ;
42
+ import org .jboss .netty .handler .codec .http .websocketx .WebSocketFrame ;
47
43
48
44
import java .io .IOException ;
49
45
import java .util .Locale ;
50
46
47
+ import static com .ning .http .client .providers .netty .ws .WebSocketUtils .getAcceptKey ;
48
+ import static org .jboss .netty .handler .codec .http .HttpResponseStatus .SWITCHING_PROTOCOLS ;
49
+
51
50
public final class WebSocketProtocol extends Protocol {
52
51
53
52
public WebSocketProtocol (ChannelManager channelManager ,//
@@ -179,12 +178,14 @@ public void setContent(ChannelBuffer content) {
179
178
public void onError (NettyResponseFuture <?> future , Throwable e ) {
180
179
logger .warn ("onError {}" , e );
181
180
181
+ Throwable throwable = e == null ? new UnexpectedWebSocketException () : e .getCause () == null ? e : e .getCause ();
182
+
182
183
try {
183
184
WebSocketUpgradeHandler h = (WebSocketUpgradeHandler ) future .getAsyncHandler ();
184
185
185
186
NettyWebSocket webSocket = NettyWebSocket .class .cast (h .onCompleted ());
186
187
if (webSocket != null ) {
187
- webSocket .onError (e . getCause () );
188
+ webSocket .onError (throwable );
188
189
webSocket .close ();
189
190
}
190
191
} catch (Throwable t ) {
@@ -207,4 +208,7 @@ public void onClose(NettyResponseFuture<?> future) {
207
208
logger .error ("onError" , t );
208
209
}
209
210
}
211
+
212
+ private final static class UnexpectedWebSocketException extends Exception {
213
+ }
210
214
}
0 commit comments