-
Notifications
You must be signed in to change notification settings - Fork 3.9k
okhttp: support JDK9 ALPN #4136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -110,7 +112,9 @@ public void negotiatorNotNull() { | |||
|
|||
@Test | |||
public void negotiate_handshakeFails() throws IOException { | |||
SSLParameters parameters = mock(SSLParameters.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not new SSLParameters()
? Please use real objects when easily possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
SSLParameters.class.getMethod("setApplicationProtocols", String[].class); | ||
Method getApplicationProtocol = | ||
AccessController.doPrivileged( | ||
new PrivilegedExceptionAction<Method>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this privileged and not the earlier getMethod?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An oversight. Fixed.
return (String) getApplicationProtocol.invoke(socket); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} catch (InvocationTargetException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is known that getApplicationProtocol can throw UnsupportedOperationException
. This case should be handled more cleanly.
For one, we can do e.getCause()
. From there we can either propagate it directly (if it is a RuntimeException) or wrap it and provide a message with additional information.
(Actually, if we verify the provider supports this method ahead-of-time, then I'm fine with this current code.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now verify at startup that an SSLEngine created using the provider does not throw when getApplicationProtocol
is invoked.
return SSLSocket.class.getMethod("getApplicationProtocol"); | ||
} | ||
}); | ||
return new JdkAlpnPlatform(sslProvider, setApplicationProtocols, getApplicationProtocol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should verify that sslProvider
supports ALPN by calling getApplicationProtocol()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. AFAICT this requires instantiating an SSLEngine to invoke getApplicationProtocol()
, which is the approach now taken.
Adds support for JDK9's built-in ALPN to the OkHttp transport.
Manually tested with JDK9. I removed the alpnagent from the interop-testing dependencies to test this locally, but did not remove them in this PR (I'm not sure if our test infrastructure is all running on JDK9 yet).
The first commit contains two test changes that are necessary to build on JDK9 (one copied from #3638).