Skip to content

Commit 84e96b0

Browse files
committed
1 parent 7a5e019 commit 84e96b0

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/main/java/com/ning/http/client/providers/netty/handler/Processor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws
125125
&& requestSender.applyIoExceptionFiltersAndReplayRequest(future, CHANNEL_CLOSED_EXCEPTION, channel))
126126
return;
127127

128-
protocol.onClose(future);
128+
protocol.onError(future, null);
129129
requestSender.handleUnexpectedClosedChannel(channel, future);
130130
}
131131
}

src/main/java/com/ning/http/client/providers/netty/handler/WebSocketProtocol.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@
1313
*/
1414
package com.ning.http.client.providers.netty.handler;
1515

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-
3116
import com.ning.http.client.AsyncHandler.STATE;
3217
import com.ning.http.client.AsyncHttpClientConfig;
3318
import com.ning.http.client.HttpResponseHeaders;
@@ -44,10 +29,24 @@
4429
import com.ning.http.client.providers.netty.response.NettyResponseStatus;
4530
import com.ning.http.client.providers.netty.ws.NettyWebSocket;
4631
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;
4743

4844
import java.io.IOException;
4945
import java.util.Locale;
5046

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+
5150
public final class WebSocketProtocol extends Protocol {
5251

5352
public WebSocketProtocol(ChannelManager channelManager,//
@@ -179,12 +178,14 @@ public void setContent(ChannelBuffer content) {
179178
public void onError(NettyResponseFuture<?> future, Throwable e) {
180179
logger.warn("onError {}", e);
181180

181+
Throwable throwable = e == null ? new UnexpectedWebSocketException() : e.getCause() == null ? e : e.getCause();
182+
182183
try {
183184
WebSocketUpgradeHandler h = (WebSocketUpgradeHandler) future.getAsyncHandler();
184185

185186
NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted());
186187
if (webSocket != null) {
187-
webSocket.onError(e.getCause());
188+
webSocket.onError(throwable);
188189
webSocket.close();
189190
}
190191
} catch (Throwable t) {
@@ -207,4 +208,7 @@ public void onClose(NettyResponseFuture<?> future) {
207208
logger.error("onError", t);
208209
}
209210
}
211+
212+
private final static class UnexpectedWebSocketException extends Exception {
213+
}
210214
}

0 commit comments

Comments
 (0)