35
35
import org .asynchttpclient .HttpResponseHeaders ;
36
36
import org .asynchttpclient .HttpResponseStatus ;
37
37
import org .asynchttpclient .Request ;
38
- import org .asynchttpclient .providers .netty .DiscardEvent ;
39
38
import org .asynchttpclient .providers .netty .NettyAsyncHttpProviderConfig ;
40
39
import org .asynchttpclient .providers .netty .channel .ChannelManager ;
41
40
import org .asynchttpclient .providers .netty .channel .Channels ;
@@ -169,16 +168,11 @@ public void handle(Channel channel, NettyResponseFuture<?> future, Object e) thr
169
168
}
170
169
171
170
@ Override
172
- public void onError (Channel channel , Throwable e ) {
173
- try {
174
- Object attribute = Channels .getAttribute (channel );
175
- logger .warn ("onError {}" , e );
176
- if (!(attribute instanceof NettyResponseFuture )) {
177
- return ;
178
- }
171
+ public void onError (NettyResponseFuture <?> future , Throwable e ) {
172
+ logger .warn ("onError {}" , e );
179
173
180
- NettyResponseFuture <?> nettyResponse = ( NettyResponseFuture <?>) attribute ;
181
- WebSocketUpgradeHandler h = WebSocketUpgradeHandler .class .cast (nettyResponse . getAsyncHandler () );
174
+ try {
175
+ WebSocketUpgradeHandler h = WebSocketUpgradeHandler .class .cast (future );
182
176
183
177
NettyWebSocket webSocket = NettyWebSocket .class .cast (h .onCompleted ());
184
178
if (webSocket != null ) {
@@ -191,21 +185,15 @@ public void onError(Channel channel, Throwable e) {
191
185
}
192
186
193
187
@ Override
194
- public void onClose (Channel channel ) {
188
+ public void onClose (NettyResponseFuture <?> future ) {
195
189
logger .trace ("onClose {}" );
196
- Object attribute = Channels .getAttribute (channel );
197
- if (!(attribute instanceof NettyResponseFuture ))
198
- return ;
199
190
200
191
try {
201
- NettyResponseFuture <?> nettyResponse = NettyResponseFuture .class .cast (attribute );
202
- WebSocketUpgradeHandler h = WebSocketUpgradeHandler .class .cast (nettyResponse .getAsyncHandler ());
192
+ WebSocketUpgradeHandler h = WebSocketUpgradeHandler .class .cast (future );
203
193
NettyWebSocket webSocket = NettyWebSocket .class .cast (h .onCompleted ());
204
194
205
- // FIXME How could this test not succeed, we just checked above that
206
- // attribute is a NettyResponseFuture????
207
195
logger .trace ("Connection was closed abnormally (that is, with no close frame being sent)." );
208
- if (attribute != DiscardEvent . INSTANCE && webSocket != null )
196
+ if (webSocket != null )
209
197
webSocket .close (1006 , "Connection was closed abnormally (that is, with no close frame being sent)." );
210
198
} catch (Throwable t ) {
211
199
logger .error ("onError" , t );
0 commit comments