Skip to content

Commit 5e2aca3

Browse files
committed
fix build issues
1 parent 730d744 commit 5e2aca3

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

spotBugsExcludeFilter.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
6464
<Class name="com.microsoft.graph.core.content.BatchResponseContent" />
6565
<Class name="com.microsoft.graph.core.requests.ResponseBodyHandler" />
6666
<Class name="com.microsoft.graph.core.requests.upload.UploadResponseHandler" />
67+
<Class name="com.microsoft.graph.core.requests.middleware.GraphTelemetryHandlerTest" />
6768
</Or>
6869
</Match>
6970
<Match>
@@ -111,4 +112,4 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
111112
<Bug pattern="DCN_NULLPOINTER_EXCEPTION" />
112113
<Class name="com.microsoft.graph.core.content.BatchResponseContentTest" />
113114
</Match>
114-
</FindBugsFilter>
115+
</FindBugsFilter>

src/main/java/com/microsoft/graph/core/requests/GraphClientFactory.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public static OkHttpClient.Builder create(@Nonnull BaseBearerTokenAuthentication
6262
return create(authenticationProvider, new RequestOption[0]);
6363
}
6464

65+
/**
66+
* OkHttpClient Builder for Graph with specified AuthenticationProvider and RequestOptions to override default graph interceptors
67+
* @param authenticationProvider the AuthenticationProvider to use for requests.
68+
* @param requestOptions custom request options to override default graph interceptors
69+
* @return an OkHttpClient Builder instance.
70+
*/
6571
@Nonnull
6672
public static OkHttpClient.Builder create(@Nonnull BaseBearerTokenAuthenticationProvider authenticationProvider, @Nonnull RequestOption[] requestOptions) {
6773
final GraphClientOption graphClientOption = new GraphClientOption();
@@ -81,9 +87,9 @@ public static OkHttpClient.Builder create(@Nonnull BaseBearerTokenAuthentication
8187
*/
8288
@Nonnull
8389
public static OkHttpClient.Builder create(@Nonnull GraphClientOption graphClientOption, @Nonnull Interceptor... interceptors) {
84-
var builder = KiotaClientFactory.create(interceptors);
85-
var customInterceptors = builder.interceptors();
86-
var telemetryHandlerExists = customInterceptors.stream().anyMatch(x -> x instanceof GraphTelemetryHandler);
90+
final OkHttpClient.Builder builder = KiotaClientFactory.create(interceptors);
91+
final List<Interceptor> customInterceptors = builder.interceptors();
92+
final boolean telemetryHandlerExists = customInterceptors.stream().anyMatch(x -> x instanceof GraphTelemetryHandler);
8793
if (!telemetryHandlerExists) {
8894
customInterceptors.add(new GraphTelemetryHandler(graphClientOption));
8995
}
@@ -112,6 +118,12 @@ public static OkHttpClient.Builder create(@Nullable GraphClientOption graphClien
112118
return create(graphClientOption, new RequestOption[0]);
113119
}
114120

121+
/**
122+
* The OkHttpClient Builder with optional GraphClientOption and RequestOptions to override default graph interceptors
123+
* @param graphClientOption the GraphClientOption for use in requests.
124+
* @param requestOptions custom request options to override default graph interceptors
125+
* @return an OkHttpClient Builder instance.
126+
*/
115127
@Nonnull
116128
public static OkHttpClient.Builder create(@Nullable GraphClientOption graphClientOption, @Nonnull RequestOption[] requestOptions) {
117129
GraphClientOption options = graphClientOption != null ? graphClientOption : new GraphClientOption();
@@ -129,6 +141,12 @@ public static Interceptor[] createDefaultGraphInterceptors(@Nonnull GraphClientO
129141
return createDefaultGraphInterceptors(graphClientOption, new RequestOption[0]);
130142
}
131143

144+
/**
145+
* Creates the default Interceptors for use with Graph configured with the provided RequestOptions.
146+
* @param graphClientOption the GraphClientOption used to create the GraphTelemetryHandler with.
147+
* @param requestOptions custom request options to override default graph interceptors
148+
* @return an array of interceptors.
149+
*/
132150
@Nonnull
133151
public static Interceptor[] createDefaultGraphInterceptors(@Nonnull GraphClientOption graphClientOption, @Nonnull RequestOption[] requestOptions) {
134152
Objects.requireNonNull(requestOptions, "parameter requestOptions cannot be null");
@@ -142,9 +160,7 @@ public static Interceptor[] createDefaultGraphInterceptors(@Nonnull GraphClientO
142160
}
143161

144162
List<Interceptor> handlers = new ArrayList<>();
145-
handlers.add(urlReplaceHandlerOption == null ?
146-
new UrlReplaceHandler(new UrlReplaceHandlerOption(CoreConstants.ReplacementConstants.getDefaultReplacementPairs())) :
147-
new UrlReplaceHandler(urlReplaceHandlerOption));
163+
handlers.add(new UrlReplaceHandler(urlReplaceHandlerOption));
148164
handlers.add(new GraphTelemetryHandler(graphClientOption));
149165
handlers.addAll(Arrays.asList(KiotaClientFactory.createDefaultInterceptors(requestOptions)));
150166
addDefaultFeatureUsages(graphClientOption);

src/test/java/com/microsoft/graph/core/requests/GraphClientFactoryTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import org.junit.jupiter.api.Assertions;
1717
import org.junit.jupiter.api.Test;
1818

19-
import com.azure.core.http.policy.RetryOptions;
20-
import com.microsoft.graph.core.CoreConstants;
2119
import com.microsoft.graph.core.authentication.AzureIdentityAccessTokenProvider;
2220
import com.microsoft.graph.core.authentication.AzureIdentityAuthenticationProvider;
2321
import com.microsoft.graph.core.requests.middleware.GraphTelemetryHandler;
@@ -89,7 +87,7 @@ void testCreateWithCustomInterceptorsOverwritesDefaults() throws IOException {
8987
new RedirectHandler()};
9088
final OkHttpClient client = GraphClientFactory.create(interceptors).build();
9189
final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build();
92-
final Response response = client.newCall(request).execute();
90+
client.newCall(request).execute();
9391

9492
for (Interceptor clientInterceptor : client.interceptors()) {
9593
if (clientInterceptor instanceof RetryHandler) {

src/test/java/com/microsoft/graph/core/requests/middleware/GraphTelemetryHandlerTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import com.microsoft.kiota.http.middleware.RedirectHandler;
77
import com.microsoft.kiota.http.middleware.RetryHandler;
88

9-
import com.microsoft.kiota.http.middleware.options.RetryHandlerOption;
109
import okhttp3.Interceptor;
1110
import okhttp3.OkHttpClient;
1211
import okhttp3.Request;
1312
import okhttp3.Response;
14-
import org.jetbrains.annotations.NotNull;
15-
import org.junit.jupiter.api.Assertions;
13+
1614
import org.junit.jupiter.api.Test;
1715

1816
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -33,6 +31,8 @@ void telemetryHandlerDefaultTests() throws IOException {
3331
final Response response = client.newCall(request).execute();
3432

3533
assertNotNull(response);
34+
assertNotNull(response.request());
35+
assertNotNull(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME));
3636
assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedCore));
3737
assertTrue(!response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(
3838
CoreConstants.Headers.ANDROID_VERSION_PREFIX)); // Android version is not going to be present on unit tests running on java platform
@@ -51,6 +51,8 @@ void arrayInterceptorsTest() throws IOException {
5151
final Response response = client.newCall(request).execute();
5252

5353
assertNotNull(response);
54+
assertNotNull(response.request());
55+
assertNotNull(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME));
5456
assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedCore));
5557
assertTrue(
5658
response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(defaultSDKVersion));
@@ -66,6 +68,8 @@ void arrayInterceptorEmptyTest() throws IOException {
6668
final Response response = client.newCall(request).execute();
6769

6870
assertNotNull(response);
71+
assertNotNull(response.request());
72+
assertNotNull(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME));
6973
assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedCore));
7074
assertTrue(
7175
response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(defaultSDKVersion));
@@ -93,6 +97,9 @@ void testClientOptions() throws IOException {
9397
final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build();
9498
final Response response = client.newCall(request).execute();
9599

100+
assertNotNull(response);
101+
assertNotNull(response.request());
102+
assertNotNull(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME));
96103
assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedCoreVer));
97104
assertTrue(
98105
response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedClientEndpoint));

0 commit comments

Comments
 (0)