@@ -383,6 +383,9 @@ public void onTimeout(Connection connection) {
383
383
false ,
384
384
false );
385
385
final SwitchingSSLFilter filter = new SwitchingSSLFilter (configurator , defaultSecState );
386
+ ProtocolHandshakeListener handshakeListener =
387
+ new ProtocolHandshakeListener ();
388
+ filter .addHandshakeListener (handshakeListener );
386
389
fcb .add (filter );
387
390
GrizzlyAsyncHttpProviderConfig providerConfig =
388
391
(GrizzlyAsyncHttpProviderConfig ) clientConfig .getAsyncHttpProviderConfig ();
@@ -494,13 +497,11 @@ private FilterChainBuilder createSpdyFilterChain(final FilterChainBuilder fcb,
494
497
int idx = spdyFcb .indexOfType (SSLFilter .class );
495
498
Filter f = spdyFcb .get (idx );
496
499
500
+
497
501
// Adjust the SSLFilter to support NPN
498
502
if (npnEnabled ) {
499
503
SSLBaseFilter sslBaseFilter = (SSLBaseFilter ) f ;
500
504
NextProtoNegSupport .getInstance ().configure (sslBaseFilter );
501
- ProtocolHandshakeListener handshakeListener =
502
- new ProtocolHandshakeListener ();
503
- sslBaseFilter .addHandshakeListener (handshakeListener );
504
505
}
505
506
506
507
// Remove the HTTP Client filter - this will be replaced by the
@@ -970,6 +971,13 @@ public void updated(Object result) {
970
971
return super .handleRead (ctx );
971
972
}
972
973
974
+ @ Override
975
+ public void exceptionOccurred (FilterChainContext ctx , Throwable error ) {
976
+ final HttpTransactionContext context = getHttpTransactionContext (ctx .getConnection ());
977
+ if (context != null ) {
978
+ context .abort (error .getCause ());
979
+ }
980
+ }
973
981
} // END AsyncHttpClientTransportFilter
974
982
975
983
@@ -1113,15 +1121,17 @@ public Boolean call() throws Exception {
1113
1121
// us a different FilterChain to use.
1114
1122
SSLConnectionContext sslCtx =
1115
1123
SSLUtils .getSslConnectionContext (ctx .getConnection ());
1116
- FilterChain fc = sslCtx .getNewConnectionFilterChain ();
1117
-
1118
- if (fc != null ) {
1119
- // Create a new FilterChain context using the new
1120
- // FilterChain.
1121
- // TODO: We need to mark this connection somehow
1122
- // as being only suitable for this type of
1123
- // request.
1124
- sendingCtx = obtainProtocolChainContext (ctx , fc );
1124
+ if (sslCtx != null ) {
1125
+ FilterChain fc = sslCtx .getNewConnectionFilterChain ();
1126
+
1127
+ if (fc != null ) {
1128
+ // Create a new FilterChain context using the new
1129
+ // FilterChain.
1130
+ // TODO: We need to mark this connection somehow
1131
+ // as being only suitable for this type of
1132
+ // request.
1133
+ sendingCtx = obtainProtocolChainContext (ctx , fc );
1134
+ }
1125
1135
}
1126
1136
return sendRequest (sendingCtx , request , requestPacketLocal );
1127
1137
}
@@ -1776,7 +1786,7 @@ protected boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext c
1776
1786
boolean result ;
1777
1787
final String proxy_auth = httpHeader .getHeader (Header .ProxyAuthenticate );
1778
1788
1779
- if (httpHeader .isSkipRemainder () ) {
1789
+ if (httpHeader .isSkipRemainder ()) {
1780
1790
if (!ProxyAuthorizationHandler .isNTLMSecondHandShake (proxy_auth )) {
1781
1791
cleanup .cleanup (ctx );
1782
1792
cleanup (ctx , provider );
@@ -2146,7 +2156,7 @@ private boolean exceuteRequest(
2146
2156
}
2147
2157
2148
2158
public static boolean isNTLMSecondHandShake (final String proxy_auth ) {
2149
- return (proxy_auth .toLowerCase ().startsWith ("ntlm" ) && !proxy_auth .equalsIgnoreCase ("ntlm" ));
2159
+ return (proxy_auth != null && proxy_auth .toLowerCase ().startsWith ("ntlm" ) && !proxy_auth .equalsIgnoreCase ("ntlm" ));
2150
2160
}
2151
2161
public static boolean isNTLMFirstHandShake (final String proxy_auth ) {
2152
2162
return (proxy_auth .equalsIgnoreCase ("ntlm" ));
@@ -2208,13 +2218,13 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
2208
2218
try {
2209
2219
final Connection c = m .obtainConnection (requestToSend ,
2210
2220
httpTransactionContext .future );
2211
- if (switchingSchemes (orig , uri )) {
2212
- try {
2213
- notifySchemeSwitch (ctx , c , uri );
2214
- } catch (IOException ioe ) {
2215
- httpTransactionContext .abort (ioe );
2216
- }
2217
- }
2221
+ // if (switchingSchemes(orig, uri)) {
2222
+ // try {
2223
+ // notifySchemeSwitch(ctx, c, uri);
2224
+ // } catch (IOException ioe) {
2225
+ // httpTransactionContext.abort(ioe);
2226
+ // }
2227
+ // }
2218
2228
final HttpTransactionContext newContext =
2219
2229
httpTransactionContext .copy ();
2220
2230
httpTransactionContext .future = null ;
@@ -3102,38 +3112,35 @@ static final class SwitchingSSLFilter extends SSLFilter {
3102
3112
3103
3113
3104
3114
@ Override
3105
- public NextAction handleConnect (FilterChainContext ctx )
3106
- throws IOException {
3107
- if (isSecure (ctx .getConnection ())) {
3108
- // initiate the handshake during the connection event
3109
- // so that we can properly install the SPDY FilterChain
3110
- // based on NPN results.
3111
- handshake (ctx .getConnection (), null );
3112
- }
3113
- return ctx .getInvokeAction ();
3115
+ protected void notifyHandshakeFailed (Connection connection , Throwable t ) {
3116
+ throw new RuntimeException (t );
3114
3117
}
3115
3118
3116
3119
@ Override
3117
3120
public NextAction handleEvent (final FilterChainContext ctx , FilterChainEvent event ) throws IOException {
3118
3121
3119
3122
if (event .type () == SSLSwitchingEvent .class ) {
3120
3123
final SSLSwitchingEvent se = (SSLSwitchingEvent ) event ;
3121
- setSecureStatus ( se . connection , se . secure );
3124
+
3122
3125
if (se .secure ) {
3123
- ProtocolHandshakeListener .addListener (ctx .getConnection (),
3124
- new HandshakeCompleteListener () {
3125
- @ Override
3126
- public void complete () {
3127
- try {
3128
- se .action .call ();
3129
- } catch (Exception e ) {
3130
- throw new RuntimeException (e );
3131
- }
3132
- }
3133
- }
3134
- );
3126
+ if (se .action != null ) {
3127
+ ProtocolHandshakeListener .addListener (
3128
+ ctx .getConnection (),
3129
+ new HandshakeCompleteListener () {
3130
+ @ Override
3131
+ public void complete () {
3132
+ try {
3133
+ se .action .call ();
3134
+ } catch (Exception e ) {
3135
+ throw new RuntimeException (e );
3136
+ }
3137
+ }
3138
+ }
3139
+ );
3140
+ }
3135
3141
handshake (ctx .getConnection (), null );
3136
3142
}
3143
+ setSecureStatus (se .connection , se .secure );
3137
3144
return ctx .getStopAction ();
3138
3145
}
3139
3146
return ctx .getInvokeAction ();
0 commit comments