Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 149852a

Browse files
committed
- Get SSL related tests passing again after SPDY-related changes.
1 parent 9671af2 commit 149852a

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

providers/grizzly/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ public void onTimeout(Connection connection) {
383383
false,
384384
false);
385385
final SwitchingSSLFilter filter = new SwitchingSSLFilter(configurator, defaultSecState);
386+
ProtocolHandshakeListener handshakeListener =
387+
new ProtocolHandshakeListener();
388+
filter.addHandshakeListener(handshakeListener);
386389
fcb.add(filter);
387390
GrizzlyAsyncHttpProviderConfig providerConfig =
388391
(GrizzlyAsyncHttpProviderConfig) clientConfig.getAsyncHttpProviderConfig();
@@ -494,13 +497,11 @@ private FilterChainBuilder createSpdyFilterChain(final FilterChainBuilder fcb,
494497
int idx = spdyFcb.indexOfType(SSLFilter.class);
495498
Filter f = spdyFcb.get(idx);
496499

500+
497501
// Adjust the SSLFilter to support NPN
498502
if (npnEnabled) {
499503
SSLBaseFilter sslBaseFilter = (SSLBaseFilter) f;
500504
NextProtoNegSupport.getInstance().configure(sslBaseFilter);
501-
ProtocolHandshakeListener handshakeListener =
502-
new ProtocolHandshakeListener();
503-
sslBaseFilter.addHandshakeListener(handshakeListener);
504505
}
505506

506507
// Remove the HTTP Client filter - this will be replaced by the
@@ -970,6 +971,13 @@ public void updated(Object result) {
970971
return super.handleRead(ctx);
971972
}
972973

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+
}
973981
} // END AsyncHttpClientTransportFilter
974982

975983

@@ -1113,15 +1121,17 @@ public Boolean call() throws Exception {
11131121
// us a different FilterChain to use.
11141122
SSLConnectionContext sslCtx =
11151123
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+
}
11251135
}
11261136
return sendRequest(sendingCtx, request, requestPacketLocal);
11271137
}
@@ -1776,7 +1786,7 @@ protected boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext c
17761786
boolean result;
17771787
final String proxy_auth = httpHeader.getHeader(Header.ProxyAuthenticate);
17781788

1779-
if (httpHeader.isSkipRemainder() ) {
1789+
if (httpHeader.isSkipRemainder()) {
17801790
if (!ProxyAuthorizationHandler.isNTLMSecondHandShake(proxy_auth)) {
17811791
cleanup.cleanup(ctx);
17821792
cleanup(ctx, provider);
@@ -2146,7 +2156,7 @@ private boolean exceuteRequest(
21462156
}
21472157

21482158
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"));
21502160
}
21512161
public static boolean isNTLMFirstHandShake(final String proxy_auth) {
21522162
return (proxy_auth.equalsIgnoreCase("ntlm"));
@@ -2208,13 +2218,13 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
22082218
try {
22092219
final Connection c = m.obtainConnection(requestToSend,
22102220
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+
// }
22182228
final HttpTransactionContext newContext =
22192229
httpTransactionContext.copy();
22202230
httpTransactionContext.future = null;
@@ -3102,38 +3112,35 @@ static final class SwitchingSSLFilter extends SSLFilter {
31023112

31033113

31043114
@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);
31143117
}
31153118

31163119
@Override
31173120
public NextAction handleEvent(final FilterChainContext ctx, FilterChainEvent event) throws IOException {
31183121

31193122
if (event.type() == SSLSwitchingEvent.class) {
31203123
final SSLSwitchingEvent se = (SSLSwitchingEvent) event;
3121-
setSecureStatus(se.connection, se.secure);
3124+
31223125
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+
}
31353141
handshake(ctx.getConnection(), null);
31363142
}
3143+
setSecureStatus(se.connection, se.secure);
31373144
return ctx.getStopAction();
31383145
}
31393146
return ctx.getInvokeAction();

0 commit comments

Comments
 (0)