Skip to content

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

Merged
merged 4 commits into from
Mar 21, 2018
Merged

Conversation

ericgribkoff
Copy link
Contributor

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).

@@ -110,7 +112,9 @@ public void negotiatorNotNull() {

@Test
public void negotiate_handshakeFails() throws IOException {
SSLParameters parameters = mock(SSLParameters.class);
Copy link
Member

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.

Copy link
Contributor Author

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>() {
Copy link
Member

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?

Copy link
Contributor Author

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) {
Copy link
Member

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.)

Copy link
Contributor Author

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);
Copy link
Member

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().

Copy link
Contributor Author

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.

@ericgribkoff ericgribkoff merged commit 52fedb6 into grpc:master Mar 21, 2018
@ericgribkoff ericgribkoff deleted the okhttp_jdk9 branch March 21, 2018 00:29
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants