Skip to content

Commit 6ede082

Browse files
cbosbaywet
authored andcommitted
Use parent Call.Factory of OkHttpClient to be able to use OpenTelemetry
1 parent 87f33b9 commit 6ede082

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/main/java/com/microsoft/graph/core/BaseClient.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.annotation.Nonnull;
4242

4343
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44+
import okhttp3.Call;
4445
import okhttp3.OkHttpClient;
4546
import okhttp3.Request;
4647

@@ -137,7 +138,7 @@ public static Builder<OkHttpClient, Request> builder() {
137138
* @return builder to start configuring the client
138139
*/
139140
@Nonnull
140-
public static <nativeClient, nativeRequest> Builder<nativeClient, nativeRequest> builder(@Nonnull final Class<nativeClient> nativeClientClass, @Nonnull final Class<nativeRequest> nativeRequestClass) {
141+
public static <nativeClient extends Call.Factory, nativeRequest> Builder<nativeClient, nativeRequest> builder(@Nonnull final Class<nativeClient> nativeClientClass, @Nonnull final Class<nativeRequest> nativeRequestClass) {
141142
return new Builder<>();
142143
}
143144

@@ -146,7 +147,7 @@ public static <nativeClient, nativeRequest> Builder<nativeClient, nativeRequest>
146147
* @param <httpClientType> type of the native http library client
147148
* @param <nativeRequestType> type of a request for the native http client
148149
*/
149-
public static class Builder<httpClientType, nativeRequestType> {
150+
public static class Builder<httpClientType extends Call.Factory, nativeRequestType> {
150151
private ISerializer serializer;
151152
private IHttpProvider<nativeRequestType> httpProvider;
152153
private ILogger logger;
@@ -174,18 +175,17 @@ private ISerializer getSerializer() {
174175
return serializer;
175176
}
176177
}
177-
@SuppressWarnings("unchecked")
178-
private httpClientType getHttpClient() {
178+
private Call.Factory getHttpClient() {
179179
if(httpClient == null) {
180-
return (httpClientType)HttpClients.createDefault(getAuthenticationProvider());
180+
return HttpClients.createDefault(getAuthenticationProvider());
181181
} else {
182182
return httpClient;
183183
}
184184
}
185185
@SuppressWarnings("unchecked")
186186
private IHttpProvider<nativeRequestType> getHttpProvider() {
187187
if(httpProvider == null) {
188-
return (IHttpProvider<nativeRequestType>)new CoreHttpProvider(getSerializer(), getLogger(), (OkHttpClient)getHttpClient());
188+
return (IHttpProvider<nativeRequestType>)new CoreHttpProvider(getSerializer(), getLogger(), getHttpClient());
189189
} else {
190190
return httpProvider;
191191
}

src/main/java/com/microsoft/graph/http/CoreHttpProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public class CoreHttpProvider implements IHttpProvider<Request> {
9898
private final ILogger logger;
9999

100100
/**
101-
* The OkHttpClient that handles all requests
101+
* The OkHttpClient(Call.Factory) that handles all requests
102102
*/
103-
private OkHttpClient corehttpClient;
103+
private Call.Factory corehttpClient;
104104

105105
/**
106106
* Creates the CoreHttpProvider
@@ -112,7 +112,7 @@ public class CoreHttpProvider implements IHttpProvider<Request> {
112112
@SuppressFBWarnings
113113
public CoreHttpProvider(@Nonnull final ISerializer serializer,
114114
@Nonnull final ILogger logger,
115-
@Nonnull final OkHttpClient httpClient) {
115+
@Nonnull final Call.Factory httpClient) {
116116
Objects.requireNonNull(logger, "parameter logger cannot be null");
117117
Objects.requireNonNull(serializer, "parameter serializer cannot be null");
118118
Objects.requireNonNull(httpClient, "parameter httpClient cannot be null");

0 commit comments

Comments
 (0)