Skip to content

Commit

Permalink
HTTP/2 for JNH connector
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <[email protected]>
  • Loading branch information
senivam committed Mar 24, 2023
1 parent 0781850 commit d63dc1b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -75,6 +75,16 @@ public class JavaNetHttpClientProperties {
public static final String DISABLE_COOKIES =
"jersey.config.jnh.client.disableCookies";

/**
* HTTP version - if null or instance of HttpClient.Version.HTTP_1_1 the version will be set to HTTP_1_1
* if version is HttpClient.Version.HTTP_2 the client will attempt to perform each request using HTTP_2 protocol
* but if not supported by server, the protocol will be still HTTP_1_1
*
* @since 3.1.2
*/
public static final String HTTP_VERSION =
"jersey.config.jnh.client.httpVersion";


/**
* Prevent this class from instantiation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -82,8 +82,10 @@ public class JavaNetHttpConnector implements Connector {
* @param configuration the configuration properties for this connector
*/
public JavaNetHttpConnector(final Client client, final Configuration configuration) {
HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
httpClientBuilder.version(HttpClient.Version.HTTP_1_1);
final HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
final HttpClient.Version version =
getPropertyOrNull(configuration, JavaNetHttpClientProperties.HTTP_VERSION, HttpClient.Version.class);
httpClientBuilder.version(version == null ? HttpClient.Version.HTTP_1_1 : version);
SSLContext sslContext = client.getSslContext();
if (sslContext != null) {
httpClientBuilder.sslContext(sslContext);
Expand Down Expand Up @@ -220,6 +222,9 @@ private <T> T getPropertyOrNull(final Configuration configuration, final String
if (propertyObject == null) {
return null;
}
if (resultClass.isEnum() && propertyObject instanceof String) {
return (T) Enum.valueOf(resultClass.asSubclass(Enum.class), (String) propertyObject);
}
if (!resultClass.isInstance(propertyObject)) {
LOGGER.warning(LocalizationMessages.ERROR_INVALID_CLASS(propertyKey, resultClass.getName()));
return null;
Expand Down
20 changes: 19 additions & 1 deletion docs/src/main/docbook/appendix-properties.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -2068,6 +2068,24 @@
</para>
</entry>
</row>
<row>
<entry>&jersey.jnh.JavaNetHttpClientProperties.HTTP_VERSION;</entry>
<entry><literal>jersey.config.jnh.client.httpVersion</literal></entry>
<entry>
<para>
HTTP version - if null or instance of HttpClient.Version.HTTP_1_1
the version will be set to HTTP_1_1. If version is HttpClient.Version.HTTP_2
the client will attempt to perform each request using HTTP_2 protocol
but if not supported by server, the protocol will be still HTTP_1_1
</para>
<para>
The value MUST be an instance of <literal>java.net.http.HttpClient.Version</literal>.
</para>
<para>
The default value is &lit.null;.
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
Expand Down
3 changes: 2 additions & 1 deletion docs/src/main/docbook/jersey.ent
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<!--
Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -489,6 +489,7 @@
<!ENTITY jersey.jnh.JavaNetHttpClientProperties.SSL_PARAMETERS "<link xlink:href='&jersey.javadoc.uri.prefix;/jnh/connector/JavaNetHttpClientProperties.html#SSL_PARAMETERS'>JavaNetHttpClientProperties.SSL_PARAMETERS</link>">
<!ENTITY jersey.jnh.JavaNetHttpClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION "<link xlink:href='&jersey.javadoc.uri.prefix;/jnh/connector/JavaNetHttpClientProperties.html#PREEMPTIVE_BASIC_AUTHENTICATION'>JavaNetHttpClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION</link>">
<!ENTITY jersey.jnh.JavaNetHttpClientProperties.DISABLE_COOKIES "<link xlink:href='&jersey.javadoc.uri.prefix;/jnh/connector/JavaNetHttpClientProperties.html#DISABLE_COOKIES'>JavaNetHttpClientProperties.DISABLE_COOKIES</link>">
<!ENTITY jersey.jnh.JavaNetHttpClientProperties.HTTP_VERSION "<link xlink:href='&jersey.javadoc.uri.prefix;/jnh/connector/JavaNetHttpClientProperties.html#HTTP_VERSION'>JavaNetHttpClientProperties.HTTP_VERSION</link>">
<!ENTITY jersey.linking.DeclarativeLinkingFeature "<link xlink:href='&jersey.javadoc.uri.prefix;/linking/DeclarativeLinkingFeature.html'>DeclarativeLinkingFeature</link>">
<!ENTITY jersey.logging.LoggingFeature "<link xlink:href='&jersey.javadoc.uri.prefix;/logging/LoggingFeature.html'>LoggingFeature</link>">
<!ENTITY jersey.logging.LoggingFeature.DEFAULT_LOGGER_NAME "<link xlink:href='&jersey.javadoc.uri.prefix;/logging/LoggingFeature.html#DEFAULT_LOGGER_NAME'>LoggingFeature.DEFAULT_LOGGER_NAME</link>">
Expand Down

0 comments on commit d63dc1b

Please sign in to comment.