Skip to content

Commit

Permalink
Move HttpClient SPI Implementation to Public API (#18580)
Browse files Browse the repository at this point in the history
* Move HttpClient Service Provider Interface Implementations to Public API

* Clean up linting

* Update documentation, fix styling
  • Loading branch information
alzimmermsft authored Jan 13, 2021
1 parent 3bc2464 commit 5c12e44
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.jdk.httpclient.implementation.JdkHttpClientProxySelector;
import com.azure.core.util.Configuration;

import com.azure.core.util.logging.ClientLogger;

import java.io.IOException;
import java.io.Reader;
import java.net.Authenticator;
Expand Down Expand Up @@ -83,8 +83,8 @@ public JdkAsyncHttpClientBuilder(java.net.http.HttpClient.Builder httpClientBuil

/**
* Sets the executor to be used for asynchronous and dependent tasks. This cannot be null.
*
* <p> If this method is not invoked prior to {@linkplain #build() building}, a default executor is created for each
* <p>
* If this method is not invoked prior to {@linkplain #build() building}, a default executor is created for each
* newly built {@code HttpClient}.
*
* @param executor the executor to be used for asynchronous and dependent tasks
Expand Down Expand Up @@ -151,8 +151,8 @@ public JdkAsyncHttpClientBuilder configuration(Configuration configuration) {
*/
public HttpClient build() {
java.net.http.HttpClient.Builder httpClientBuilder = this.httpClientBuilder == null
? java.net.http.HttpClient.newBuilder()
: this.httpClientBuilder;
? java.net.http.HttpClient.newBuilder()
: this.httpClientBuilder;

httpClientBuilder = (this.connectionTimeout != null)
? httpClientBuilder.connectTimeout(this.connectionTimeout)
Expand Down Expand Up @@ -210,7 +210,7 @@ private Set<String> getAllowRestrictedHeaders() {

// Combine the set of all allowed restricted headers from both sources
allowRestrictedHeaders.addAll(
Arrays.stream(allowRestrictedHeadersSystemProperties)
Arrays.stream(allowRestrictedHeadersSystemProperties)
.map(String::trim)
.collect(Collectors.toSet()));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.jdk.httpclient;

import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpClientProvider;

/**
* An {@link HttpClientProvider} that provides an implementation of HttpClient based on native JDK HttpClient.
* <p>
* NOTE: This implementation is only available in Java 11+ as that is when {@link java.net.http.HttpClient} was
* introduced.
*/
public final class JdkHttpClientProvider implements HttpClientProvider {

@Override
public HttpClient createInstance() {
return new JdkAsyncHttpClientBuilder().build();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import com.azure.core.http.jdk.httpclient.implementation.JdkHttpClientProvider;
import com.azure.core.http.jdk.httpclient.JdkHttpClientProvider;

module com.azure.core.http.jdk.httpclient {
requires transitive com.azure.core;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.azure.core.http.jdk.httpclient.implementation.JdkHttpClientProvider
com.azure.core.http.jdk.httpclient.JdkHttpClientProvider
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.jdk.httpclient.implementation;
package com.azure.core.http.jdk.httpclient;

import com.azure.core.http.HttpClient;
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.jdk.httpclient.JdkAsyncHttpClientBuilder;
import com.azure.core.test.RestProxyTestsWireMockServer;
import com.azure.core.test.implementation.RestProxyTests;
import com.github.tomakehurst.wiremock.WireMockServer;
Expand All @@ -26,7 +25,7 @@ public static void getWireMockServer() {
}

@AfterAll
public static void shutdownWireMockServer() {
public static void shutJdkAsyncHttpClientBuilderdownWireMockServer() {
if (server != null) {
server.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.jdk.httpclient.implementation;
package com.azure.core.http.jdk.httpclient;

import com.azure.core.http.HttpClient;
import com.azure.core.http.jdk.httpclient.JdkAsyncHttpClientBuilder;
import com.azure.core.test.implementation.RestProxyTests;
import com.azure.core.test.RestProxyTestsWireMockServer;
import com.azure.core.test.implementation.RestProxyTests;
import com.github.tomakehurst.wiremock.WireMockServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.netty.implementation;
package com.azure.core.http.netty;

import com.azure.core.http.HttpClient;
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.core.http.HttpClientProvider;

public class ReactorNettyClientProvider implements HttpClientProvider {
/**
* An {@link HttpClientProvider} that provides an implementation of HttpClient based on Netty.
*/
public final class ReactorNettyClientProvider implements HttpClientProvider {

@Override
public HttpClient createInstance() {
Expand Down
5 changes: 3 additions & 2 deletions sdk/core/azure-core-http-netty/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import com.azure.core.http.netty.ReactorNettyClientProvider;

module com.azure.http.netty {
requires transitive com.azure.core;
requires reactor.netty;
Expand All @@ -13,10 +15,9 @@
requires io.netty.handler.proxy;

exports com.azure.core.http.netty;
exports com.azure.core.http.netty.implementation; // FIXME this should not be a long-term solution

provides com.azure.core.http.HttpClientProvider
with com.azure.core.http.netty.implementation.ReactorNettyClientProvider;
with ReactorNettyClientProvider;

uses com.azure.core.http.HttpClientProvider;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.azure.core.http.netty.implementation.ReactorNettyClientProvider
com.azure.core.http.netty.ReactorNettyClientProvider
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.netty.implementation.ReactorNettyClientProvider;
import com.azure.core.util.Context;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.netty.implementation;
package com.azure.core.http.netty;

import com.azure.core.http.HttpClient;
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.core.test.RestProxyTestsWireMockServer;
import com.azure.core.test.implementation.RestProxyTests;
import com.github.tomakehurst.wiremock.WireMockServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.netty.implementation;
package com.azure.core.http.netty;

import com.azure.core.http.HttpClient;
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.core.test.RestProxyTestsWireMockServer;
import com.azure.core.test.implementation.RestProxyTests;
import com.github.tomakehurst.wiremock.WireMockServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.okhttp.implementation;
package com.azure.core.http.okhttp;

import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpClientProvider;
import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder;

public class OkHttpClientProvider implements HttpClientProvider {
/**
* An {@link HttpClientProvider} that provides an implementation of HttpClient based on OkHttp.
*/
public final class OkHttpClientProvider implements HttpClientProvider {

@Override
public HttpClient createInstance() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import com.azure.core.http.okhttp.OkHttpClientProvider;

module com.azure.core.http.okhttp {
requires transitive com.azure.core;

requires okhttp3;
requires okio;

exports com.azure.core.http.okhttp;
exports com.azure.core.http.okhttp.implementation; // FIXME this should not be a long-term solution

provides com.azure.core.http.HttpClientProvider
with com.azure.core.http.okhttp.implementation.OkHttpClientProvider;
with OkHttpClientProvider;

uses com.azure.core.http.HttpClientProvider;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.azure.core.http.okhttp.implementation.OkHttpClientProvider
com.azure.core.http.okhttp.OkHttpClientProvider
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.okhttp.implementation;
package com.azure.core.http.okhttp;

import com.azure.core.http.HttpClient;
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder;
import com.azure.core.test.RestProxyTestsWireMockServer;
import com.azure.core.test.implementation.RestProxyTests;
import com.github.tomakehurst.wiremock.WireMockServer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.http.okhttp.implementation;
package com.azure.core.http.okhttp;

import com.azure.core.http.HttpClient;
import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder;
import com.azure.core.test.RestProxyTestsWireMockServer;
import com.azure.core.test.implementation.RestProxyTests;
import com.github.tomakehurst.wiremock.WireMockServer;
Expand Down

0 comments on commit 5c12e44

Please sign in to comment.