From c82abbba1138d7d92db25d01940081fe19e6c560 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Mon, 4 Apr 2022 15:30:19 -0700 Subject: [PATCH 001/561] Refactor changes --- .../graph/httpcore/AuthenticationHandler.java | 8 ---- .../graph/httpcore/ChaosHttpHandler.java | 9 ---- .../graph/httpcore/RedirectHandler.java | 9 ---- .../graph/httpcore/RetryHandler.java | 9 ---- .../graph/httpcore/TelemetryHandler.java | 13 +++--- ...tions.java => TelemetryHandlerOption.java} | 2 +- .../graph/httpcore/TelemetryOptionsTest.java | 44 +++++++++---------- 7 files changed, 29 insertions(+), 65 deletions(-) rename src/main/java/com/microsoft/graph/httpcore/middlewareoption/{TelemetryOptions.java => TelemetryHandlerOption.java} (98%) diff --git a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java index ce125664b..9818cd2f3 100644 --- a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java @@ -9,7 +9,6 @@ import javax.annotation.Nonnull; import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; import okhttp3.Interceptor; import okhttp3.Request; @@ -43,13 +42,6 @@ public AuthenticationHandler(@Nonnull final IAuthenticationProvider authProvider public Response intercept(@Nonnull final Chain chain) throws IOException { Request originalRequest = chain.request(); - TelemetryOptions telemetryOptions = originalRequest.tag(TelemetryOptions.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryOptions(); - originalRequest = originalRequest.newBuilder().tag(TelemetryOptions.class, telemetryOptions).build(); - } - telemetryOptions.setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG); - try { final CompletableFuture future = authProvider.getAuthorizationTokenAsync(originalRequest.url().url()); final String accessToken = future.get(); diff --git a/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java b/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java index b1df1b4ee..3638bc280 100644 --- a/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java @@ -6,7 +6,6 @@ import javax.annotation.Nonnull; import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; import okhttp3.Interceptor; import okhttp3.MediaType; @@ -49,14 +48,6 @@ public class ChaosHttpHandler implements Interceptor { @Nonnull public Response intercept(@Nonnull final Chain chain) throws IOException { Request request = chain.request(); - - TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryOptions(); - request = request.newBuilder().tag(TelemetryOptions.class, telemetryOptions).build(); - } - telemetryOptions.setFeatureUsage(TelemetryOptions.RETRY_HANDLER_ENABLED_FLAG); - final int dice = ThreadLocalRandom.current().nextInt(1, Integer.MAX_VALUE); if(dice % failureRate == 0) { diff --git a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java index d66a36fbd..4ba69551b 100644 --- a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java @@ -14,7 +14,6 @@ import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; import okhttp3.HttpUrl; import okhttp3.Interceptor; @@ -118,14 +117,6 @@ Request getRedirect( @Nonnull public Response intercept(@Nonnull final Chain chain) throws IOException { Request request = chain.request(); - - TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryOptions(); - request = request.newBuilder().tag(TelemetryOptions.class, telemetryOptions).build(); - } - telemetryOptions.setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG); - Response response = null; int requestsCount = 1; diff --git a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java index ed799a7f0..cf5472c63 100644 --- a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java @@ -9,7 +9,6 @@ import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry; import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; import com.microsoft.graph.httpcore.middlewareoption.RetryOptions; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; import com.microsoft.graph.logger.DefaultLogger; import com.microsoft.graph.logger.ILogger; @@ -166,14 +165,6 @@ boolean isBuffered(final Request request) { @Nonnull public Response intercept(@Nonnull final Chain chain) throws IOException { Request request = chain.request(); - - TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryOptions(); - request = request.newBuilder().tag(TelemetryOptions.class, telemetryOptions).build(); - } - telemetryOptions.setFeatureUsage(TelemetryOptions.RETRY_HANDLER_ENABLED_FLAG); - Response response = chain.proceed(request); // Use should retry pass along with this request diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index e9edb71ef..7775dee32 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -2,11 +2,10 @@ import java.io.IOException; import java.lang.reflect.Field; -import java.util.Objects; import javax.annotation.Nonnull; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; +import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import okhttp3.Interceptor; import okhttp3.Request; @@ -50,11 +49,11 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { final Request request = chain.request(); final Request.Builder telemetryAddedBuilder = request.newBuilder(); - TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class); - if(telemetryOptions == null) - telemetryOptions = new TelemetryOptions(); + TelemetryHandlerOption telemetryHandlerOption = request.tag(TelemetryHandlerOption.class); + if(telemetryHandlerOption == null) + telemetryHandlerOption = new TelemetryHandlerOption(); - final String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")"; + final String featureUsage = "(featureUsage=" + telemetryHandlerOption.getFeatureUsage() + ")"; final String javaVersion = System.getProperty("java.version"); final String androidVersion = getAndroidAPILevel(); final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + @@ -63,7 +62,7 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value); if(request.header(CLIENT_REQUEST_ID) == null) { - telemetryAddedBuilder.addHeader(CLIENT_REQUEST_ID, telemetryOptions.getClientRequestId()); + telemetryAddedBuilder.addHeader(CLIENT_REQUEST_ID, telemetryHandlerOption.getClientRequestId()); } return chain.proceed(telemetryAddedBuilder.build()); diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java similarity index 98% rename from src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java rename to src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java index 22ee826d2..8d36a47fb 100644 --- a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java +++ b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java @@ -8,7 +8,7 @@ /** * Options to be passed to the telemetry middleware. */ -public class TelemetryOptions { +public class TelemetryHandlerOption { /** * No SDK feature in use diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java index 0660094a2..28d3b81a8 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java @@ -5,49 +5,49 @@ import org.junit.jupiter.api.Test; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions; +import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; public class TelemetryOptionsTest { @Test public void createTelemetryOptionsTest() { - TelemetryOptions telemetryOptions = new TelemetryOptions(); - assertNotNull(telemetryOptions); - assertNotNull(telemetryOptions.getClientRequestId()); + TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); + assertNotNull(telemetryHandlerOption); + assertNotNull(telemetryHandlerOption.getClientRequestId()); } @Test public void setFeatureUsageTest() { - TelemetryOptions telemetryOptions = new TelemetryOptions(); - telemetryOptions.setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG); - telemetryOptions.setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG); - assertTrue(telemetryOptions.getSerializedFeatureUsage().compareTo("5")==0); + TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); + telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.AUTH_HANDLER_ENABLED_FLAG); + telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.REDIRECT_HANDLER_ENABLED_FLAG); + assertTrue(telemetryHandlerOption.getSerializedFeatureUsage().compareTo("5")==0); } @Test public void getSerializedFeatureUsageTest() { - TelemetryOptions telemetryOptions = new TelemetryOptions(); - telemetryOptions.setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG); - telemetryOptions.setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG); - telemetryOptions.setFeatureUsage(TelemetryOptions.RETRY_HANDLER_ENABLED_FLAG); - assertTrue(telemetryOptions.getSerializedFeatureUsage().compareTo("7")==0); + TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); + telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.AUTH_HANDLER_ENABLED_FLAG); + telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.REDIRECT_HANDLER_ENABLED_FLAG); + telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.RETRY_HANDLER_ENABLED_FLAG); + assertTrue(telemetryHandlerOption.getSerializedFeatureUsage().compareTo("7")==0); } @Test public void setClientRequestIdTest() { - TelemetryOptions telemetryOptions = new TelemetryOptions(); - telemetryOptions.setClientRequestId("test id"); - assertTrue(telemetryOptions.getClientRequestId().compareTo("test id")==0); + TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); + telemetryHandlerOption.setClientRequestId("test id"); + assertTrue(telemetryHandlerOption.getClientRequestId().compareTo("test id")==0); } @Test public void getClientRequestIdTest() { - TelemetryOptions telemetryOptions = new TelemetryOptions(); - assertNotNull(telemetryOptions.getClientRequestId()); - telemetryOptions.setClientRequestId("test id 1"); - assertTrue(telemetryOptions.getClientRequestId().compareTo("test id 1")==0); - telemetryOptions.setClientRequestId("test id 2"); - assertTrue(telemetryOptions.getClientRequestId().compareTo("test id 2")==0); + TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); + assertNotNull(telemetryHandlerOption.getClientRequestId()); + telemetryHandlerOption.setClientRequestId("test id 1"); + assertTrue(telemetryHandlerOption.getClientRequestId().compareTo("test id 1")==0); + telemetryHandlerOption.setClientRequestId("test id 2"); + assertTrue(telemetryHandlerOption.getClientRequestId().compareTo("test id 2")==0); } } From 32c93ea0fd4cc0dc73de18bae7d01d910a9e9ca1 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 13 Apr 2022 17:31:12 -0700 Subject: [PATCH 002/561] GraphTelemetryHandler progress to enable flagging of tasks --- .../com/microsoft/graph/CoreConstants.java | 32 +++++++++++++ .../microsoft/graph/httpcore/FeatureFlag.java | 22 +++++++++ ...andler.java => GraphTelemetryHandler.java} | 47 +++++-------------- .../microsoft/graph/httpcore/HttpClients.java | 2 +- .../graph/tasks/LargeFileUploadRequest.java | 3 ++ .../graph/httpcore/TelemetryHandlerTest.java | 27 ++++++----- 6 files changed, 83 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/microsoft/graph/CoreConstants.java create mode 100644 src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java rename src/main/java/com/microsoft/graph/httpcore/{TelemetryHandler.java => GraphTelemetryHandler.java} (61%) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java new file mode 100644 index 000000000..ed2ff4fad --- /dev/null +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -0,0 +1,32 @@ +package com.microsoft.graph; + +public class CoreConstants { + + private static class VersionValues { + private static final int Major = 3; + private static final int Minor = 0; + private static final int Patch = 0; + } + + public static class Headers { + public static final String Bearer = "Bearer"; + public static final String SdkVersionHeaderName = "SdkVersion"; + public static final String GraphVersionPrefix = "graph-java-core"; + public static final String AndroidVersionPrefix = "android"; + public static final String JavaVersionPrefix = "java"; + public static final String Version = String.format("v%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); + public static final String ClientRequestId = "client-request-id"; + public static final String FeatureFlag = "FeatureFlag"; + public static final String DefaultVersionValue = "0"; + + /**The following appear in dotnet core, are they necessary in Java? + * Content-Type header: + * public final String FormUrlEncodedContentType = "application/x-www-form-urlencoded"; + * Throw-site header: + * public final String ThrowSiteHeaderName = "X-ThrowSite"; + **/ + } + + //TODO add other constants classes as work on other core features continues + +} diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java new file mode 100644 index 000000000..8163767c5 --- /dev/null +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java @@ -0,0 +1,22 @@ +package com.microsoft.graph.httpcore; + +public class FeatureFlag { + public static final int NONE_FLAG = 0; + public static final int REDIRECT_HANDLER_FLAG = 1; + public static final int RETRY_HANDLER_FLAG = 2; + public static final int AUTH_HANDLER_FLAG = 4; + public static final int DEFAULT_HTTP_FLAG = 8; + public static final int LOGGING_HANDLER_FLAG = 16; + public static final int SERVICE_DISCOVERY_FLAG = 32; + public static final int COMPRESSION_HANDLER_FLAG = 64; + public static final int CONNECTION_POOL_FLAG = 128; + public static final int LONG_RUNNING_OP_FLAG = 256; + public static final int BATCH_REQUEST_FLAG = 512; + public static final int PAGE_ITERATOR_FLAG = 1024; + public static final int FILE_UPLOAD_FLAG = 2048; + + public static String addFeatureToHeader(FeatureFlag flag){ + return "This should be the header to add after calculating the change"; + } + +} diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java similarity index 61% rename from src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java rename to src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java index 7775dee32..3f8aae390 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java @@ -5,6 +5,7 @@ import javax.annotation.Nonnull; +import com.microsoft.graph.CoreConstants; import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import okhttp3.Interceptor; @@ -15,33 +16,7 @@ * Middleware responsible for adding telemetry information on SDK usage * Note: the telemetry only collects anonymous information on SDK version and usage. No personal information is collected. */ -public class TelemetryHandler implements Interceptor{ - - /** - * Http request header to send the telemetry infromation with - */ - public static final String SDK_VERSION = "SdkVersion"; - /** - * Current SDK version - */ - public static final String VERSION = "v2.0.11"; - /** - * Verion prefix - */ - public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; - /** - * Java version prefix - */ - public static final String JAVA_VERSION_PREFIX = "java"; - /** - * Android version prefix - */ - public static final String ANDROID_VERSION_PREFIX = "android"; - /** - * The client request ID header - */ - public static final String CLIENT_REQUEST_ID = "client-request-id"; - private static final String DEFAULT_VERSION_VALUE = "0"; +public class GraphTelemetryHandler implements Interceptor{ @Override @Nonnull @@ -56,13 +31,13 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { final String featureUsage = "(featureUsage=" + telemetryHandlerOption.getFeatureUsage() + ")"; final String javaVersion = System.getProperty("java.version"); final String androidVersion = getAndroidAPILevel(); - final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage + - (DEFAULT_VERSION_VALUE.equals(javaVersion) ? "" : (", " + JAVA_VERSION_PREFIX + "/" + javaVersion)) + - (DEFAULT_VERSION_VALUE.equals(androidVersion) ? "" : (", " + ANDROID_VERSION_PREFIX + "/" + androidVersion)); - telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value); + final String sdkversion_value = CoreConstants.Headers.GraphVersionPrefix + "/" + CoreConstants.Headers.Version + " " + featureUsage + + (CoreConstants.Headers.DefaultVersionValue.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JavaVersionPrefix + "/" + javaVersion)) + + (CoreConstants.Headers.DefaultVersionValue.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.AndroidVersionPrefix + "/" + androidVersion)); + telemetryAddedBuilder.addHeader(CoreConstants.Headers.SdkVersionHeaderName, sdkversion_value); - if(request.header(CLIENT_REQUEST_ID) == null) { - telemetryAddedBuilder.addHeader(CLIENT_REQUEST_ID, telemetryHandlerOption.getClientRequestId()); + if(request.header(CoreConstants.Headers.ClientRequestId) == null) { + telemetryAddedBuilder.addHeader(CoreConstants.Headers.ClientRequestId, telemetryHandlerOption.getClientRequestId()); } return chain.proceed(telemetryAddedBuilder.build()); @@ -87,16 +62,16 @@ private String getAndroidAPILevelInternal() { } } if(versionClass == null) - return DEFAULT_VERSION_VALUE; + return CoreConstants.Headers.DefaultVersionValue; else { final Field sdkVersionField = versionClass.getField("SDK_INT"); final Object value = sdkVersionField.get(null); final String valueStr = String.valueOf(value); - return valueStr == null || valueStr.equals("") ? DEFAULT_VERSION_VALUE : valueStr; + return valueStr == null || valueStr.equals("") ? CoreConstants.Headers.DefaultVersionValue : valueStr; } } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException ex) { // we're not on android and return "0" to align with java version which returns "0" when running on android - return DEFAULT_VERSION_VALUE; + return CoreConstants.Headers.DefaultVersionValue; } } } diff --git a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java index 70e62756b..477558fec 100644 --- a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java +++ b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java @@ -26,7 +26,7 @@ private HttpClients() { @Nonnull public static Builder custom() { return new OkHttpClient.Builder() - .addInterceptor(new TelemetryHandler()) + .addInterceptor(new GraphTelemetryHandler()) .followRedirects(false) .followSslRedirects(false); } diff --git a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java index ba2f67785..e63dc9209 100644 --- a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java +++ b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java @@ -11,10 +11,12 @@ import javax.annotation.Nullable; import javax.annotation.Nonnull; +import com.microsoft.graph.CoreConstants; import com.microsoft.graph.core.ClientException; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; import com.microsoft.graph.core.IBaseClient; +import com.microsoft.graph.httpcore.FeatureFlag; import com.microsoft.graph.options.Option; /** @@ -76,6 +78,7 @@ protected LargeFileUploadRequest(@Nonnull final String requestUrl, beginIndex, beginIndex + chunkSize - 1, totalLength)); + //this.baseRequest.addHeader(CoreConstants.Headers.FeatureFlag, FeatureFlag.FILE_UPLOAD_FLAG); } /** diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java index 795a88091..6012983d6 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java @@ -10,6 +10,7 @@ import java.net.URL; import java.util.concurrent.CompletableFuture; +import com.microsoft.graph.CoreConstants; import com.microsoft.graph.authentication.IAuthenticationProvider; import org.junit.jupiter.api.Test; @@ -21,23 +22,23 @@ public class TelemetryHandlerTest { @Test public void telemetryInitTest() { - final TelemetryHandler telemetryHandler = new TelemetryHandler(); - assertNotNull(telemetryHandler); + final GraphTelemetryHandler graphTelemetryHandler = new GraphTelemetryHandler(); + assertNotNull(graphTelemetryHandler); } @Test public void interceptTest() throws IOException { - final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" - +TelemetryHandler.VERSION; + final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" + + CoreConstants.Headers.Version; final IAuthenticationProvider authProvider = mock(IAuthenticationProvider.class); when(authProvider.getAuthorizationTokenAsync(any(URL.class))).thenReturn(CompletableFuture.completedFuture("")); final OkHttpClient client = HttpClients.createDefault(authProvider); final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); - assertTrue(!response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.ANDROID_VERSION_PREFIX)); // Android version is not going to be present on unit tests runnning on java platform - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(TelemetryHandler.JAVA_VERSION_PREFIX)); + assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); + assertTrue(!response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(CoreConstants.Headers.AndroidVersionPrefix)); // Android version is not going to be present on unit tests runnning on java platform + assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(CoreConstants.Headers.JavaVersionPrefix)); } @Test @@ -47,24 +48,24 @@ public void arrayInterceptorsTest() throws IOException { final AuthenticationHandler authenticationHandler = new AuthenticationHandler(authProvider); final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" - +TelemetryHandler.VERSION; + final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" + + CoreConstants.Headers.Version; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); + assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); } @Test public void arrayInterceptorEmptyTest() throws IOException { final Interceptor[] interceptors = null; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = TelemetryHandler.GRAPH_VERSION_PREFIX +"/" - +TelemetryHandler.VERSION; + final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" + + CoreConstants.Headers.Version; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(TelemetryHandler.SDK_VERSION).contains(expectedHeader)); + assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); } } From 21996d426373b29831a26fb08d50e0279e6c2d1d Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Thu, 14 Apr 2022 16:45:59 -0700 Subject: [PATCH 003/561] GraphTelemetryHandler todo for beta/v1 enpoint --- .../graph/httpcore/GraphTelemetryHandler.java | 2 +- .../TelemetryHandlerOption.java | 29 ++----------------- .../graph/httpcore/TelemetryHandlerTest.java | 12 ++++++++ .../graph/httpcore/TelemetryOptionsTest.java | 10 +++---- 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java index 3f8aae390..a47dc6d9c 100644 --- a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java @@ -23,7 +23,7 @@ public class GraphTelemetryHandler implements Interceptor{ public Response intercept(@Nonnull final Chain chain) throws IOException { final Request request = chain.request(); final Request.Builder telemetryAddedBuilder = request.newBuilder(); - + //TODO: add a check to see if the url is using v1 or beta enpoint, add this as a value in the telemetryHandler options TelemetryHandlerOption telemetryHandlerOption = request.tag(TelemetryHandlerOption.class); if(telemetryHandlerOption == null) telemetryHandlerOption = new TelemetryHandlerOption(); diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java index 8d36a47fb..0ef7cf3b9 100644 --- a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java +++ b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java @@ -5,37 +5,14 @@ import javax.annotation.Nonnull; +import com.microsoft.graph.httpcore.FeatureFlag; + /** * Options to be passed to the telemetry middleware. */ public class TelemetryHandlerOption { - /** - * No SDK feature in use - */ - public static final int NONE_FLAG = 0; - /** - * Redirect handler enabled - */ - public static final int REDIRECT_HANDLER_ENABLED_FLAG = 1; - /** - * Retry handler enabled - */ - public static final int RETRY_HANDLER_ENABLED_FLAG = 2; - /** - * Authentication handler enabled - */ - public static final int AUTH_HANDLER_ENABLED_FLAG = 4; - /** - * Default http provider enabled - */ - public static final int DEFAULT_HTTPROVIDER_ENABLED_FLAG = 8; - /** - * Logging handler enabled - */ - public static final int LOGGING_HANDLER_ENABLED_FLAG = 16; - - private int featureUsage = NONE_FLAG; + private int featureUsage = FeatureFlag.NONE_FLAG; private String clientRequestId; /** diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java index 6012983d6..e84f37dd6 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java @@ -56,6 +56,18 @@ public void arrayInterceptorsTest() throws IOException { assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); } + @Test + public void arrayInterceptorsTest2() throws IOException{ + Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler()}; + OkHttpClient client = HttpClients.createFromInterceptors(interceptors); + Response response = client.newCall(request).execute(); + System.out.println(response.request().headers().toString()); + System.out.println(response.request().headers().size()); + + } + + @Test public void arrayInterceptorEmptyTest() throws IOException { final Interceptor[] interceptors = null; diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java index 28d3b81a8..91b671ebc 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java @@ -19,17 +19,17 @@ public void createTelemetryOptionsTest() { @Test public void setFeatureUsageTest() { TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.AUTH_HANDLER_ENABLED_FLAG); - telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.REDIRECT_HANDLER_ENABLED_FLAG); + telemetryHandlerOption.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); + telemetryHandlerOption.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); assertTrue(telemetryHandlerOption.getSerializedFeatureUsage().compareTo("5")==0); } @Test public void getSerializedFeatureUsageTest() { TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.AUTH_HANDLER_ENABLED_FLAG); - telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.REDIRECT_HANDLER_ENABLED_FLAG); - telemetryHandlerOption.setFeatureUsage(TelemetryHandlerOption.RETRY_HANDLER_ENABLED_FLAG); + telemetryHandlerOption.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); + telemetryHandlerOption.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); + telemetryHandlerOption.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); assertTrue(telemetryHandlerOption.getSerializedFeatureUsage().compareTo("7")==0); } From 121196a0c05f2fbbb637f8bd28e860625af245b8 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Tue, 19 Apr 2022 19:43:41 -0700 Subject: [PATCH 004/561] add endpoint check, v1.0 or beta to telemetryhandler --- .../microsoft/graph/httpcore/AuthenticationHandler.java | 8 ++++++++ .../microsoft/graph/httpcore/GraphTelemetryHandler.java | 7 ++++++- .../com/microsoft/graph/httpcore/RedirectHandler.java | 8 ++++++++ .../java/com/microsoft/graph/httpcore/RetryHandler.java | 8 ++++++++ .../microsoft/graph/httpcore/TelemetryHandlerTest.java | 2 +- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java index 9818cd2f3..e6766cf6e 100644 --- a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java @@ -10,6 +10,7 @@ import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; +import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; @@ -42,6 +43,13 @@ public AuthenticationHandler(@Nonnull final IAuthenticationProvider authProvider public Response intercept(@Nonnull final Chain chain) throws IOException { Request originalRequest = chain.request(); + TelemetryHandlerOption telemetryOptions = originalRequest.tag(TelemetryHandlerOption.class); + if(telemetryOptions == null) { + telemetryOptions = new TelemetryHandlerOption(); + originalRequest = originalRequest.newBuilder().tag(TelemetryHandlerOption.class, telemetryOptions).build(); + } + telemetryOptions.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); + try { final CompletableFuture future = authProvider.getAuthorizationTokenAsync(originalRequest.url().url()); final String accessToken = future.get(); diff --git a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java index a47dc6d9c..cdcf5411a 100644 --- a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java @@ -23,11 +23,14 @@ public class GraphTelemetryHandler implements Interceptor{ public Response intercept(@Nonnull final Chain chain) throws IOException { final Request request = chain.request(); final Request.Builder telemetryAddedBuilder = request.newBuilder(); - //TODO: add a check to see if the url is using v1 or beta enpoint, add this as a value in the telemetryHandler options + TelemetryHandlerOption telemetryHandlerOption = request.tag(TelemetryHandlerOption.class); if(telemetryHandlerOption == null) telemetryHandlerOption = new TelemetryHandlerOption(); + //This assumes a call to graph will always include v1.0 or beta in the url, should this assumption be changed? + final String graphEndpoint = request.url().toString().contains("/v1.0/") ? "v1.0" : "beta"; + System.out.println(graphEndpoint); final String featureUsage = "(featureUsage=" + telemetryHandlerOption.getFeatureUsage() + ")"; final String javaVersion = System.getProperty("java.version"); final String androidVersion = getAndroidAPILevel(); @@ -40,6 +43,8 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { telemetryAddedBuilder.addHeader(CoreConstants.Headers.ClientRequestId, telemetryHandlerOption.getClientRequestId()); } + //TODO: add the option to set sdk and core version on telemetryOptions. Set default graph version to latest major version most likely. Add this constants. + return chain.proceed(telemetryAddedBuilder.build()); } diff --git a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java index 4ba69551b..f91e4f78b 100644 --- a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java @@ -15,6 +15,7 @@ import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions; +import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.Request; @@ -120,6 +121,13 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { Response response = null; int requestsCount = 1; + TelemetryHandlerOption telemetryOptions = request.tag(TelemetryHandlerOption.class); + if(telemetryOptions == null) { + telemetryOptions = new TelemetryHandlerOption(); + request = request.newBuilder().tag(TelemetryHandlerOption.class, telemetryOptions).build(); + } + telemetryOptions.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); + // Use should retry pass along with this request RedirectOptions redirectOptions = request.tag(RedirectOptions.class); redirectOptions = redirectOptions != null ? redirectOptions : this.mRedirectOptions; diff --git a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java index cf5472c63..7389cbf32 100644 --- a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java @@ -9,6 +9,7 @@ import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry; import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; import com.microsoft.graph.httpcore.middlewareoption.RetryOptions; +import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import com.microsoft.graph.logger.DefaultLogger; import com.microsoft.graph.logger.ILogger; @@ -167,6 +168,13 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { Request request = chain.request(); Response response = chain.proceed(request); + TelemetryHandlerOption telemetryOptions = request.tag(TelemetryHandlerOption.class); + if(telemetryOptions == null) { + telemetryOptions = new TelemetryHandlerOption(); + request = request.newBuilder().tag(TelemetryHandlerOption.class, telemetryOptions).build(); + } + telemetryOptions.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); + // Use should retry pass along with this request RetryOptions retryOption = request.tag(RetryOptions.class); retryOption = retryOption != null ? retryOption : mRetryOption; diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java index e84f37dd6..678c820ee 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java @@ -58,7 +58,7 @@ public void arrayInterceptorsTest() throws IOException { @Test public void arrayInterceptorsTest2() throws IOException{ - Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); + Request request = new Request.Builder().url("https://graph.microsoft.com/beta/users/").build(); final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler()}; OkHttpClient client = HttpClients.createFromInterceptors(interceptors); Response response = client.newCall(request).execute(); From e1d97146c14594ba7622e77c41d0e8a77433b8e9 Mon Sep 17 00:00:00 2001 From: ramsessanchez <63934382+ramsessanchez@users.noreply.github.com> Date: Thu, 21 Apr 2022 19:12:59 -0700 Subject: [PATCH 005/561] Preparing GraphTelemetryHandlerfor updated spec --- .../com/microsoft/graph/CoreConstants.java | 2 +- .../graph/http/CoreHttpProvider.java | 3 + .../graph/httpcore/AuthenticationHandler.java | 17 ++--- .../graph/httpcore/ChaosHttpHandler.java | 6 -- .../graph/httpcore/FeatureTracker.java | 31 +++++++++ .../graph/httpcore/GraphTelemetryHandler.java | 41 ++++++++---- .../microsoft/graph/httpcore/HttpClients.java | 7 +- .../graph/httpcore/RedirectHandler.java | 17 ++--- .../graph/httpcore/RetryHandler.java | 18 ++--- .../middlewareoption/GraphClientOptions.java | 67 +++++++++++++++++++ .../middlewareoption/MiddlewareType.java | 27 -------- .../TelemetryHandlerOption.java | 62 ----------------- .../graph/httpcore/FeatureTrackerTest.java | 24 +++++++ ...st.java => GraphTelemetryHandlerTest.java} | 16 +++-- .../graph/httpcore/HttpClientsTest.java | 2 +- .../graph/httpcore/TelemetryOptionsTest.java | 43 ++++-------- 16 files changed, 199 insertions(+), 184 deletions(-) create mode 100644 src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java create mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/MiddlewareType.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java create mode 100644 src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java rename src/test/java/com/microsoft/graph/httpcore/{TelemetryHandlerTest.java => GraphTelemetryHandlerTest.java} (82%) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java index ed2ff4fad..6be703562 100644 --- a/src/main/java/com/microsoft/graph/CoreConstants.java +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -14,7 +14,7 @@ public static class Headers { public static final String GraphVersionPrefix = "graph-java-core"; public static final String AndroidVersionPrefix = "android"; public static final String JavaVersionPrefix = "java"; - public static final String Version = String.format("v%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); + public static final String Version = String.format("%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); public static final String ClientRequestId = "client-request-id"; public static final String FeatureFlag = "FeatureFlag"; public static final String DefaultVersionValue = "0"; diff --git a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java index 8fd8be582..5c9b4e9df 100644 --- a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java +++ b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java @@ -25,6 +25,7 @@ import com.google.common.annotations.VisibleForTesting; import com.microsoft.graph.core.ClientException; +import com.microsoft.graph.httpcore.FeatureTracker; import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions; import com.microsoft.graph.httpcore.middlewareoption.RetryOptions; import com.microsoft.graph.logger.ILogger; @@ -266,6 +267,8 @@ public Request getHttpRequest(@Nonnull final IHttpRequest request if(retryOptions != null) { corehttpRequestBuilder = corehttpRequestBuilder.tag(RetryOptions.class, retryOptions); } + //Add a feature tracker to the request, ability to track features here + corehttpRequestBuilder.tag(FeatureTracker.class, new FeatureTracker()); String contenttype = null; diff --git a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java index e6766cf6e..05335b00e 100644 --- a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java @@ -8,9 +8,6 @@ import javax.annotation.Nonnull; -import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; - -import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; @@ -23,10 +20,6 @@ public class AuthenticationHandler implements Interceptor { protected static final String BEARER = "Bearer "; /** The authorization request header name */ protected static final String AUTHORIZATION_HEADER = "Authorization"; - /** - * The current middleware type - */ - public final MiddlewareType MIDDLEWARE_TYPE = MiddlewareType.AUTHENTICATION; private IAuthenticationProvider authProvider; @@ -43,12 +36,12 @@ public AuthenticationHandler(@Nonnull final IAuthenticationProvider authProvider public Response intercept(@Nonnull final Chain chain) throws IOException { Request originalRequest = chain.request(); - TelemetryHandlerOption telemetryOptions = originalRequest.tag(TelemetryHandlerOption.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryHandlerOption(); - originalRequest = originalRequest.newBuilder().tag(TelemetryHandlerOption.class, telemetryOptions).build(); + FeatureTracker featureTracker = originalRequest.tag(FeatureTracker.class); + if(featureTracker == null) { + featureTracker = new FeatureTracker(); + originalRequest = originalRequest.newBuilder().tag(FeatureTracker.class, featureTracker).build(); } - telemetryOptions.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); + featureTracker.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); try { final CompletableFuture future = authProvider.getAuthorizationTokenAsync(originalRequest.url().url()); diff --git a/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java b/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java index 3638bc280..d4e929617 100644 --- a/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java @@ -5,8 +5,6 @@ import javax.annotation.Nonnull; -import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; - import okhttp3.Interceptor; import okhttp3.MediaType; import okhttp3.Protocol; @@ -19,10 +17,6 @@ * interceptor that randomly fails the responses for unit testing purposes */ public class ChaosHttpHandler implements Interceptor { - /** - * The current middleware type - */ - public final MiddlewareType MIDDLEWARE_TYPE = MiddlewareType.RETRY; /** * constant string being used */ diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java b/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java new file mode 100644 index 000000000..5c5888763 --- /dev/null +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java @@ -0,0 +1,31 @@ +package com.microsoft.graph.httpcore; + +import javax.annotation.Nonnull; + +public class FeatureTracker { + + private int featureUsage = FeatureFlag.NONE_FLAG; + /** + * Sets a numeric representation of the SDK feature usage + * @param flag a numeric representation of the SDK feature usage + */ + public void setFeatureUsage(int flag) { + featureUsage = featureUsage | flag; + } + /** + * Gets a numeric representation of the SDK feature usage + * @return a numeric representation of the SDK feature usage + */ + public int getFeatureUsage() { + return featureUsage; + } + + /** + * Gets a serialized representation of the SDK feature usage. + * @return a serialized representation of the SDK feature usage + */ + @Nonnull + public String getSerializedFeatureUsage() { + return Integer.toHexString(featureUsage); + } +} diff --git a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java index cdcf5411a..c57973a46 100644 --- a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java @@ -6,8 +6,9 @@ import javax.annotation.Nonnull; import com.microsoft.graph.CoreConstants; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; +import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; @@ -18,33 +19,45 @@ */ public class GraphTelemetryHandler implements Interceptor{ + private GraphClientOptions mGraphClientOptions; + + public GraphTelemetryHandler(){ + this.mGraphClientOptions = new GraphClientOptions(); + } + + @SuppressFBWarnings + //graphClientOptions exposes strings which are naturally immutable + public GraphTelemetryHandler(@Nonnull final GraphClientOptions graphClientOptions){ + this.mGraphClientOptions = graphClientOptions; + } + @Override @Nonnull public Response intercept(@Nonnull final Chain chain) throws IOException { final Request request = chain.request(); final Request.Builder telemetryAddedBuilder = request.newBuilder(); - TelemetryHandlerOption telemetryHandlerOption = request.tag(TelemetryHandlerOption.class); - if(telemetryHandlerOption == null) - telemetryHandlerOption = new TelemetryHandlerOption(); + FeatureTracker featureTracker = request.tag(FeatureTracker.class); + if(featureTracker == null) { + featureTracker = new FeatureTracker(); + } - //This assumes a call to graph will always include v1.0 or beta in the url, should this assumption be changed? - final String graphEndpoint = request.url().toString().contains("/v1.0/") ? "v1.0" : "beta"; - System.out.println(graphEndpoint); - final String featureUsage = "(featureUsage=" + telemetryHandlerOption.getFeatureUsage() + ")"; + //This assumes a call to graph will always include v1.0 or beta in the url + final String graphEndpoint = request.url().toString().contains("/v1.0/") ? "-v1.0" : "-beta"; + final String featureUsage = "(featureUsage=" + featureTracker.getSerializedFeatureUsage() + ")"; final String javaVersion = System.getProperty("java.version"); final String androidVersion = getAndroidAPILevel(); - final String sdkversion_value = CoreConstants.Headers.GraphVersionPrefix + "/" + CoreConstants.Headers.Version + " " + featureUsage + - (CoreConstants.Headers.DefaultVersionValue.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JavaVersionPrefix + "/" + javaVersion)) + - (CoreConstants.Headers.DefaultVersionValue.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.AndroidVersionPrefix + "/" + androidVersion)); + final String sdkversion_value = "graph-" + CoreConstants.Headers.JavaVersionPrefix + graphEndpoint + + (mGraphClientOptions.getClientLibraryVersion() == null ? "" : "/"+ mGraphClientOptions.getClientLibraryVersion()) + ", " + + CoreConstants.Headers.GraphVersionPrefix + "/" + mGraphClientOptions.getCoreLibraryVersion() + " " + featureUsage + + (CoreConstants.Headers.DefaultVersionValue.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JavaVersionPrefix + "/" + javaVersion)) + + (CoreConstants.Headers.DefaultVersionValue.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.AndroidVersionPrefix + "/" + androidVersion)); telemetryAddedBuilder.addHeader(CoreConstants.Headers.SdkVersionHeaderName, sdkversion_value); if(request.header(CoreConstants.Headers.ClientRequestId) == null) { - telemetryAddedBuilder.addHeader(CoreConstants.Headers.ClientRequestId, telemetryHandlerOption.getClientRequestId()); + telemetryAddedBuilder.addHeader(CoreConstants.Headers.ClientRequestId, mGraphClientOptions.getClientRequestId()); } - //TODO: add the option to set sdk and core version on telemetryOptions. Set default graph version to latest major version most likely. Add this constants. - return chain.proceed(telemetryAddedBuilder.build()); } diff --git a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java index 477558fec..7c0abfda2 100644 --- a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java +++ b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java @@ -1,12 +1,14 @@ package com.microsoft.graph.httpcore; import com.microsoft.graph.authentication.IAuthenticationProvider; +import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.OkHttpClient.Builder; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Arrays; import java.util.Objects; /** @@ -26,7 +28,7 @@ private HttpClients() { @Nonnull public static Builder custom() { return new OkHttpClient.Builder() - .addInterceptor(new GraphTelemetryHandler()) + //.addInterceptor(new GraphTelemetryHandler()) removing as default interceptor until we can determine when it is most safe to add clientOptions .followRedirects(false) .followSslRedirects(false); } @@ -42,6 +44,7 @@ public static Builder custom() { public static OkHttpClient createDefault(@Nonnull final IAuthenticationProvider auth) { Objects.requireNonNull(auth, "parameter auth cannot be null"); return custom() + .addInterceptor(new GraphTelemetryHandler()) //as it is default it will build with default client options .addInterceptor(new AuthenticationHandler(auth)) .addInterceptor(new RetryHandler()) .addInterceptor(new RedirectHandler()) @@ -56,7 +59,9 @@ public static OkHttpClient createDefault(@Nonnull final IAuthenticationProvider */ @Nonnull public static OkHttpClient createFromInterceptors(@Nullable final Interceptor[] interceptors) { + //TelemetryInterceptor must be included in interceptors list as it is not default in custom() OkHttpClient.Builder builder = custom(); + System.out.println(builder.interceptors().toString()); if(interceptors != null) for(Interceptor interceptor : interceptors) { if(interceptor != null) diff --git a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java index f91e4f78b..45a56d46b 100644 --- a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java @@ -12,10 +12,8 @@ import javax.annotation.Nullable; import javax.annotation.Nonnull; -import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.Request; @@ -26,11 +24,6 @@ */ public class RedirectHandler implements Interceptor{ - /** - * The current middleware type - */ - public final MiddlewareType MIDDLEWARE_TYPE = MiddlewareType.REDIRECT; - private RedirectOptions mRedirectOptions; /** @@ -121,12 +114,12 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { Response response = null; int requestsCount = 1; - TelemetryHandlerOption telemetryOptions = request.tag(TelemetryHandlerOption.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryHandlerOption(); - request = request.newBuilder().tag(TelemetryHandlerOption.class, telemetryOptions).build(); + FeatureTracker featureTracker = request.tag(FeatureTracker.class); + if(featureTracker == null) { + featureTracker = new FeatureTracker(); + request = request.newBuilder().tag(FeatureTracker.class, featureTracker).build(); } - telemetryOptions.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); + featureTracker.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); // Use should retry pass along with this request RedirectOptions redirectOptions = request.tag(RedirectOptions.class); diff --git a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java index 7389cbf32..9d39ccad4 100644 --- a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java @@ -7,9 +7,7 @@ import javax.annotation.Nonnull; import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry; -import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType; import com.microsoft.graph.httpcore.middlewareoption.RetryOptions; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; import com.microsoft.graph.logger.DefaultLogger; import com.microsoft.graph.logger.ILogger; @@ -23,12 +21,6 @@ * The middleware responsible for retrying requests when they fail because of transient issues */ public class RetryHandler implements Interceptor{ - - /** - * Type of the current middleware - */ - public final MiddlewareType MIDDLEWARE_TYPE = MiddlewareType.RETRY; - private RetryOptions mRetryOption; /** @@ -168,12 +160,12 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { Request request = chain.request(); Response response = chain.proceed(request); - TelemetryHandlerOption telemetryOptions = request.tag(TelemetryHandlerOption.class); - if(telemetryOptions == null) { - telemetryOptions = new TelemetryHandlerOption(); - request = request.newBuilder().tag(TelemetryHandlerOption.class, telemetryOptions).build(); + FeatureTracker featureTracker = request.tag(FeatureTracker.class); + if(featureTracker == null) { + featureTracker = new FeatureTracker(); + request = request.newBuilder().tag(FeatureTracker.class, featureTracker).build(); } - telemetryOptions.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); + featureTracker.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); // Use should retry pass along with this request RetryOptions retryOption = request.tag(RetryOptions.class); diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java new file mode 100644 index 000000000..415153e0f --- /dev/null +++ b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java @@ -0,0 +1,67 @@ +package com.microsoft.graph.httpcore.middlewareoption; + +import java.util.Objects; +import java.util.UUID; + +import javax.annotation.Nonnull; + +import com.microsoft.graph.CoreConstants; + +/** + * Options to be passed to the telemetry middleware. + */ +public class GraphClientOptions implements IMiddlewareControl{ + + private String clientRequestId; + private String coreLibraryVersion; + private String clientLibraryVersion; + + /** + * Set the core library version as a String, in this format 'x.x.x' + * @param version core library version specified by user. + */ + public void setCoreLibraryVersion(@Nonnull final String version){ + this.coreLibraryVersion = Objects.requireNonNull(version, "parameter version cannot be null"); + } + /** + * Get the core library version as a String, in this format 'x.x.x' + * If null return the value in CoreConstants. + * @return core library version. + */ + public String getCoreLibraryVersion() { + return this.coreLibraryVersion == null ? CoreConstants.Headers.Version : this.coreLibraryVersion; + } + /** + * Sets a string representation of the client library + * @param version client library version specified by user. + */ + public void setClientLibraryVersion(@Nonnull final String version) { + this.clientLibraryVersion = Objects.requireNonNull(version, "parameter version cannot be null"); + } + /** + * Get the client library version as a string + * If null return null; + * @return client library version. + */ + public String getClientLibraryVersion() { + return this.clientLibraryVersion == null ? null : this.clientLibraryVersion; + } + /** + * Sets the client request id + * @param clientRequestId the client request id to set, preferably the string representation of a GUID + */ + public void setClientRequestId(@Nonnull final String clientRequestId) { + this.clientRequestId = Objects.requireNonNull(clientRequestId, "parameter clientRequestId cannot be null"); + } + /** + * Gets the client request id + * @return the client request id + */ + @Nonnull + public String getClientRequestId() { + if(clientRequestId == null) { + clientRequestId = UUID.randomUUID().toString(); + } + return clientRequestId; + } +} diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/MiddlewareType.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/MiddlewareType.java deleted file mode 100644 index 3c05d3dd1..000000000 --- a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/MiddlewareType.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.microsoft.graph.httpcore.middlewareoption; - -/** - * The type of middleware to applied to the request/response - */ -public enum MiddlewareType { - - /** - * Authentication Middleware - */ - AUTHENTICATION, - - /** - * Redirect Middleware - */ - REDIRECT, - - /** - * Retry Middleware - */ - RETRY, - - /** - * Not supported - */ - NOT_SUPPORTED -} diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java deleted file mode 100644 index 0ef7cf3b9..000000000 --- a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryHandlerOption.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.microsoft.graph.httpcore.middlewareoption; - -import java.util.Objects; -import java.util.UUID; - -import javax.annotation.Nonnull; - -import com.microsoft.graph.httpcore.FeatureFlag; - -/** - * Options to be passed to the telemetry middleware. - */ -public class TelemetryHandlerOption { - - private int featureUsage = FeatureFlag.NONE_FLAG; - private String clientRequestId; - - /** - * Sets a numeric representation of the SDK feature usage - * @param flag a numeric representation of the SDK feature usage - */ - public void setFeatureUsage(int flag) { - featureUsage = featureUsage | flag; - } - - /** - * Gets a numeric representation of the SDK feature usage - * @return a numeric representation of the SDK feature usage - */ - public int getFeatureUsage() { - return featureUsage; - } - - /** - * Gets a serialized representation of the SDK feature usage. - * @return a serialized representation of the SDK feature usage - */ - @Nonnull - public String getSerializedFeatureUsage() { - return Integer.toHexString(featureUsage); - } - - /** - * Sets the client request id - * @param clientRequestId the client request id to set, preferably the string representation of a GUID - */ - public void setClientRequestId(@Nonnull final String clientRequestId) { - this.clientRequestId = Objects.requireNonNull(clientRequestId, "parameter clientRequestId cannot be null"); - } - /** - * Gets the client request id - * @return the client request id - */ - @Nonnull - public String getClientRequestId() { - if(clientRequestId == null) { - clientRequestId = UUID.randomUUID().toString(); - } - return clientRequestId; - } - -} diff --git a/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java b/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java new file mode 100644 index 000000000..f1b455244 --- /dev/null +++ b/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java @@ -0,0 +1,24 @@ +package com.microsoft.graph.httpcore; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class FeatureTrackerTest { + @Test + public void setFeatureUsageTest() { + FeatureTracker featureTracker = new FeatureTracker(); + featureTracker.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); + featureTracker.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); + assertTrue(featureTracker.getSerializedFeatureUsage().compareTo("5")==0); + } + + @Test + public void getSerializedFeatureUsageTest() { + FeatureTracker featureTracker = new FeatureTracker(); + featureTracker.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); + featureTracker.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); + featureTracker.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); + assertTrue(featureTracker.getSerializedFeatureUsage().compareTo("7")==0); + } +} diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java similarity index 82% rename from src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java rename to src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java index 678c820ee..1a4feac39 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java @@ -12,6 +12,7 @@ import com.microsoft.graph.CoreConstants; import com.microsoft.graph.authentication.IAuthenticationProvider; +import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; import org.junit.jupiter.api.Test; import okhttp3.Interceptor; @@ -19,7 +20,7 @@ import okhttp3.Request; import okhttp3.Response; -public class TelemetryHandlerTest { +public class GraphTelemetryHandlerTest { @Test public void telemetryInitTest() { final GraphTelemetryHandler graphTelemetryHandler = new GraphTelemetryHandler(); @@ -46,31 +47,36 @@ public void arrayInterceptorsTest() throws IOException { final IAuthenticationProvider authProvider = mock(IAuthenticationProvider.class); when(authProvider.getAuthorizationTokenAsync(any(URL.class))).thenReturn(CompletableFuture.completedFuture("")); final AuthenticationHandler authenticationHandler = new AuthenticationHandler(authProvider); - final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; + final Interceptor[] interceptors = {new GraphTelemetryHandler(), new RetryHandler(), new RedirectHandler(), authenticationHandler}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" + CoreConstants.Headers.Version; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); + System.out.println(response.request().header(CoreConstants.Headers.SdkVersionHeaderName)); + System.out.println(expectedHeader); assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); } @Test public void arrayInterceptorsTest2() throws IOException{ Request request = new Request.Builder().url("https://graph.microsoft.com/beta/users/").build(); - final Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler()}; + GraphClientOptions graphClientOptions = new GraphClientOptions(); + graphClientOptions.setClientLibraryVersion("5.9.0"); + graphClientOptions.setCoreLibraryVersion("2.9.0"); + + final Interceptor[] interceptors = {new GraphTelemetryHandler(graphClientOptions), new RetryHandler(), new RedirectHandler()}; OkHttpClient client = HttpClients.createFromInterceptors(interceptors); Response response = client.newCall(request).execute(); System.out.println(response.request().headers().toString()); - System.out.println(response.request().headers().size()); } @Test public void arrayInterceptorEmptyTest() throws IOException { - final Interceptor[] interceptors = null; + final Interceptor[] interceptors = new Interceptor[] {new GraphTelemetryHandler()}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" + CoreConstants.Headers.Version; diff --git a/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java b/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java index 86ea5f9b2..7985fc0ac 100644 --- a/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java @@ -22,7 +22,7 @@ public void testHttpClientCreation() { @SuppressWarnings("unchecked") public void arrayInterceptorsTest() { AuthenticationHandler authenticationHandler = new AuthenticationHandler(mock(IAuthenticationProvider.class)); - Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler}; + Interceptor[] interceptors = {new GraphTelemetryHandler(), new RetryHandler(), new RedirectHandler(), authenticationHandler}; OkHttpClient client = HttpClients.createFromInterceptors(interceptors); assertTrue(client.interceptors().size()==4); } diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java index 91b671ebc..4b3726e80 100644 --- a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java @@ -5,49 +5,32 @@ import org.junit.jupiter.api.Test; -import com.microsoft.graph.httpcore.middlewareoption.TelemetryHandlerOption; +import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; public class TelemetryOptionsTest { @Test public void createTelemetryOptionsTest() { - TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - assertNotNull(telemetryHandlerOption); - assertNotNull(telemetryHandlerOption.getClientRequestId()); - } - - @Test - public void setFeatureUsageTest() { - TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - telemetryHandlerOption.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); - telemetryHandlerOption.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); - assertTrue(telemetryHandlerOption.getSerializedFeatureUsage().compareTo("5")==0); - } - - @Test - public void getSerializedFeatureUsageTest() { - TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - telemetryHandlerOption.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); - telemetryHandlerOption.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); - telemetryHandlerOption.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); - assertTrue(telemetryHandlerOption.getSerializedFeatureUsage().compareTo("7")==0); + GraphClientOptions graphClientOptions = new GraphClientOptions(); + assertNotNull(graphClientOptions); + assertNotNull(graphClientOptions.getClientRequestId()); } @Test public void setClientRequestIdTest() { - TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - telemetryHandlerOption.setClientRequestId("test id"); - assertTrue(telemetryHandlerOption.getClientRequestId().compareTo("test id")==0); + GraphClientOptions graphClientOptions = new GraphClientOptions(); + graphClientOptions.setClientRequestId("test id"); + assertTrue(graphClientOptions.getClientRequestId().compareTo("test id")==0); } @Test public void getClientRequestIdTest() { - TelemetryHandlerOption telemetryHandlerOption = new TelemetryHandlerOption(); - assertNotNull(telemetryHandlerOption.getClientRequestId()); - telemetryHandlerOption.setClientRequestId("test id 1"); - assertTrue(telemetryHandlerOption.getClientRequestId().compareTo("test id 1")==0); - telemetryHandlerOption.setClientRequestId("test id 2"); - assertTrue(telemetryHandlerOption.getClientRequestId().compareTo("test id 2")==0); + GraphClientOptions graphClientOptions = new GraphClientOptions(); + assertNotNull(graphClientOptions.getClientRequestId()); + graphClientOptions.setClientRequestId("test id 1"); + assertTrue(graphClientOptions.getClientRequestId().compareTo("test id 1")==0); + graphClientOptions.setClientRequestId("test id 2"); + assertTrue(graphClientOptions.getClientRequestId().compareTo("test id 2")==0); } } From 1cf91953770168bde00172adfd84150d635d19c2 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Mon, 25 Apr 2022 16:32:28 -0700 Subject: [PATCH 006/561] Code-Lint compliance changes --- .../com/microsoft/graph/CoreConstants.java | 18 ++++----- .../microsoft/graph/httpcore/FeatureFlag.java | 5 --- .../graph/httpcore/FeatureTracker.java | 2 + .../graph/httpcore/GraphTelemetryHandler.java | 20 +++++----- .../microsoft/graph/httpcore/HttpClients.java | 4 +- .../middlewareoption/GraphClientOptions.java | 2 +- .../graph/tasks/LargeFileUploadRequest.java | 5 +-- .../BaseAuthenticationProviderTest.java | 4 +- .../httpcore/GraphTelemetryHandlerTest.java | 40 ++++++------------- 9 files changed, 39 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java index 6be703562..b0db76106 100644 --- a/src/main/java/com/microsoft/graph/CoreConstants.java +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -9,15 +9,15 @@ private static class VersionValues { } public static class Headers { - public static final String Bearer = "Bearer"; - public static final String SdkVersionHeaderName = "SdkVersion"; - public static final String GraphVersionPrefix = "graph-java-core"; - public static final String AndroidVersionPrefix = "android"; - public static final String JavaVersionPrefix = "java"; - public static final String Version = String.format("%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); - public static final String ClientRequestId = "client-request-id"; - public static final String FeatureFlag = "FeatureFlag"; - public static final String DefaultVersionValue = "0"; + public static final String BEARER = "Bearer"; + public static final String SDK_VERSION_HEADER_NAME = "SdkVersion"; + public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; + public static final String ANDROID_VERSION_PREFIX = "android"; + public static final String JAVA_VERSION_PREFIX = "java"; + public static final String VERSION = String.format("%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); + public static final String CLIENT_REQUEST_ID = "client-request-id"; + public static final String FEATURE_FLAG = "FeatureFlag"; + public static final String DEFAULT_VERSION_VALUE = "0"; /**The following appear in dotnet core, are they necessary in Java? * Content-Type header: diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java index 8163767c5..185615c0f 100644 --- a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java @@ -14,9 +14,4 @@ public class FeatureFlag { public static final int BATCH_REQUEST_FLAG = 512; public static final int PAGE_ITERATOR_FLAG = 1024; public static final int FILE_UPLOAD_FLAG = 2048; - - public static String addFeatureToHeader(FeatureFlag flag){ - return "This should be the header to add after calculating the change"; - } - } diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java b/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java index 5c5888763..be8e316a4 100644 --- a/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java @@ -28,4 +28,6 @@ public int getFeatureUsage() { public String getSerializedFeatureUsage() { return Integer.toHexString(featureUsage); } + + // TODO: add a method to add a feature flag to the header, do this once implementation on how to address tasks and their flags is decided } diff --git a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java index c57973a46..f828e5999 100644 --- a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java @@ -47,15 +47,15 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { final String featureUsage = "(featureUsage=" + featureTracker.getSerializedFeatureUsage() + ")"; final String javaVersion = System.getProperty("java.version"); final String androidVersion = getAndroidAPILevel(); - final String sdkversion_value = "graph-" + CoreConstants.Headers.JavaVersionPrefix + graphEndpoint + + final String sdkversion_value = "graph-" + CoreConstants.Headers.JAVA_VERSION_PREFIX + graphEndpoint + (mGraphClientOptions.getClientLibraryVersion() == null ? "" : "/"+ mGraphClientOptions.getClientLibraryVersion()) + ", " + - CoreConstants.Headers.GraphVersionPrefix + "/" + mGraphClientOptions.getCoreLibraryVersion() + " " + featureUsage + - (CoreConstants.Headers.DefaultVersionValue.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JavaVersionPrefix + "/" + javaVersion)) + - (CoreConstants.Headers.DefaultVersionValue.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.AndroidVersionPrefix + "/" + androidVersion)); - telemetryAddedBuilder.addHeader(CoreConstants.Headers.SdkVersionHeaderName, sdkversion_value); + CoreConstants.Headers.GRAPH_VERSION_PREFIX + "/" + mGraphClientOptions.getCoreLibraryVersion() + " " + featureUsage + + (CoreConstants.Headers.DEFAULT_VERSION_VALUE.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JAVA_VERSION_PREFIX + "/" + javaVersion)) + + (CoreConstants.Headers.DEFAULT_VERSION_VALUE.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.ANDROID_VERSION_PREFIX + "/" + androidVersion)); + telemetryAddedBuilder.addHeader(CoreConstants.Headers.SDK_VERSION_HEADER_NAME, sdkversion_value); - if(request.header(CoreConstants.Headers.ClientRequestId) == null) { - telemetryAddedBuilder.addHeader(CoreConstants.Headers.ClientRequestId, mGraphClientOptions.getClientRequestId()); + if(request.header(CoreConstants.Headers.CLIENT_REQUEST_ID) == null) { + telemetryAddedBuilder.addHeader(CoreConstants.Headers.CLIENT_REQUEST_ID, mGraphClientOptions.getClientRequestId()); } return chain.proceed(telemetryAddedBuilder.build()); @@ -80,16 +80,16 @@ private String getAndroidAPILevelInternal() { } } if(versionClass == null) - return CoreConstants.Headers.DefaultVersionValue; + return CoreConstants.Headers.DEFAULT_VERSION_VALUE; else { final Field sdkVersionField = versionClass.getField("SDK_INT"); final Object value = sdkVersionField.get(null); final String valueStr = String.valueOf(value); - return valueStr == null || valueStr.equals("") ? CoreConstants.Headers.DefaultVersionValue : valueStr; + return valueStr == null || valueStr.equals("") ? CoreConstants.Headers.DEFAULT_VERSION_VALUE : valueStr; } } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException ex) { // we're not on android and return "0" to align with java version which returns "0" when running on android - return CoreConstants.Headers.DefaultVersionValue; + return CoreConstants.Headers.DEFAULT_VERSION_VALUE; } } } diff --git a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java index 7c0abfda2..32ef80cc8 100644 --- a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java +++ b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java @@ -1,14 +1,13 @@ package com.microsoft.graph.httpcore; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; + import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.OkHttpClient.Builder; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.Objects; /** @@ -61,7 +60,6 @@ public static OkHttpClient createDefault(@Nonnull final IAuthenticationProvider public static OkHttpClient createFromInterceptors(@Nullable final Interceptor[] interceptors) { //TelemetryInterceptor must be included in interceptors list as it is not default in custom() OkHttpClient.Builder builder = custom(); - System.out.println(builder.interceptors().toString()); if(interceptors != null) for(Interceptor interceptor : interceptors) { if(interceptor != null) diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java index 415153e0f..cd71e8505 100644 --- a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java +++ b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java @@ -29,7 +29,7 @@ public void setCoreLibraryVersion(@Nonnull final String version){ * @return core library version. */ public String getCoreLibraryVersion() { - return this.coreLibraryVersion == null ? CoreConstants.Headers.Version : this.coreLibraryVersion; + return this.coreLibraryVersion == null ? CoreConstants.Headers.VERSION : this.coreLibraryVersion; } /** * Sets a string representation of the client library diff --git a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java index e63dc9209..fc3d3a7f3 100644 --- a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java +++ b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java @@ -11,12 +11,10 @@ import javax.annotation.Nullable; import javax.annotation.Nonnull; -import com.microsoft.graph.CoreConstants; import com.microsoft.graph.core.ClientException; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.httpcore.FeatureFlag; import com.microsoft.graph.options.Option; /** @@ -78,7 +76,8 @@ protected LargeFileUploadRequest(@Nonnull final String requestUrl, beginIndex, beginIndex + chunkSize - 1, totalLength)); - //this.baseRequest.addHeader(CoreConstants.Headers.FeatureFlag, FeatureFlag.FILE_UPLOAD_FLAG); + //TODO: decide if we want this implementation: this.baseRequest.addHeader(CoreConstants.Headers.FeatureFlag, FeatureFlag.FILE_UPLOAD_FLAG); + //Decide how to best handle this implementation ^. } /** diff --git a/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java b/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java index 48f6f7d98..c52c56973 100644 --- a/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java +++ b/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java @@ -77,7 +77,7 @@ public void providerAddsTokenToCustomHosts() throws MalformedURLException { //Assert assertTrue(result); - assertEquals(authProvider.getCustomHosts().length, 1); - assertEquals(authProvider.getCustomHosts()[0], "localhost.com"); + assertEquals(1, authProvider.getCustomHosts().length); + assertEquals( "localhost.com", authProvider.getCustomHosts()[0]); } } diff --git a/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java index 1a4feac39..2d18b74d8 100644 --- a/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java @@ -12,7 +12,6 @@ import com.microsoft.graph.CoreConstants; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; import org.junit.jupiter.api.Test; import okhttp3.Interceptor; @@ -29,17 +28,17 @@ public void telemetryInitTest() { @Test public void interceptTest() throws IOException { - final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" - + CoreConstants.Headers.Version; + final String expectedHeader = CoreConstants.Headers.GRAPH_VERSION_PREFIX +"/" + + CoreConstants.Headers.VERSION; final IAuthenticationProvider authProvider = mock(IAuthenticationProvider.class); when(authProvider.getAuthorizationTokenAsync(any(URL.class))).thenReturn(CompletableFuture.completedFuture("")); final OkHttpClient client = HttpClients.createDefault(authProvider); final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); - assertTrue(!response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(CoreConstants.Headers.AndroidVersionPrefix)); // Android version is not going to be present on unit tests runnning on java platform - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(CoreConstants.Headers.JavaVersionPrefix)); + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedHeader)); + assertTrue(!response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(CoreConstants.Headers.ANDROID_VERSION_PREFIX)); // Android version is not going to be present on unit tests runnning on java platform + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(CoreConstants.Headers.JAVA_VERSION_PREFIX)); } @Test @@ -49,41 +48,26 @@ public void arrayInterceptorsTest() throws IOException { final AuthenticationHandler authenticationHandler = new AuthenticationHandler(authProvider); final Interceptor[] interceptors = {new GraphTelemetryHandler(), new RetryHandler(), new RedirectHandler(), authenticationHandler}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" - + CoreConstants.Headers.Version; + final String expectedHeader = CoreConstants.Headers.GRAPH_VERSION_PREFIX +"/" + + CoreConstants.Headers.VERSION; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - System.out.println(response.request().header(CoreConstants.Headers.SdkVersionHeaderName)); + System.out.println(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME)); System.out.println(expectedHeader); - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedHeader)); } - @Test - public void arrayInterceptorsTest2() throws IOException{ - Request request = new Request.Builder().url("https://graph.microsoft.com/beta/users/").build(); - GraphClientOptions graphClientOptions = new GraphClientOptions(); - graphClientOptions.setClientLibraryVersion("5.9.0"); - graphClientOptions.setCoreLibraryVersion("2.9.0"); - - final Interceptor[] interceptors = {new GraphTelemetryHandler(graphClientOptions), new RetryHandler(), new RedirectHandler()}; - OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - Response response = client.newCall(request).execute(); - System.out.println(response.request().headers().toString()); - - } - - @Test public void arrayInterceptorEmptyTest() throws IOException { final Interceptor[] interceptors = new Interceptor[] {new GraphTelemetryHandler()}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" - + CoreConstants.Headers.Version; + final String expectedHeader = CoreConstants.Headers.GRAPH_VERSION_PREFIX +"/" + + CoreConstants.Headers.VERSION; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedHeader)); } } From 8b5e6f8d7e2e0b929a9ef86af3f3d5cbeaca8168 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Mon, 25 Apr 2022 16:45:31 -0700 Subject: [PATCH 007/561] Constants-classes compliance changes --- src/main/java/com/microsoft/graph/CoreConstants.java | 3 ++- src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java index b0db76106..e8b4949c3 100644 --- a/src/main/java/com/microsoft/graph/CoreConstants.java +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -1,6 +1,6 @@ package com.microsoft.graph; -public class CoreConstants { +public final class CoreConstants { private static class VersionValues { private static final int Major = 3; @@ -9,6 +9,7 @@ private static class VersionValues { } public static class Headers { + private Headers(){} public static final String BEARER = "Bearer"; public static final String SDK_VERSION_HEADER_NAME = "SdkVersion"; public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java index 185615c0f..c126b2360 100644 --- a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java @@ -1,6 +1,7 @@ package com.microsoft.graph.httpcore; public class FeatureFlag { + private FeatureFlag(){} public static final int NONE_FLAG = 0; public static final int REDIRECT_HANDLER_FLAG = 1; public static final int RETRY_HANDLER_FLAG = 2; From a97399b802a6fbea0899381e25b8a4dbcd7c1cfd Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Mon, 25 Apr 2022 16:46:45 -0700 Subject: [PATCH 008/561] Constants-classes compliance changes --- src/main/java/com/microsoft/graph/CoreConstants.java | 1 + src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java index e8b4949c3..8f2d8e33c 100644 --- a/src/main/java/com/microsoft/graph/CoreConstants.java +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -1,6 +1,7 @@ package com.microsoft.graph; public final class CoreConstants { + private CoreConstants(){} private static class VersionValues { private static final int Major = 3; diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java index c126b2360..23c5ced87 100644 --- a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java @@ -1,6 +1,6 @@ package com.microsoft.graph.httpcore; -public class FeatureFlag { +public final class FeatureFlag { private FeatureFlag(){} public static final int NONE_FLAG = 0; public static final int REDIRECT_HANDLER_FLAG = 1; From 52d1eb3a777ebdb2cba2f912ddd5298f56e37896 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Mon, 25 Apr 2022 16:32:28 -0700 Subject: [PATCH 009/561] Code-lint compliance changes Code-Lint compliance changes Constants-classes compliance changes --- .../com/microsoft/graph/CoreConstants.java | 22 +++++----- .../microsoft/graph/httpcore/FeatureFlag.java | 8 +--- .../graph/httpcore/FeatureTracker.java | 2 + .../graph/httpcore/GraphTelemetryHandler.java | 20 +++++----- .../microsoft/graph/httpcore/HttpClients.java | 4 +- .../middlewareoption/GraphClientOptions.java | 2 +- .../graph/tasks/LargeFileUploadRequest.java | 5 +-- .../BaseAuthenticationProviderTest.java | 4 +- .../httpcore/GraphTelemetryHandlerTest.java | 40 ++++++------------- 9 files changed, 44 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java index 6be703562..8f2d8e33c 100644 --- a/src/main/java/com/microsoft/graph/CoreConstants.java +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -1,6 +1,7 @@ package com.microsoft.graph; -public class CoreConstants { +public final class CoreConstants { + private CoreConstants(){} private static class VersionValues { private static final int Major = 3; @@ -9,15 +10,16 @@ private static class VersionValues { } public static class Headers { - public static final String Bearer = "Bearer"; - public static final String SdkVersionHeaderName = "SdkVersion"; - public static final String GraphVersionPrefix = "graph-java-core"; - public static final String AndroidVersionPrefix = "android"; - public static final String JavaVersionPrefix = "java"; - public static final String Version = String.format("%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); - public static final String ClientRequestId = "client-request-id"; - public static final String FeatureFlag = "FeatureFlag"; - public static final String DefaultVersionValue = "0"; + private Headers(){} + public static final String BEARER = "Bearer"; + public static final String SDK_VERSION_HEADER_NAME = "SdkVersion"; + public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; + public static final String ANDROID_VERSION_PREFIX = "android"; + public static final String JAVA_VERSION_PREFIX = "java"; + public static final String VERSION = String.format("%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); + public static final String CLIENT_REQUEST_ID = "client-request-id"; + public static final String FEATURE_FLAG = "FeatureFlag"; + public static final String DEFAULT_VERSION_VALUE = "0"; /**The following appear in dotnet core, are they necessary in Java? * Content-Type header: diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java index 8163767c5..23c5ced87 100644 --- a/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureFlag.java @@ -1,6 +1,7 @@ package com.microsoft.graph.httpcore; -public class FeatureFlag { +public final class FeatureFlag { + private FeatureFlag(){} public static final int NONE_FLAG = 0; public static final int REDIRECT_HANDLER_FLAG = 1; public static final int RETRY_HANDLER_FLAG = 2; @@ -14,9 +15,4 @@ public class FeatureFlag { public static final int BATCH_REQUEST_FLAG = 512; public static final int PAGE_ITERATOR_FLAG = 1024; public static final int FILE_UPLOAD_FLAG = 2048; - - public static String addFeatureToHeader(FeatureFlag flag){ - return "This should be the header to add after calculating the change"; - } - } diff --git a/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java b/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java index 5c5888763..be8e316a4 100644 --- a/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java +++ b/src/main/java/com/microsoft/graph/httpcore/FeatureTracker.java @@ -28,4 +28,6 @@ public int getFeatureUsage() { public String getSerializedFeatureUsage() { return Integer.toHexString(featureUsage); } + + // TODO: add a method to add a feature flag to the header, do this once implementation on how to address tasks and their flags is decided } diff --git a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java index c57973a46..f828e5999 100644 --- a/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/GraphTelemetryHandler.java @@ -47,15 +47,15 @@ public Response intercept(@Nonnull final Chain chain) throws IOException { final String featureUsage = "(featureUsage=" + featureTracker.getSerializedFeatureUsage() + ")"; final String javaVersion = System.getProperty("java.version"); final String androidVersion = getAndroidAPILevel(); - final String sdkversion_value = "graph-" + CoreConstants.Headers.JavaVersionPrefix + graphEndpoint + + final String sdkversion_value = "graph-" + CoreConstants.Headers.JAVA_VERSION_PREFIX + graphEndpoint + (mGraphClientOptions.getClientLibraryVersion() == null ? "" : "/"+ mGraphClientOptions.getClientLibraryVersion()) + ", " + - CoreConstants.Headers.GraphVersionPrefix + "/" + mGraphClientOptions.getCoreLibraryVersion() + " " + featureUsage + - (CoreConstants.Headers.DefaultVersionValue.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JavaVersionPrefix + "/" + javaVersion)) + - (CoreConstants.Headers.DefaultVersionValue.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.AndroidVersionPrefix + "/" + androidVersion)); - telemetryAddedBuilder.addHeader(CoreConstants.Headers.SdkVersionHeaderName, sdkversion_value); + CoreConstants.Headers.GRAPH_VERSION_PREFIX + "/" + mGraphClientOptions.getCoreLibraryVersion() + " " + featureUsage + + (CoreConstants.Headers.DEFAULT_VERSION_VALUE.equals(javaVersion) ? "" : (", " + CoreConstants.Headers.JAVA_VERSION_PREFIX + "/" + javaVersion)) + + (CoreConstants.Headers.DEFAULT_VERSION_VALUE.equals(androidVersion) ? "" : (", " + CoreConstants.Headers.ANDROID_VERSION_PREFIX + "/" + androidVersion)); + telemetryAddedBuilder.addHeader(CoreConstants.Headers.SDK_VERSION_HEADER_NAME, sdkversion_value); - if(request.header(CoreConstants.Headers.ClientRequestId) == null) { - telemetryAddedBuilder.addHeader(CoreConstants.Headers.ClientRequestId, mGraphClientOptions.getClientRequestId()); + if(request.header(CoreConstants.Headers.CLIENT_REQUEST_ID) == null) { + telemetryAddedBuilder.addHeader(CoreConstants.Headers.CLIENT_REQUEST_ID, mGraphClientOptions.getClientRequestId()); } return chain.proceed(telemetryAddedBuilder.build()); @@ -80,16 +80,16 @@ private String getAndroidAPILevelInternal() { } } if(versionClass == null) - return CoreConstants.Headers.DefaultVersionValue; + return CoreConstants.Headers.DEFAULT_VERSION_VALUE; else { final Field sdkVersionField = versionClass.getField("SDK_INT"); final Object value = sdkVersionField.get(null); final String valueStr = String.valueOf(value); - return valueStr == null || valueStr.equals("") ? CoreConstants.Headers.DefaultVersionValue : valueStr; + return valueStr == null || valueStr.equals("") ? CoreConstants.Headers.DEFAULT_VERSION_VALUE : valueStr; } } catch (IllegalAccessException | ClassNotFoundException | NoSuchFieldException ex) { // we're not on android and return "0" to align with java version which returns "0" when running on android - return CoreConstants.Headers.DefaultVersionValue; + return CoreConstants.Headers.DEFAULT_VERSION_VALUE; } } } diff --git a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java index 7c0abfda2..32ef80cc8 100644 --- a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java +++ b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java @@ -1,14 +1,13 @@ package com.microsoft.graph.httpcore; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; + import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.OkHttpClient.Builder; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.Objects; /** @@ -61,7 +60,6 @@ public static OkHttpClient createDefault(@Nonnull final IAuthenticationProvider public static OkHttpClient createFromInterceptors(@Nullable final Interceptor[] interceptors) { //TelemetryInterceptor must be included in interceptors list as it is not default in custom() OkHttpClient.Builder builder = custom(); - System.out.println(builder.interceptors().toString()); if(interceptors != null) for(Interceptor interceptor : interceptors) { if(interceptor != null) diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java index 415153e0f..cd71e8505 100644 --- a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java +++ b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/GraphClientOptions.java @@ -29,7 +29,7 @@ public void setCoreLibraryVersion(@Nonnull final String version){ * @return core library version. */ public String getCoreLibraryVersion() { - return this.coreLibraryVersion == null ? CoreConstants.Headers.Version : this.coreLibraryVersion; + return this.coreLibraryVersion == null ? CoreConstants.Headers.VERSION : this.coreLibraryVersion; } /** * Sets a string representation of the client library diff --git a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java index e63dc9209..fc3d3a7f3 100644 --- a/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java +++ b/src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java @@ -11,12 +11,10 @@ import javax.annotation.Nullable; import javax.annotation.Nonnull; -import com.microsoft.graph.CoreConstants; import com.microsoft.graph.core.ClientException; import com.microsoft.graph.http.BaseRequest; import com.microsoft.graph.http.HttpMethod; import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.httpcore.FeatureFlag; import com.microsoft.graph.options.Option; /** @@ -78,7 +76,8 @@ protected LargeFileUploadRequest(@Nonnull final String requestUrl, beginIndex, beginIndex + chunkSize - 1, totalLength)); - //this.baseRequest.addHeader(CoreConstants.Headers.FeatureFlag, FeatureFlag.FILE_UPLOAD_FLAG); + //TODO: decide if we want this implementation: this.baseRequest.addHeader(CoreConstants.Headers.FeatureFlag, FeatureFlag.FILE_UPLOAD_FLAG); + //Decide how to best handle this implementation ^. } /** diff --git a/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java b/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java index 48f6f7d98..c52c56973 100644 --- a/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java +++ b/src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java @@ -77,7 +77,7 @@ public void providerAddsTokenToCustomHosts() throws MalformedURLException { //Assert assertTrue(result); - assertEquals(authProvider.getCustomHosts().length, 1); - assertEquals(authProvider.getCustomHosts()[0], "localhost.com"); + assertEquals(1, authProvider.getCustomHosts().length); + assertEquals( "localhost.com", authProvider.getCustomHosts()[0]); } } diff --git a/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java index 1a4feac39..2d18b74d8 100644 --- a/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/GraphTelemetryHandlerTest.java @@ -12,7 +12,6 @@ import com.microsoft.graph.CoreConstants; import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.httpcore.middlewareoption.GraphClientOptions; import org.junit.jupiter.api.Test; import okhttp3.Interceptor; @@ -29,17 +28,17 @@ public void telemetryInitTest() { @Test public void interceptTest() throws IOException { - final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" - + CoreConstants.Headers.Version; + final String expectedHeader = CoreConstants.Headers.GRAPH_VERSION_PREFIX +"/" + + CoreConstants.Headers.VERSION; final IAuthenticationProvider authProvider = mock(IAuthenticationProvider.class); when(authProvider.getAuthorizationTokenAsync(any(URL.class))).thenReturn(CompletableFuture.completedFuture("")); final OkHttpClient client = HttpClients.createDefault(authProvider); final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); - assertTrue(!response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(CoreConstants.Headers.AndroidVersionPrefix)); // Android version is not going to be present on unit tests runnning on java platform - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(CoreConstants.Headers.JavaVersionPrefix)); + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedHeader)); + assertTrue(!response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(CoreConstants.Headers.ANDROID_VERSION_PREFIX)); // Android version is not going to be present on unit tests runnning on java platform + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(CoreConstants.Headers.JAVA_VERSION_PREFIX)); } @Test @@ -49,41 +48,26 @@ public void arrayInterceptorsTest() throws IOException { final AuthenticationHandler authenticationHandler = new AuthenticationHandler(authProvider); final Interceptor[] interceptors = {new GraphTelemetryHandler(), new RetryHandler(), new RedirectHandler(), authenticationHandler}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" - + CoreConstants.Headers.Version; + final String expectedHeader = CoreConstants.Headers.GRAPH_VERSION_PREFIX +"/" + + CoreConstants.Headers.VERSION; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - System.out.println(response.request().header(CoreConstants.Headers.SdkVersionHeaderName)); + System.out.println(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME)); System.out.println(expectedHeader); - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedHeader)); } - @Test - public void arrayInterceptorsTest2() throws IOException{ - Request request = new Request.Builder().url("https://graph.microsoft.com/beta/users/").build(); - GraphClientOptions graphClientOptions = new GraphClientOptions(); - graphClientOptions.setClientLibraryVersion("5.9.0"); - graphClientOptions.setCoreLibraryVersion("2.9.0"); - - final Interceptor[] interceptors = {new GraphTelemetryHandler(graphClientOptions), new RetryHandler(), new RedirectHandler()}; - OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - Response response = client.newCall(request).execute(); - System.out.println(response.request().headers().toString()); - - } - - @Test public void arrayInterceptorEmptyTest() throws IOException { final Interceptor[] interceptors = new Interceptor[] {new GraphTelemetryHandler()}; final OkHttpClient client = HttpClients.createFromInterceptors(interceptors); - final String expectedHeader = CoreConstants.Headers.GraphVersionPrefix +"/" - + CoreConstants.Headers.Version; + final String expectedHeader = CoreConstants.Headers.GRAPH_VERSION_PREFIX +"/" + + CoreConstants.Headers.VERSION; final Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build(); final Response response = client.newCall(request).execute(); assertNotNull(response); - assertTrue(response.request().header(CoreConstants.Headers.SdkVersionHeaderName).contains(expectedHeader)); + assertTrue(response.request().header(CoreConstants.Headers.SDK_VERSION_HEADER_NAME).contains(expectedHeader)); } } From 6dacea3c7429e57732e56dc2f844221471895734 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Mon, 25 Apr 2022 16:58:12 -0700 Subject: [PATCH 010/561] Code-Lint compliance changes --- src/main/java/com/microsoft/graph/CoreConstants.java | 8 ++++---- .../microsoft/graph/httpcore/FeatureTrackerTest.java | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/microsoft/graph/CoreConstants.java b/src/main/java/com/microsoft/graph/CoreConstants.java index 8f2d8e33c..3fbd42e4d 100644 --- a/src/main/java/com/microsoft/graph/CoreConstants.java +++ b/src/main/java/com/microsoft/graph/CoreConstants.java @@ -4,9 +4,9 @@ public final class CoreConstants { private CoreConstants(){} private static class VersionValues { - private static final int Major = 3; - private static final int Minor = 0; - private static final int Patch = 0; + private static final int MAJOR = 3; + private static final int MINOR = 0; + private static final int PATCH = 0; } public static class Headers { @@ -16,7 +16,7 @@ private Headers(){} public static final String GRAPH_VERSION_PREFIX = "graph-java-core"; public static final String ANDROID_VERSION_PREFIX = "android"; public static final String JAVA_VERSION_PREFIX = "java"; - public static final String VERSION = String.format("%d.%d.%d", VersionValues.Major, VersionValues.Minor, VersionValues.Patch); + public static final String VERSION = String.format("%d.%d.%d", VersionValues.MAJOR, VersionValues.MINOR, VersionValues.PATCH); public static final String CLIENT_REQUEST_ID = "client-request-id"; public static final String FEATURE_FLAG = "FeatureFlag"; public static final String DEFAULT_VERSION_VALUE = "0"; diff --git a/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java b/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java index f1b455244..8240ecd6d 100644 --- a/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java +++ b/src/test/java/com/microsoft/graph/httpcore/FeatureTrackerTest.java @@ -2,23 +2,23 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class FeatureTrackerTest { +class FeatureTrackerTest { @Test - public void setFeatureUsageTest() { + void setFeatureUsageTest() { FeatureTracker featureTracker = new FeatureTracker(); featureTracker.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); featureTracker.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); - assertTrue(featureTracker.getSerializedFeatureUsage().compareTo("5")==0); + assertEquals("5", featureTracker.getSerializedFeatureUsage()); } @Test - public void getSerializedFeatureUsageTest() { + void getSerializedFeatureUsageTest() { FeatureTracker featureTracker = new FeatureTracker(); featureTracker.setFeatureUsage(FeatureFlag.AUTH_HANDLER_FLAG); featureTracker.setFeatureUsage(FeatureFlag.REDIRECT_HANDLER_FLAG); featureTracker.setFeatureUsage(FeatureFlag.RETRY_HANDLER_FLAG); - assertTrue(featureTracker.getSerializedFeatureUsage().compareTo("7")==0); + assertEquals("7", featureTracker.getSerializedFeatureUsage()); } } From 726b7f66a8f980bcd4dd51c439d5e01d6616cb42 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 8 Jun 2022 17:05:04 -0700 Subject: [PATCH 011/561] BaseGraphRequestAdapter --- .../Requests/BaseGraphRequestAdapter.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java new file mode 100644 index 000000000..24a13ea8c --- /dev/null +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -0,0 +1,21 @@ +package com.microsoft.graph.Requests; + +import com.microsoft.kiota.authentication.AuthenticationProvider; +import com.microsoft.kiota.http.OkHttpRequestAdapter; +import com.microsoft.kiota.serialization.ParseNodeFactory; +import com.microsoft.kiota.serialization.SerializationWriterFactory; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import okhttp3.OkHttpClient; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +@SuppressFBWarnings +public class BaseGraphRequestAdapter extends OkHttpRequestAdapter { + + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { + super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); + } + + +} From e05c6364c48ac1a931ee95ff8d8304a47c918882 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 8 Jun 2022 17:05:50 -0700 Subject: [PATCH 012/561] BaseGraphRequestAdapter --- .../com/microsoft/graph/Requests/BaseGraphRequestAdapter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java index 24a13ea8c..821fb6c00 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -16,6 +16,4 @@ public class BaseGraphRequestAdapter extends OkHttpRequestAdapter { public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); } - - } From 1765be960dd84ddd9d9be097ec746efaab319e82 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Fri, 10 Jun 2022 10:40:51 -0700 Subject: [PATCH 013/561] Kiota-Core IBaseClient & BaseClient --- .../microsoft/graph/Requests/BaseClient.java | 49 +++++++++++++++++++ .../microsoft/graph/Requests/IBaseClient.java | 15 ++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/java/com/microsoft/graph/Requests/BaseClient.java create mode 100644 src/main/java/com/microsoft/graph/Requests/IBaseClient.java diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java new file mode 100644 index 000000000..c19041c98 --- /dev/null +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -0,0 +1,49 @@ +package com.microsoft.graph.Requests; + +import com.microsoft.graph.content.BatchRequestBuilder; +import com.microsoft.kiota.RequestAdapter; +import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; +import com.microsoft.kiota.authentication.AuthenticationProvider; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import okhttp3.OkHttpClient; + +import javax.annotation.Nonnull; + +@SuppressFBWarnings +class BaseClient implements IBaseClient{ + + private RequestAdapter requestAdapter; + public BatchRequestBuilder batchRequestBuilder; + + BaseClient(@Nonnull RequestAdapter requestAdapter) { + this.requestAdapter = requestAdapter; + } + + BaseClient(@Nonnull String baseUrl, @Nonnull AuthenticationProvider authenticationProvider) { + this.requestAdapter = new BaseGraphRequestAdapter(authenticationProvider, null, null, null, null); + this.requestAdapter.setBaseUrl(baseUrl); + } + + BaseClient(@Nonnull String baseUrl, @Nonnull OkHttpClient client) { + this.requestAdapter = new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider(), null, null, client, null); + this.requestAdapter.setBaseUrl(baseUrl); + } + + @Override + public void setRequestAdapter(RequestAdapter requestAdapter) { + this.requestAdapter = requestAdapter; + } + + @Override + public RequestAdapter getRequestAdapter() { + return this.requestAdapter; + } + + @Override + public BatchRequestBuilder getBatchRequestBuilder() { + //TODO: Refactor BatchRequestBuilder so that it accepts a request adapter as the param + //return this.batchRequestBuilder != null ? this.batchRequestBuilder : new BatchRequestBuilder(this.requestAdapter) + return this.batchRequestBuilder; + } + +} diff --git a/src/main/java/com/microsoft/graph/Requests/IBaseClient.java b/src/main/java/com/microsoft/graph/Requests/IBaseClient.java new file mode 100644 index 000000000..358b006b7 --- /dev/null +++ b/src/main/java/com/microsoft/graph/Requests/IBaseClient.java @@ -0,0 +1,15 @@ +package com.microsoft.graph.Requests; + +import com.microsoft.graph.content.BatchRequestBuilder; +import com.microsoft.kiota.RequestAdapter; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +@SuppressFBWarnings +public interface IBaseClient { + + public void setRequestAdapter(RequestAdapter requestAdapter); + + public RequestAdapter getRequestAdapter(); + + public BatchRequestBuilder getBatchRequestBuilder(); +} From 215dcae217e97071c3a6bca1f7047efbc7cc36ff Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 15 Jun 2022 16:52:11 -0700 Subject: [PATCH 014/561] adding GraphClientFactory --- .../graph/Requests/GraphClientFactory.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java diff --git a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java new file mode 100644 index 000000000..fea0f7ee8 --- /dev/null +++ b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java @@ -0,0 +1,75 @@ +package com.microsoft.graph.Requests; + +import com.microsoft.graph.httpcore.CompressionHandler; +import com.microsoft.graph.httpcore.GraphTelemetryHandler; +import com.microsoft.kiota.RequestInformation; +import com.microsoft.kiota.http.KiotaClientFactory; +import edu.umd.cs.findbugs.annotations.Nullable; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; + +import java.net.URI; +import java.net.URISyntaxException; +import java.text.Format; +import java.time.temporal.ChronoUnit; +import java.util.*; + +@SuppressFBWarnings +public class GraphClientFactory { + private GraphClientFactory() { } + + //private static final ChronoUnit defaultTimeout = new ChroUn + + private static final HashMap cloudList = new HashMap() {{ + put( "Global_Cloud" , "https://graph.microsoft.com" ); + put( "USGOV_Cloud", "https://graph.microsoft.us"); + put( "China_Cloud", "https://microsoftgraph.chinacloudapi.cn"); + put( "Germany_Cloud", "https://graph.microsoft.de"); + put( "USGOV_DOD_Cloud", "https://dod-graph.microsoft.us"); + }}; + + public final String Global_Cloud = "Global"; + public final String USGOV_Cloud = "US_GOV"; + public final String USGOV_DOD_Cloud = "US_GOV_DOD"; + public final String China_Cloud = "China"; + public final String Germany_Cloud = "Germany"; + + public static OkHttpClient.Builder create() { + return create((GraphClientOptions) null); + } + + public static OkHttpClient.Builder create(Interceptor[] interceptors, @Nullable GraphClientOptions graphClientOptions) { + OkHttpClient.Builder builder = create((GraphClientOptions) null); + for(Interceptor interceptor : interceptors) { + builder.addInterceptor(interceptor); + } + return builder; + } + + public static OkHttpClient.Builder create(@Nullable GraphClientOptions options) { + OkHttpClient.Builder builder = KiotaClientFactory.Create(createDefaultGraphInterceptors(options)); + return builder; + } + + public static Interceptor[] createDefaultGraphInterceptors(@Nullable GraphClientOptions graphClientOptions) { + List handlers = new ArrayList<>(); + handlers.add(new GraphTelemetryHandler(graphClientOptions)); + handlers.add(new CompressionHandler()); + for(final Interceptor interceptor: KiotaClientFactory.CreateDefaultInterceptors()) { + handlers.add(interceptor); + } + return (Interceptor[]) handlers.toArray(); + } + + + //Cant set base address on client in OKhttp, Keeping this in case we need it but I don't believe this will belong here. + private static URI determineBaseAddress(String nationalCloud, String version) throws URISyntaxException, IllegalArgumentException { + String cloud = cloudList.get(nationalCloud); + if(cloud == null){ + throw new IllegalArgumentException(String.format("%s is an unexpected national cloud.", nationalCloud)); + } + return new URI(String.format("%s/%s/",nationalCloud,version)); + } + +} From e03c48bef13e325371231d080f6b62d71eadb594 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Tue, 21 Jun 2022 16:29:26 -0700 Subject: [PATCH 015/561] BaseClient, BaseGraphRequestAdapter, GraphClientFactory updates --- .../microsoft/graph/Requests/BaseClient.java | 12 +++--- .../Requests/BaseGraphRequestAdapter.java | 39 ++++++++++++++++++- .../graph/Requests/GraphClientFactory.java | 27 ------------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java index c19041c98..7bb41813b 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -8,6 +8,8 @@ import okhttp3.OkHttpClient; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.net.URISyntaxException; @SuppressFBWarnings class BaseClient implements IBaseClient{ @@ -19,14 +21,12 @@ class BaseClient implements IBaseClient{ this.requestAdapter = requestAdapter; } - BaseClient(@Nonnull String baseUrl, @Nonnull AuthenticationProvider authenticationProvider) { - this.requestAdapter = new BaseGraphRequestAdapter(authenticationProvider, null, null, null, null); - this.requestAdapter.setBaseUrl(baseUrl); + BaseClient(@Nullable String baseUrl, @Nonnull AuthenticationProvider authenticationProvider) { + this.requestAdapter = new BaseGraphRequestAdapter(authenticationProvider, null, null, null, null, baseUrl); } - BaseClient(@Nonnull String baseUrl, @Nonnull OkHttpClient client) { - this.requestAdapter = new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider(), null, null, client, null); - this.requestAdapter.setBaseUrl(baseUrl); + BaseClient(@Nullable String baseUrl, @Nonnull OkHttpClient client) { + this.requestAdapter = new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider(), null, null, client, null, baseUrl); } @Override diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java index 821fb6c00..a83874395 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -9,11 +9,48 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; @SuppressFBWarnings public class BaseGraphRequestAdapter extends OkHttpRequestAdapter { - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { + enum Clouds { + GLOBAL_CLOUD, + USGOV_CLOUD, + CHINA_CLOUD, + GERMANY_CLOUD, + USGOV_DOD_CLOUD + } + + private static final HashMap cloudList = new HashMap() {{ + put( Clouds.GLOBAL_CLOUD, "https://graph.microsoft.com" ); + put( Clouds.USGOV_CLOUD, "https://graph.microsoft.us"); + put( Clouds.CHINA_CLOUD, "https://microsoftgraph.chinacloudapi.cn"); + put( Clouds.GERMANY_CLOUD, "https://graph.microsoft.de"); + put( Clouds.USGOV_DOD_CLOUD, "https://dod-graph.microsoft.us"); + }}; + + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable String baseUrl) { super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); + if (baseUrl == null) { + setBaseUrl(baseUrl); + } else { + setBaseUrl(determineBaseAddress(null, null)); + } + } + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable Clouds nationalCloud, @Nullable String version) { + this(authenticationProvider, parseNodeFactory, serializationWriterFactory, client, graphClientOptions, determineBaseAddress(nationalCloud, version)); } + + private static String determineBaseAddress(@Nullable Clouds nationalCloud, @Nullable String version) throws IllegalArgumentException { + String cloud = nationalCloud == null ? cloudList.get(Clouds.GLOBAL_CLOUD) : cloudList.get(nationalCloud); + if(cloud == null) { + throw new IllegalArgumentException(String.format("%s is an unexpected national cloud.", nationalCloud)); + } + String baseAddress = version == null ? String.format("%s/%s/",cloud,"v1.0") : String.format("%s/%s/",cloud,version); + return baseAddress; + } + } diff --git a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java index fea0f7ee8..3fb6b2a21 100644 --- a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java +++ b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java @@ -19,22 +19,6 @@ public class GraphClientFactory { private GraphClientFactory() { } - //private static final ChronoUnit defaultTimeout = new ChroUn - - private static final HashMap cloudList = new HashMap() {{ - put( "Global_Cloud" , "https://graph.microsoft.com" ); - put( "USGOV_Cloud", "https://graph.microsoft.us"); - put( "China_Cloud", "https://microsoftgraph.chinacloudapi.cn"); - put( "Germany_Cloud", "https://graph.microsoft.de"); - put( "USGOV_DOD_Cloud", "https://dod-graph.microsoft.us"); - }}; - - public final String Global_Cloud = "Global"; - public final String USGOV_Cloud = "US_GOV"; - public final String USGOV_DOD_Cloud = "US_GOV_DOD"; - public final String China_Cloud = "China"; - public final String Germany_Cloud = "Germany"; - public static OkHttpClient.Builder create() { return create((GraphClientOptions) null); } @@ -61,15 +45,4 @@ public static Interceptor[] createDefaultGraphInterceptors(@Nullable GraphClient } return (Interceptor[]) handlers.toArray(); } - - - //Cant set base address on client in OKhttp, Keeping this in case we need it but I don't believe this will belong here. - private static URI determineBaseAddress(String nationalCloud, String version) throws URISyntaxException, IllegalArgumentException { - String cloud = cloudList.get(nationalCloud); - if(cloud == null){ - throw new IllegalArgumentException(String.format("%s is an unexpected national cloud.", nationalCloud)); - } - return new URI(String.format("%s/%s/",nationalCloud,version)); - } - } From 069cb8e253c8a799ac3210f640d4e3a18f7a8f94 Mon Sep 17 00:00:00 2001 From: ramsessanchez <63934382+ramsessanchez@users.noreply.github.com> Date: Wed, 29 Jun 2022 13:45:59 -0700 Subject: [PATCH 016/561] Update src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java Co-authored-by: Vincent Biret --- .../com/microsoft/graph/Requests/BaseGraphRequestAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java index a83874395..010c03721 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -34,7 +34,7 @@ enum Clouds { public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable String baseUrl) { super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); - if (baseUrl == null) { + if (baseUrl != null && !baseUrl.isEmpty()) { setBaseUrl(baseUrl); } else { setBaseUrl(determineBaseAddress(null, null)); From ad3226db0e6e4c6785b0a4961cbcf1b6aee32c6f Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 29 Jun 2022 18:40:08 -0700 Subject: [PATCH 017/561] Add overloads to BaseGraphRequestAdapter Add overloads to BaseClient --- .../microsoft/graph/Requests/BaseClient.java | 24 ++++++++++++++--- .../Requests/BaseGraphRequestAdapter.java | 27 ++++++++++++++----- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java index 7bb41813b..a4b44757b 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -2,14 +2,12 @@ import com.microsoft.graph.content.BatchRequestBuilder; import com.microsoft.kiota.RequestAdapter; -import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.authentication.AuthenticationProvider; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import okhttp3.OkHttpClient; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.net.URISyntaxException; @SuppressFBWarnings class BaseClient implements IBaseClient{ @@ -21,12 +19,30 @@ class BaseClient implements IBaseClient{ this.requestAdapter = requestAdapter; } + /**BaseClient Constructors for use with baseUrl */ BaseClient(@Nullable String baseUrl, @Nonnull AuthenticationProvider authenticationProvider) { - this.requestAdapter = new BaseGraphRequestAdapter(authenticationProvider, null, null, null, null, baseUrl); + this(new BaseGraphRequestAdapter(authenticationProvider, baseUrl)); } BaseClient(@Nullable String baseUrl, @Nonnull OkHttpClient client) { - this.requestAdapter = new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider(), null, null, client, null, baseUrl); + this(baseUrl, client, null); + } + + BaseClient(@Nullable String baseUrl, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { + this(new BaseGraphRequestAdapter(client, graphClientOptions, baseUrl)); + } + + /**BaseClient constructors for use with specific national cloud and version */ + BaseClient(@Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version, @Nonnull AuthenticationProvider authenticationProvider){ + this(new BaseGraphRequestAdapter(authenticationProvider, nationalCloud, version)); + } + + BaseClient(@Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version, @Nonnull OkHttpClient client){ + this(nationalCloud, version, client, null); + } + + BaseClient(@Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { + this(new BaseGraphRequestAdapter(client, graphClientOptions, nationalCloud, version)); } @Override diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java index 010c03721..aea5199d8 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -1,5 +1,6 @@ package com.microsoft.graph.Requests; +import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.authentication.AuthenticationProvider; import com.microsoft.kiota.http.OkHttpRequestAdapter; import com.microsoft.kiota.serialization.ParseNodeFactory; @@ -9,14 +10,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.net.URI; -import java.net.URISyntaxException; + import java.util.HashMap; @SuppressFBWarnings public class BaseGraphRequestAdapter extends OkHttpRequestAdapter { - enum Clouds { + public enum Clouds { GLOBAL_CLOUD, USGOV_CLOUD, CHINA_CLOUD, @@ -32,7 +32,9 @@ enum Clouds { put( Clouds.USGOV_DOD_CLOUD, "https://dod-graph.microsoft.us"); }}; - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable String baseUrl) { + + /** Base Constructor */ + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable final GraphClientOptions graphClientOptions, @Nullable String baseUrl) { super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); if (baseUrl != null && !baseUrl.isEmpty()) { setBaseUrl(baseUrl); @@ -40,8 +42,21 @@ public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticat setBaseUrl(determineBaseAddress(null, null)); } } - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable Clouds nationalCloud, @Nullable String version) { - this(authenticationProvider, parseNodeFactory, serializationWriterFactory, client, graphClientOptions, determineBaseAddress(nationalCloud, version)); + + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { + this(authenticationProvider, null, null, null, null, baseUrl); + } + + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull Clouds nationalCloud, @Nonnull String version) { + this(authenticationProvider, determineBaseAddress(nationalCloud, version)); + } + + public BaseGraphRequestAdapter(@Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { + this(new AnonymousAuthenticationProvider(), null, null, client,graphClientOptions, baseUrl); + } + + public BaseGraphRequestAdapter(@Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull Clouds nationalCloud, @Nonnull String version) { + this(client,graphClientOptions, determineBaseAddress(nationalCloud, version)); } private static String determineBaseAddress(@Nullable Clouds nationalCloud, @Nullable String version) throws IllegalArgumentException { From d01363d872dfb04fa9beac0cc02fc50fd1af3d6a Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 29 Jun 2022 18:41:43 -0700 Subject: [PATCH 018/561] method chaining --- src/main/java/com/microsoft/graph/Requests/BaseClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java index a4b44757b..02f6f953a 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -16,7 +16,7 @@ class BaseClient implements IBaseClient{ public BatchRequestBuilder batchRequestBuilder; BaseClient(@Nonnull RequestAdapter requestAdapter) { - this.requestAdapter = requestAdapter; + setRequestAdapter(requestAdapter); } /**BaseClient Constructors for use with baseUrl */ From ef2b4bd9ef3b5e99766cb8bfbccf4be52e8f55e7 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 29 Jun 2022 18:55:46 -0700 Subject: [PATCH 019/561] Use snapshot dependencies. Update target jdk to 17 --- build.gradle | 15 ++++++++++++--- gradle/dependencies.gradle | 7 +++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index dc2e30692..3a2a69c26 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,15 @@ jacoco { toolVersion = "0.8.7" } +//Prevent javadocs from failing build +tasks.withType(Javadoc) { + failOnError false + options.addStringOption('Xdoclint:none', '-quiet') + options.addStringOption('encoding', 'UTF-8') + options.addStringOption('charSet', 'UTF-8') +} + + spotbugsMain { excludeFilter = file("spotBugsExcludeFilter.xml") reports { @@ -74,7 +83,7 @@ sourceSets { repositories { // You can declare any Maven/Ivy/file repository here. mavenCentral() - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } // for jacoco, until 0.8.7 gets released + maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }// for jacoco, until 0.8.7 gets released } apply from: "gradle/dependencies.gradle" @@ -212,8 +221,8 @@ def fixAscNames = { name -> } compileJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 + sourceCompatibility = '17' + targetCompatibility = '17' } def getVersionCode() { diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 0c89e350e..dab5e5c13 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -16,4 +16,11 @@ dependencies { compileOnly 'com.github.spotbugs:spotbugs-annotations:4.7.0' testCompileOnly 'net.jcip:jcip-annotations:1.0' testCompileOnly 'com.github.spotbugs:spotbugs-annotations:4.7.0' + + implementation 'com.microsoft.kiota:microsoft-kiota-abstractions:0.0.1-SNAPSHOT' + implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:0.0.1-SNAPSHOT' + implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:0.0.1-SNAPSHOT' + implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:0.0.1-SNAPSHOT' + implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:0.0.1-SNAPSHOT' + } \ No newline at end of file From d7425c8da624846f3b053425f607e0494c3664c2 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 29 Jun 2022 18:57:32 -0700 Subject: [PATCH 020/561] GraphClientFactory will not add CompressionHandler --- .../java/com/microsoft/graph/Requests/GraphClientFactory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java index 3fb6b2a21..4e20e04c8 100644 --- a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java +++ b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java @@ -39,7 +39,6 @@ public static OkHttpClient.Builder create(@Nullable GraphClientOptions options) public static Interceptor[] createDefaultGraphInterceptors(@Nullable GraphClientOptions graphClientOptions) { List handlers = new ArrayList<>(); handlers.add(new GraphTelemetryHandler(graphClientOptions)); - handlers.add(new CompressionHandler()); for(final Interceptor interceptor: KiotaClientFactory.CreateDefaultInterceptors()) { handlers.add(interceptor); } From d163ed04771d45b5a584504c0f81c32e5e9fb433 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Thu, 30 Jun 2022 15:06:25 -0700 Subject: [PATCH 021/561] Finalized BaseClient and BaseGraphRequestAdapter constructors --- .../microsoft/graph/Requests/BaseClient.java | 26 +++++++++---------- .../Requests/BaseGraphRequestAdapter.java | 19 ++++++++++---- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java index 02f6f953a..046cec264 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -19,30 +19,28 @@ class BaseClient implements IBaseClient{ setRequestAdapter(requestAdapter); } - /**BaseClient Constructors for use with baseUrl */ - BaseClient(@Nullable String baseUrl, @Nonnull AuthenticationProvider authenticationProvider) { - this(new BaseGraphRequestAdapter(authenticationProvider, baseUrl)); + BaseClient(@Nonnull AuthenticationProvider authenticationProvider) { + this(new BaseGraphRequestAdapter(authenticationProvider)); } - BaseClient(@Nullable String baseUrl, @Nonnull OkHttpClient client) { - this(baseUrl, client, null); + BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { + this(new BaseGraphRequestAdapter(authenticationProvider, baseUrl)); } - BaseClient(@Nullable String baseUrl, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { - this(new BaseGraphRequestAdapter(client, graphClientOptions, baseUrl)); + BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version){ + this(new BaseGraphRequestAdapter(authenticationProvider, nationalCloud, version)); } - /**BaseClient constructors for use with specific national cloud and version */ - BaseClient(@Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version, @Nonnull AuthenticationProvider authenticationProvider){ - this(new BaseGraphRequestAdapter(authenticationProvider, nationalCloud, version)); + BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { + this(new BaseGraphRequestAdapter(authenticationProvider,client, graphClientOptions)); } - BaseClient(@Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version, @Nonnull OkHttpClient client){ - this(nationalCloud, version, client, null); + BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { + this(new BaseGraphRequestAdapter(authenticationProvider, client, graphClientOptions, baseUrl)); } - BaseClient(@Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { - this(new BaseGraphRequestAdapter(client, graphClientOptions, nationalCloud, version)); + BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable BaseGraphRequestAdapter.Clouds nationalCloud, @Nullable String version) { + this(new BaseGraphRequestAdapter(authenticationProvider,client, graphClientOptions, nationalCloud, version)); } @Override diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java index aea5199d8..d19805b2c 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -1,5 +1,6 @@ package com.microsoft.graph.Requests; +import com.microsoft.graph.core.ClientException; import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.authentication.AuthenticationProvider; import com.microsoft.kiota.http.OkHttpRequestAdapter; @@ -43,20 +44,28 @@ public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticat } } + BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider){ + this(authenticationProvider, null, null, null, null, null); + } + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { this(authenticationProvider, null, null, null, null, baseUrl); } - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull Clouds nationalCloud, @Nonnull String version) { + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable Clouds nationalCloud, @Nullable String version) { this(authenticationProvider, determineBaseAddress(nationalCloud, version)); } - public BaseGraphRequestAdapter(@Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { - this(new AnonymousAuthenticationProvider(), null, null, client,graphClientOptions, baseUrl); + BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { + this(authenticationProvider, client, graphClientOptions, null, null); + } + + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { + this(authenticationProvider, null, null, client,graphClientOptions, baseUrl); } - public BaseGraphRequestAdapter(@Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull Clouds nationalCloud, @Nonnull String version) { - this(client,graphClientOptions, determineBaseAddress(nationalCloud, version)); + public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable Clouds nationalCloud, @Nullable String version) { + this(authenticationProvider, client, graphClientOptions , determineBaseAddress(nationalCloud, version)); } private static String determineBaseAddress(@Nullable Clouds nationalCloud, @Nullable String version) throws IllegalArgumentException { From c84ac7489fee6e93472c0a98cc22bf9f265c7b8b Mon Sep 17 00:00:00 2001 From: ramsessanchez <63934382+ramsessanchez@users.noreply.github.com> Date: Thu, 30 Jun 2022 15:24:29 -0700 Subject: [PATCH 022/561] Update BaseClient.java --- src/main/java/com/microsoft/graph/Requests/BaseClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java index 046cec264..22b2e69aa 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -27,7 +27,7 @@ class BaseClient implements IBaseClient{ this(new BaseGraphRequestAdapter(authenticationProvider, baseUrl)); } - BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull BaseGraphRequestAdapter.Clouds nationalCloud, @Nonnull String version){ + BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nullable BaseGraphRequestAdapter.Clouds nationalCloud, @Nullable String version){ this(new BaseGraphRequestAdapter(authenticationProvider, nationalCloud, version)); } From 2a0549ac4bc155fbed4105644c571de3ff579921 Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Wed, 13 Jul 2022 16:01:23 -0700 Subject: [PATCH 023/561] JavaDocs, adapter, factory, client constructor updates. --- build.gradle | 138 +++++++++--------- .../microsoft/graph/Requests/BaseClient.java | 46 +++--- .../Requests/BaseGraphRequestAdapter.java | 107 ++++++++++++-- .../graph/Requests/GraphClientFactory.java | 43 +++++- .../microsoft/graph/Requests/IBaseClient.java | 20 ++- 5 files changed, 234 insertions(+), 120 deletions(-) diff --git a/build.gradle b/build.gradle index 3a2a69c26..3f4ff3392 100644 --- a/build.gradle +++ b/build.gradle @@ -34,21 +34,12 @@ jacoco { toolVersion = "0.8.7" } -//Prevent javadocs from failing build -tasks.withType(Javadoc) { - failOnError false - options.addStringOption('Xdoclint:none', '-quiet') - options.addStringOption('encoding', 'UTF-8') - options.addStringOption('charSet', 'UTF-8') -} - - spotbugsMain { excludeFilter = file("spotBugsExcludeFilter.xml") reports { html { - enabled = true - destination = file("$buildDir/reports/spotbugs/main/spotbugs.html") + required + outputLocation = new File("$buildDir/reports/spotbugs/main/spotbugs.html") stylesheet = 'fancy-hist.xsl' } } @@ -58,16 +49,17 @@ spotbugsTest { excludeFilter = file("spotBugsExcludeFilter.xml") reports { html { - enabled = true - destination = file("$buildDir/reports/spotbugs/test/spotbugs.html") + required + outputLocation = new File('$buildDir/reports/spotbugs/test/spotbugs.html') stylesheet = 'fancy-hist.xsl' + } } } jacocoTestReport { reports { - xml.enabled true + xml.required } } @@ -99,11 +91,11 @@ def pomConfig = { } sonarqube { - properties { - property "sonar.projectKey", "microsoftgraph_msgraph-sdk-java-core" - property "sonar.organization", "microsoftgraph2" - property "sonar.host.url", "https://sonarcloud.io" - } + properties { + property "sonar.projectKey", "microsoftgraph_msgraph-sdk-java-core" + property "sonar.organization", "microsoftgraph2" + property "sonar.host.url", "https://sonarcloud.io" + } } //Publishing tasks- @@ -137,7 +129,7 @@ publishing { version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenArtifactSuffix}" from components.java artifact sourceJar - artifact javadocJar + artifact javadocJar pom.withXml { def root = asNode() root.appendNode('name', 'Microsoft Graph Core SDK for Java') @@ -149,59 +141,59 @@ publishing { } Snapshot(MavenPublication) { - customizePom(pom) - groupId project.property('mavenGroupId') - artifactId project.property('mavenArtifactId') - version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}" - from components.java - pom.withXml { - def pomFile = file("${project.buildDir}/generated-pom.xml") - writeTo(pomFile) - } - artifact sourceJar - artifact javadocJar - } - - mavenCentralRelease(MavenPublication) { - customizePom(pom) - groupId project.property('mavenGroupId') - artifactId project.property('mavenArtifactId') - version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}" - from components.java - pom.withXml { - def pomFile = file("${project.buildDir}/generated-pom.xml") - writeTo(pomFile) - } - artifact sourceJar - artifact javadocJar - } + customizePom(pom) + groupId project.property('mavenGroupId') + artifactId project.property('mavenArtifactId') + version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}${mavenCentralSnapshotArtifactSuffix}" + from components.java + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + } + artifact sourceJar + artifact javadocJar + } + + mavenCentralRelease(MavenPublication) { + customizePom(pom) + groupId project.property('mavenGroupId') + artifactId project.property('mavenArtifactId') + version "${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}" + from components.java + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + } + artifact sourceJar + artifact javadocJar + } } - repositories { + repositories { maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' name = 'sonatypeSnapshot' - + credentials { - if (project.rootProject.file('local.properties').exists()) { - Properties properties = new Properties() - properties.load(project.rootProject.file('local.properties').newDataInputStream()) - username = properties.getProperty('sonatypeUsername') - password = properties.getProperty('sonatypePassword') - } + if (project.rootProject.file('local.properties').exists()) { + Properties properties = new Properties() + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + username = properties.getProperty('sonatypeUsername') + password = properties.getProperty('sonatypePassword') + } } } - + maven { url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' name = 'sonatype' credentials { - if (project.rootProject.file('local.properties').exists()) { - Properties properties = new Properties() - properties.load(project.rootProject.file('local.properties').newDataInputStream()) - username = properties.getProperty('sonatypeUsername') - password = properties.getProperty('sonatypePassword') - } + if (project.rootProject.file('local.properties').exists()) { + Properties properties = new Properties() + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + username = properties.getProperty('sonatypeUsername') + password = properties.getProperty('sonatypePassword') + } } } } @@ -212,7 +204,7 @@ signing { } tasks.withType(Sign)*.enabled = mavenCentralPublishingEnabled.toBoolean() -def fixAscNames = { name -> +def fixAscNames = { name -> if(name.contains('pom')) { "${project.property('mavenArtifactId')}-${mavenMajorVersion}.${mavenMinorVersion}.${mavenPatchVersion}.pom.asc" } else { @@ -221,8 +213,8 @@ def fixAscNames = { name -> } compileJava { - sourceCompatibility = '17' - targetCompatibility = '17' + sourceCompatibility = '17' + targetCompatibility = '17' } def getVersionCode() { @@ -234,9 +226,9 @@ def getVersionName() { } artifacts { - archives jar - archives sourceJar - archives javadocJar + archives jar + archives sourceJar + archives javadocJar } def customizePom(pom) { @@ -264,14 +256,14 @@ def customizePom(pom) { licenses { license { name "MIT License" - url "http://opensource.org/licenses/MIT" - distribution "repo" + url "http://opensource.org/licenses/MIT" + distribution "repo" } } scm { url 'https://github.com/microsoftgraph/msgraph-sdk-java-core' - connection 'scm:git:git://github.com/microsoftgraph/msgraph-sdk-java-core.git' - developerConnection 'scm:git:ssh://git@github.com:microsoftgraph/msgraph-sdk-java-core.git' + connection 'scm:git:git://github.com/microsoftgraph/msgraph-sdk-java-core.git' + developerConnection 'scm:git:ssh://git@github.com:microsoftgraph/msgraph-sdk-java-core.git' } developers { developer { @@ -283,13 +275,13 @@ def customizePom(pom) { } gradle.taskGraph.whenReady { taskGraph -> - if (project.rootProject.file('local.properties').exists()) { + if (project.rootProject.file('local.properties').exists()) { Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) tasks.withType(Sign)*.enabled = (properties.containsKey('enableSigning')) ? properties.getProperty('enableSigning').toBoolean() : false allprojects { ext."signing.keyId" = properties.getProperty('signing.keyId') } allprojects { ext."signing.secretKeyRingFile" = properties.getProperty('signing.secretKeyRingFile') } - allprojects { ext."signing.password" = properties.getProperty('signing.password') } + allprojects { ext."signing.password" = properties.getProperty('signing.password') } } } diff --git a/src/main/java/com/microsoft/graph/Requests/BaseClient.java b/src/main/java/com/microsoft/graph/Requests/BaseClient.java index 22b2e69aa..58b1b4820 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseClient.java @@ -9,40 +9,43 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -@SuppressFBWarnings -class BaseClient implements IBaseClient{ +/** + * Default client implementation. + */ +public class BaseClient implements IBaseClient{ private RequestAdapter requestAdapter; + /** RequestBuilder for completing Batch Requests */ public BatchRequestBuilder batchRequestBuilder; - BaseClient(@Nonnull RequestAdapter requestAdapter) { + /** + * Constructor requiring only a RequestAdapter. + * + * @param requestAdapter the specified RequestAdapter used to complete requests. + */ + public BaseClient(@Nonnull RequestAdapter requestAdapter) { setRequestAdapter(requestAdapter); } - BaseClient(@Nonnull AuthenticationProvider authenticationProvider) { + /** + * Constructor requiring only an AuthenticationProvider. + * + * @param authenticationProvider the specified AuthenticationProvider for use in requests. + */ + public BaseClient(@Nonnull AuthenticationProvider authenticationProvider) { this(new BaseGraphRequestAdapter(authenticationProvider)); } - BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { + /** + * Constructor requiring an AuthenticationProvider and Base URL. + * + * @param authenticationProvider the specified AuthenticationProvider for use in requests. + * @param baseUrl the specified base URL for use in requests. + */ + public BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { this(new BaseGraphRequestAdapter(authenticationProvider, baseUrl)); } - BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nullable BaseGraphRequestAdapter.Clouds nationalCloud, @Nullable String version){ - this(new BaseGraphRequestAdapter(authenticationProvider, nationalCloud, version)); - } - - BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { - this(new BaseGraphRequestAdapter(authenticationProvider,client, graphClientOptions)); - } - - BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { - this(new BaseGraphRequestAdapter(authenticationProvider, client, graphClientOptions, baseUrl)); - } - - BaseClient(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable BaseGraphRequestAdapter.Clouds nationalCloud, @Nullable String version) { - this(new BaseGraphRequestAdapter(authenticationProvider,client, graphClientOptions, nationalCloud, version)); - } - @Override public void setRequestAdapter(RequestAdapter requestAdapter) { this.requestAdapter = requestAdapter; @@ -59,5 +62,4 @@ public BatchRequestBuilder getBatchRequestBuilder() { //return this.batchRequestBuilder != null ? this.batchRequestBuilder : new BatchRequestBuilder(this.requestAdapter) return this.batchRequestBuilder; } - } diff --git a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java index d19805b2c..ba695dac0 100644 --- a/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java +++ b/src/main/java/com/microsoft/graph/Requests/BaseGraphRequestAdapter.java @@ -1,5 +1,6 @@ package com.microsoft.graph.Requests; +import com.fasterxml.jackson.databind.ser.Serializers; import com.microsoft.graph.core.ClientException; import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.authentication.AuthenticationProvider; @@ -12,19 +13,34 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.net.URL; import java.util.HashMap; -@SuppressFBWarnings +/** + * Extension of the OkHttpRequestAdapter which is used as the default for Graph Requests. + */ public class BaseGraphRequestAdapter extends OkHttpRequestAdapter { + /** + * Enum list of Keys which can be used to access the cloudList map. + */ public enum Clouds { + /** Key for Global Cloud URL */ GLOBAL_CLOUD, + /** Key for US GOV Cloud URL */ USGOV_CLOUD, + /** Key for China Cloud URL */ CHINA_CLOUD, + /** Key for Germany Cloud URL */ GERMANY_CLOUD, + /** Key for US DOD Cloud URL */ USGOV_DOD_CLOUD } + /** + * Map of valid cloud urls for use in Graph requests. + * Accessible using a Clouds enum value. + */ private static final HashMap cloudList = new HashMap() {{ put( Clouds.GLOBAL_CLOUD, "https://graph.microsoft.com" ); put( Clouds.USGOV_CLOUD, "https://graph.microsoft.us"); @@ -34,7 +50,17 @@ public enum Clouds { }}; - /** Base Constructor */ + /** + * The default BaseGraphRequestAdapter constructor, includes all configurable properties. + * Note: GraphClientOptions will be ignored if you also choose to include an OKHttpClient. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param parseNodeFactory the ParseNodeFactory for use in requests. + * @param serializationWriterFactory the SerializationWriterFactory for use in requests. + * @param client the OkHttpClient for use in requests. + * @param graphClientOptions the GraphClientOptions for use in requests. + * @param baseUrl the base URL for use in requests. + */ public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable final ParseNodeFactory parseNodeFactory, @Nullable final SerializationWriterFactory serializationWriterFactory, @Nullable final OkHttpClient client, @Nullable final GraphClientOptions graphClientOptions, @Nullable String baseUrl) { super(authenticationProvider, parseNodeFactory, serializationWriterFactory, client != null ? client : GraphClientFactory.create(graphClientOptions).build()); if (baseUrl != null && !baseUrl.isEmpty()) { @@ -44,28 +70,80 @@ public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticat } } - BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider){ - this(authenticationProvider, null, null, null, null, null); + /** + * Constructor requiring only an AuthenticationProvider + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider) { + this(authenticationProvider, determineBaseAddress(null, null)); } - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { - this(authenticationProvider, null, null, null, null, baseUrl); + /** + * Constructor requiring an AuthenticationProvider and a base URL. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param baseUrl the base URL for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl) { + this(authenticationProvider, baseUrl, new GraphClientOptions()); } - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nullable Clouds nationalCloud, @Nullable String version) { - this(authenticationProvider, determineBaseAddress(nationalCloud, version)); + /** + * Constructor requiring an AuthenticationProvider, base URL, and an OkHttpClient. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param baseUrl the base URL for use in requests. + * @param client the OkHttpClient for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl, @Nonnull OkHttpClient client) { + this(authenticationProvider, null, null, client, null, baseUrl); } - BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions) { - this(authenticationProvider, client, graphClientOptions, null, null); + /** + * Constructor requiring an AuthenticationProvider, base URL, and GraphClientOptions. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param baseUrl the base URL for use in requests. + * @param graphClientOptions the GraphClientOptions for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull String baseUrl, @Nonnull GraphClientOptions graphClientOptions) { + this(authenticationProvider, null, null, null, graphClientOptions, baseUrl); } - public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nonnull String baseUrl) { - this(authenticationProvider, null, null, client,graphClientOptions, baseUrl); + /** + * Constructor requiring an AuthenticationProvider, optional National Cloud, and optional Version. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param cloud the National Cloud for use in requests. + * @param version the Graph version for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nullable Clouds cloud, @Nullable String version) { + this(authenticationProvider, determineBaseAddress(cloud, version)); } - public BaseGraphRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider, @Nonnull OkHttpClient client, @Nullable GraphClientOptions graphClientOptions, @Nullable Clouds nationalCloud, @Nullable String version) { - this(authenticationProvider, client, graphClientOptions , determineBaseAddress(nationalCloud, version)); + /** + * Constructor requiring an AuthenticationProvider, optional National Cloud, optional Version, and required OkHttpClient. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param cloud the National Cloud for use in requests. + * @param version the Graph version for use in requests. + * @param client the OkHttpClient for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nullable Clouds cloud, @Nullable String version, @Nonnull OkHttpClient client) { + this(authenticationProvider, determineBaseAddress(cloud, version), client); + } + + /** + * Constructor requiring an AuthenticationProvider, optional National Cloud, optional Version, and required GraphClientOptions. + * + * @param authenticationProvider the AuthenticationProvider for use in requests. + * @param cloud the National Cloud for use in requests. + * @param version the Graph version for use in requests. + * @param graphClientOptions the GraphClientOptions for use in requests. + */ + public BaseGraphRequestAdapter(@Nonnull AuthenticationProvider authenticationProvider, @Nullable Clouds cloud, @Nullable String version, @Nonnull GraphClientOptions graphClientOptions) { + this(authenticationProvider, determineBaseAddress(cloud, version), graphClientOptions); } private static String determineBaseAddress(@Nullable Clouds nationalCloud, @Nullable String version) throws IllegalArgumentException { @@ -76,5 +154,4 @@ private static String determineBaseAddress(@Nullable Clouds nationalCloud, @Null String baseAddress = version == null ? String.format("%s/%s/",cloud,"v1.0") : String.format("%s/%s/",cloud,version); return baseAddress; } - } diff --git a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java index 4e20e04c8..3bf384cb8 100644 --- a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java +++ b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java @@ -9,34 +9,61 @@ import okhttp3.Interceptor; import okhttp3.OkHttpClient; +import javax.annotation.Nonnull; import java.net.URI; import java.net.URISyntaxException; import java.text.Format; import java.time.temporal.ChronoUnit; import java.util.*; -@SuppressFBWarnings +/** + * The GraphClientFactory used to create the OkHttpClient. + */ public class GraphClientFactory { private GraphClientFactory() { } + /** + * The default OkHttpClient Builder for Graph. + * + * @return an OkHttpClient Builder instance. + */ public static OkHttpClient.Builder create() { - return create((GraphClientOptions) null); + return create(new GraphClientOptions()); } - public static OkHttpClient.Builder create(Interceptor[] interceptors, @Nullable GraphClientOptions graphClientOptions) { - OkHttpClient.Builder builder = create((GraphClientOptions) null); + /** + * OkHttpClient Builder for Graph with specified Interceptors and optional GraphClientOptions. + * + * @param interceptors desired interceptors for use in requests. + * @param graphClientOptions the GraphClientOptions for use in requests. + * @return an OkHttpClient Builder instance. + */ + public static OkHttpClient.Builder create(@Nonnull Interceptor[] interceptors, @Nullable GraphClientOptions graphClientOptions) { + OkHttpClient.Builder builder = graphClientOptions == null ? create() : create(graphClientOptions); for(Interceptor interceptor : interceptors) { builder.addInterceptor(interceptor); } return builder; } - public static OkHttpClient.Builder create(@Nullable GraphClientOptions options) { - OkHttpClient.Builder builder = KiotaClientFactory.Create(createDefaultGraphInterceptors(options)); - return builder; + /** + * The OkHttpClient Builder with optional GraphClientOptions + * + * @param graphClientOptions the GraphClientOptions for use in requests. + * @return an OkHttpClient Builder instance. + */ + public static OkHttpClient.Builder create(@Nullable GraphClientOptions graphClientOptions) { + GraphClientOptions options = graphClientOptions != null ? graphClientOptions : new GraphClientOptions(); + return KiotaClientFactory.Create(createDefaultGraphInterceptors(options)); } - public static Interceptor[] createDefaultGraphInterceptors(@Nullable GraphClientOptions graphClientOptions) { + /** + * Creates the default Interceptors for use with Graph. + * + * @param graphClientOptions the GraphClientOptions used to create the GraphTelemetryHandler with. + * @return an array of interceptors. + */ + public static Interceptor[] createDefaultGraphInterceptors(@Nonnull GraphClientOptions graphClientOptions) { List handlers = new ArrayList<>(); handlers.add(new GraphTelemetryHandler(graphClientOptions)); for(final Interceptor interceptor: KiotaClientFactory.CreateDefaultInterceptors()) { diff --git a/src/main/java/com/microsoft/graph/Requests/IBaseClient.java b/src/main/java/com/microsoft/graph/Requests/IBaseClient.java index 358b006b7..bab15dd6a 100644 --- a/src/main/java/com/microsoft/graph/Requests/IBaseClient.java +++ b/src/main/java/com/microsoft/graph/Requests/IBaseClient.java @@ -2,14 +2,30 @@ import com.microsoft.graph.content.BatchRequestBuilder; import com.microsoft.kiota.RequestAdapter; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -@SuppressFBWarnings +/** + * The default client interface + */ public interface IBaseClient { + /** + * Method to set the RequestAdapter property + * + * @param requestAdapter specifies the desired RequestAdapter + */ public void setRequestAdapter(RequestAdapter requestAdapter); + /** + * Returns the current RequestAdapter for sending requests + * + * @return the RequestAdapter currently in use + */ public RequestAdapter getRequestAdapter(); + /** + * Gets the BatchRequestBuilder for use in Batch Requests + * + * @return the BatchRequestBuilder instance + */ public BatchRequestBuilder getBatchRequestBuilder(); } From 1115722cbe34a8d8286357d0c2e73a2021e9f9de Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Thu, 14 Jul 2022 11:55:08 -0700 Subject: [PATCH 024/561] Add Interceptor only constructor --- .../graph/Requests/GraphClientFactory.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java index 3bf384cb8..3e1630127 100644 --- a/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java +++ b/src/main/java/com/microsoft/graph/Requests/GraphClientFactory.java @@ -32,14 +32,24 @@ public static OkHttpClient.Builder create() { } /** - * OkHttpClient Builder for Graph with specified Interceptors and optional GraphClientOptions. + * OkHttpClient Builder for Graph with specified Interceptors. + * + * @param interceptors desired interceptors for use in requests. + * @return an OkHttpClient Builder instance. + */ + public static OkHttpClient.Builder create(@Nonnull Interceptor[] interceptors) { + return create(interceptors, new GraphClientOptions()); + } + + /** + * OkHttpClient Builder for Graph with specified Interceptors and GraphClientOptions. * * @param interceptors desired interceptors for use in requests. * @param graphClientOptions the GraphClientOptions for use in requests. * @return an OkHttpClient Builder instance. */ - public static OkHttpClient.Builder create(@Nonnull Interceptor[] interceptors, @Nullable GraphClientOptions graphClientOptions) { - OkHttpClient.Builder builder = graphClientOptions == null ? create() : create(graphClientOptions); + public static OkHttpClient.Builder create(@Nonnull Interceptor[] interceptors, @Nonnull GraphClientOptions graphClientOptions) { + OkHttpClient.Builder builder = create(graphClientOptions); for(Interceptor interceptor : interceptors) { builder.addInterceptor(interceptor); } From 9528617145b8955769172ce851d487d18a09417d Mon Sep 17 00:00:00 2001 From: ramsessanchez Date: Tue, 9 Aug 2022 18:32:12 -0700 Subject: [PATCH 025/561] Delete all files which will need to be changes/not needed for kiota core --- .../BaseAuthenticationProvider.java | 50 -- .../IAuthenticationProvider.java | 20 - .../TokenCredentialAuthProvider.java | 64 -- .../microsoft/graph/content/BatchRequest.java | 85 --- .../graph/content/BatchRequestBuilder.java | 66 -- .../graph/content/BatchRequestContent.java | 186 ----- .../graph/content/BatchRequestStep.java | 49 -- .../graph/content/BatchResponseContent.java | 59 -- .../graph/content/BatchResponseStep.java | 76 --- .../microsoft/graph/content/BatchStep.java | 49 -- .../com/microsoft/graph/core/BaseClient.java | 382 ----------- .../graph/core/CustomRequestBuilder.java | 56 -- .../com/microsoft/graph/core/IBaseClient.java | 111 --- .../http/BaseActionCollectionRequest.java | 107 --- .../BaseActionCollectionRequestBuilder.java | 41 -- .../graph/http/BaseActionRequestBuilder.java | 33 - .../graph/http/BaseCollectionPage.java | 139 ---- ...BaseCollectionReferenceRequestBuilder.java | 51 -- .../graph/http/BaseCollectionRequest.java | 449 ------------ .../http/BaseCollectionRequestBuilder.java | 86 --- .../graph/http/BaseCollectionResponse.java | 84 --- .../BaseCollectionWithReferencesRequest.java | 58 -- ...ollectionWithReferencesRequestBuilder.java | 78 --- .../http/BaseDeltaCollectionRequest.java | 99 --- .../http/BaseEntityCollectionRequest.java | 93 --- .../http/BaseFunctionCollectionRequest.java | 81 --- .../BaseFunctionCollectionRequestBuilder.java | 50 -- .../http/BaseFunctionRequestBuilder.java | 43 -- .../graph/http/BaseReferenceRequest.java | 67 -- .../http/BaseReferenceRequestBuilder.java | 80 --- .../com/microsoft/graph/http/BaseRequest.java | 607 ----------------- .../graph/http/BaseRequestBuilder.java | 136 ---- .../graph/http/BaseStreamRequest.java | 314 --------- .../http/BaseVoidActionCollectionRequest.java | 103 --- .../graph/http/BaseWithReferenceRequest.java | 142 ---- .../http/BaseWithReferenceRequestBuilder.java | 101 --- .../http/CoreHttpCallbackFutureWrapper.java | 37 - .../graph/http/CoreHttpProvider.java | 643 ------------------ .../microsoft/graph/http/CustomRequest.java | 207 ------ .../graph/http/DeltaCollectionPage.java | 80 --- .../com/microsoft/graph/http/GraphError.java | 104 --- .../graph/http/GraphErrorResponse.java | 87 --- .../http/GraphFatalServiceException.java | 71 -- .../microsoft/graph/http/GraphInnerError.java | 82 --- .../graph/http/GraphServiceException.java | 485 ------------- .../com/microsoft/graph/http/HttpMethod.java | 54 -- .../graph/http/HttpResponseCode.java | 69 -- .../graph/http/ICollectionResponse.java | 27 - .../microsoft/graph/http/IHttpProvider.java | 134 ---- .../microsoft/graph/http/IHttpRequest.java | 198 ------ .../graph/http/IHttpStreamRequest.java | 29 - .../microsoft/graph/http/IRequestBuilder.java | 60 -- .../graph/http/IStatefulResponseHandler.java | 58 -- .../graph/http/PrimitiveRequest.java | 69 -- .../graph/http/PrimitiveRequestBuilder.java | 73 -- .../graph/http/ReferenceRequestBody.java | 72 -- .../graph/httpcore/AuthenticationHandler.java | 71 -- .../graph/httpcore/ChaosHttpHandler.java | 77 --- .../microsoft/graph/httpcore/HttpClients.java | 67 -- .../graph/httpcore/RedirectHandler.java | 151 ---- .../graph/httpcore/RetryHandler.java | 198 ------ .../graph/httpcore/TelemetryHandler.java | 103 --- .../middlewareoption/IMiddlewareControl.java | 8 - .../middlewareoption/IShouldRedirect.java | 17 - .../middlewareoption/IShouldRetry.java | 21 - .../middlewareoption/MiddlewareType.java | 27 - .../middlewareoption/RedirectOptions.java | 63 -- .../middlewareoption/RetryOptions.java | 92 --- .../middlewareoption/TelemetryOptions.java | 85 --- .../microsoft/graph/logger/DefaultLogger.java | 122 ---- .../com/microsoft/graph/logger/ILogger.java | 63 -- .../microsoft/graph/logger/LoggerLevel.java | 38 -- .../graph/options/FunctionOption.java | 40 -- .../microsoft/graph/options/HeaderOption.java | 42 -- .../com/microsoft/graph/options/Option.java | 79 --- .../microsoft/graph/options/QueryOption.java | 41 -- .../serializer/AdditionalDataManager.java | 101 --- .../graph/serializer/ByteArraySerializer.java | 68 -- .../serializer/CollectionPageSerializer.java | 130 ---- .../CollectionResponseDeserializer.java | 116 ---- .../graph/serializer/DefaultSerializer.java | 330 --------- .../serializer/DerivedClassIdentifier.java | 78 --- .../serializer/EdmNativeTypeSerializer.java | 58 -- .../graph/serializer/EnumSetSerializer.java | 91 --- .../FallbackTypeAdapterFactory.java | 162 ----- .../graph/serializer/GsonFactory.java | 250 ------- .../graph/serializer/IJsonBackedObject.java | 51 -- .../graph/serializer/ISerializer.java | 123 ---- ...peParametrizedIJsonBackedTypedAdapter.java | 63 -- .../serializer/OffsetDateTimeSerializer.java | 80 --- .../graph/tasks/IProgressCallback.java | 37 - .../microsoft/graph/tasks/IUploadSession.java | 48 -- .../graph/tasks/LargeFileUploadRequest.java | 109 --- .../graph/tasks/LargeFileUploadResponse.java | 163 ----- .../tasks/LargeFileUploadResponseHandler.java | 132 ---- .../graph/tasks/LargeFileUploadResult.java | 22 - .../graph/tasks/LargeFileUploadTask.java | 299 -------- .../BaseAuthenticationProviderTest.java | 83 --- .../TokenCredentialAuthProviderTest.java | 58 -- .../content/BatchRequestContentTest.java | 269 -------- .../graph/content/BatchRequestTestBody.java | 32 - .../content/BatchResponseContentTest.java | 169 ----- .../microsoft/graph/core/BaseClientTests.java | 115 ---- .../graph/core/ClientExceptionTests.java | 29 - .../graph/core/GraphServiceClientTest.java | 197 ------ .../microsoft/graph/core/MultipartTests.java | 75 -- .../graph/http/BaseCollectionPageTests.java | 67 -- .../http/BaseCollectionRequestTests.java | 174 ----- .../graph/http/BaseRequestBuilderTests.java | 37 - .../graph/http/BaseRequestTests.java | 141 ---- .../graph/http/BaseStreamRequestTests.java | 163 ----- .../CoreHttpCallbackFutureWrapperTests.java | 48 -- .../graph/http/CoreHttpProviderTests.java | 331 --------- .../graph/http/DeltaCollectionPageTests.java | 22 - .../graph/http/GraphErrorResponseTests.java | 62 -- .../microsoft/graph/http/GraphErrorTests.java | 31 - .../http/GraphFatalServiceExceptionTests.java | 26 - .../http/GraphServiceExceptionTests.java | 97 --- .../graph/http/ReferenceRequestBodyTests.java | 20 - .../httpcore/AuthenticationHandlerTest.java | 32 - .../graph/httpcore/HttpClientsTest.java | 30 - .../graph/httpcore/RedirectHandlerTest.java | 282 -------- .../graph/httpcore/RetryHandlerTest.java | 202 ------ .../graph/httpcore/TelemetryHandlerTest.java | 70 -- .../graph/httpcore/TelemetryOptionsTest.java | 53 -- .../middlewareoption/RedirectOptionsTest.java | 35 - .../middlewareoption/RetryOptionsTest.java | 35 - .../graph/logger/DefaultLoggerTests.java | 19 - .../graph/mocks/MockTokenCredential.java | 22 - .../microsoft/graph/models/MessageStub.java | 20 - .../MessagesCollectionResponseStub.java | 10 - .../microsoft/graph/models/ReactionStub.java | 21 - .../microsoft/graph/models/ReactionsStub.java | 21 - .../graph/models/SubReactionStub1.java | 10 - .../graph/models/SubReactionStub2.java | 10 - .../graph/models/TestIJsonBackedObject.java | 34 - .../microsoft/graph/options/OptionTests.java | 40 -- .../serializer/ByteArraySerializerTests.java | 26 - .../CollectionResponseOfBoolean.java | 7 - .../serializer/CollectionResponseOfLong.java | 7 - .../CollectionResponseOfPrimitivesTests.java | 41 -- .../CollectionResponseOfString.java | 6 - .../graph/serializer/DateOnlyTests.java | 41 -- .../serializer/DefaultSerializerTest.java | 67 -- .../DerivedClassIdentifierTest.java | 18 - .../graph/serializer/DurationTests.java | 30 - .../EdmNativeTypeSerializerTests.java | 76 --- .../graph/serializer/ISO8601Test.java | 48 -- ...rametrizedIJsonBackedTypedAdapterTest.java | 101 --- .../OffsetDateTimeSerializerTests.java | 199 ------ .../graph/serializer/TimeOfDayTests.java | 57 -- 151 files changed, 14766 deletions(-) delete mode 100644 src/main/java/com/microsoft/graph/authentication/BaseAuthenticationProvider.java delete mode 100644 src/main/java/com/microsoft/graph/authentication/IAuthenticationProvider.java delete mode 100644 src/main/java/com/microsoft/graph/authentication/TokenCredentialAuthProvider.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchRequest.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchRequestContent.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchRequestStep.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchResponseContent.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchResponseStep.java delete mode 100644 src/main/java/com/microsoft/graph/content/BatchStep.java delete mode 100644 src/main/java/com/microsoft/graph/core/BaseClient.java delete mode 100644 src/main/java/com/microsoft/graph/core/CustomRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/core/IBaseClient.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseActionCollectionRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseActionCollectionRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseActionRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionPage.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionReferenceRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionResponse.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionWithReferencesRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseCollectionWithReferencesRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseDeltaCollectionRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseEntityCollectionRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseFunctionCollectionRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseFunctionCollectionRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseFunctionRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseReferenceRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseReferenceRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseStreamRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseVoidActionCollectionRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseWithReferenceRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/BaseWithReferenceRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/CoreHttpCallbackFutureWrapper.java delete mode 100644 src/main/java/com/microsoft/graph/http/CoreHttpProvider.java delete mode 100644 src/main/java/com/microsoft/graph/http/CustomRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/DeltaCollectionPage.java delete mode 100644 src/main/java/com/microsoft/graph/http/GraphError.java delete mode 100644 src/main/java/com/microsoft/graph/http/GraphErrorResponse.java delete mode 100644 src/main/java/com/microsoft/graph/http/GraphFatalServiceException.java delete mode 100644 src/main/java/com/microsoft/graph/http/GraphInnerError.java delete mode 100644 src/main/java/com/microsoft/graph/http/GraphServiceException.java delete mode 100644 src/main/java/com/microsoft/graph/http/HttpMethod.java delete mode 100644 src/main/java/com/microsoft/graph/http/HttpResponseCode.java delete mode 100644 src/main/java/com/microsoft/graph/http/ICollectionResponse.java delete mode 100644 src/main/java/com/microsoft/graph/http/IHttpProvider.java delete mode 100644 src/main/java/com/microsoft/graph/http/IHttpRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/IHttpStreamRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/IRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/IStatefulResponseHandler.java delete mode 100644 src/main/java/com/microsoft/graph/http/PrimitiveRequest.java delete mode 100644 src/main/java/com/microsoft/graph/http/PrimitiveRequestBuilder.java delete mode 100644 src/main/java/com/microsoft/graph/http/ReferenceRequestBody.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/ChaosHttpHandler.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/HttpClients.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/RetryHandler.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/IMiddlewareControl.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/IShouldRedirect.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/IShouldRetry.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/MiddlewareType.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/RedirectOptions.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/RetryOptions.java delete mode 100644 src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java delete mode 100644 src/main/java/com/microsoft/graph/logger/DefaultLogger.java delete mode 100644 src/main/java/com/microsoft/graph/logger/ILogger.java delete mode 100644 src/main/java/com/microsoft/graph/logger/LoggerLevel.java delete mode 100644 src/main/java/com/microsoft/graph/options/FunctionOption.java delete mode 100644 src/main/java/com/microsoft/graph/options/HeaderOption.java delete mode 100644 src/main/java/com/microsoft/graph/options/Option.java delete mode 100644 src/main/java/com/microsoft/graph/options/QueryOption.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/AdditionalDataManager.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/ByteArraySerializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/CollectionPageSerializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/CollectionResponseDeserializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/DerivedClassIdentifier.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/EdmNativeTypeSerializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/EnumSetSerializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/FallbackTypeAdapterFactory.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/GsonFactory.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/IJsonBackedObject.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/ISerializer.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/ODataTypeParametrizedIJsonBackedTypedAdapter.java delete mode 100644 src/main/java/com/microsoft/graph/serializer/OffsetDateTimeSerializer.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/IProgressCallback.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/IUploadSession.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/LargeFileUploadRequest.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponse.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/LargeFileUploadResponseHandler.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/LargeFileUploadResult.java delete mode 100644 src/main/java/com/microsoft/graph/tasks/LargeFileUploadTask.java delete mode 100644 src/test/java/com/microsoft/graph/authentication/BaseAuthenticationProviderTest.java delete mode 100644 src/test/java/com/microsoft/graph/authentication/TokenCredentialAuthProviderTest.java delete mode 100644 src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java delete mode 100644 src/test/java/com/microsoft/graph/content/BatchRequestTestBody.java delete mode 100644 src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java delete mode 100644 src/test/java/com/microsoft/graph/core/BaseClientTests.java delete mode 100644 src/test/java/com/microsoft/graph/core/ClientExceptionTests.java delete mode 100644 src/test/java/com/microsoft/graph/core/GraphServiceClientTest.java delete mode 100644 src/test/java/com/microsoft/graph/core/MultipartTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/BaseCollectionPageTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/BaseCollectionRequestTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/BaseRequestBuilderTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/BaseRequestTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/BaseStreamRequestTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/CoreHttpCallbackFutureWrapperTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/CoreHttpProviderTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/DeltaCollectionPageTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/GraphErrorTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/GraphFatalServiceExceptionTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/GraphServiceExceptionTests.java delete mode 100644 src/test/java/com/microsoft/graph/http/ReferenceRequestBodyTests.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/AuthenticationHandlerTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/RedirectHandlerTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/middlewareoption/RedirectOptionsTest.java delete mode 100644 src/test/java/com/microsoft/graph/httpcore/middlewareoption/RetryOptionsTest.java delete mode 100644 src/test/java/com/microsoft/graph/logger/DefaultLoggerTests.java delete mode 100644 src/test/java/com/microsoft/graph/mocks/MockTokenCredential.java delete mode 100644 src/test/java/com/microsoft/graph/models/MessageStub.java delete mode 100644 src/test/java/com/microsoft/graph/models/MessagesCollectionResponseStub.java delete mode 100644 src/test/java/com/microsoft/graph/models/ReactionStub.java delete mode 100644 src/test/java/com/microsoft/graph/models/ReactionsStub.java delete mode 100644 src/test/java/com/microsoft/graph/models/SubReactionStub1.java delete mode 100644 src/test/java/com/microsoft/graph/models/SubReactionStub2.java delete mode 100644 src/test/java/com/microsoft/graph/models/TestIJsonBackedObject.java delete mode 100644 src/test/java/com/microsoft/graph/options/OptionTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/ByteArraySerializerTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/CollectionResponseOfBoolean.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/CollectionResponseOfLong.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/CollectionResponseOfPrimitivesTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/CollectionResponseOfString.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/DateOnlyTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/DefaultSerializerTest.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/DerivedClassIdentifierTest.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/DurationTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/EdmNativeTypeSerializerTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/ISO8601Test.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/ODataTypeParametrizedIJsonBackedTypedAdapterTest.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/OffsetDateTimeSerializerTests.java delete mode 100644 src/test/java/com/microsoft/graph/serializer/TimeOfDayTests.java diff --git a/src/main/java/com/microsoft/graph/authentication/BaseAuthenticationProvider.java b/src/main/java/com/microsoft/graph/authentication/BaseAuthenticationProvider.java deleted file mode 100644 index d2fb35a9f..000000000 --- a/src/main/java/com/microsoft/graph/authentication/BaseAuthenticationProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.microsoft.graph.authentication; - -import java.net.URL; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Locale; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * Provides basic common methods for all authentication providers - */ -public abstract class BaseAuthenticationProvider implements IAuthenticationProvider { - private static final HashSet validGraphHostNames = new HashSet<>(Arrays.asList("graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com")); - private HashSet customHosts; - - /** - * Allow the user to add custom hosts by passing in Array - * @param customHosts custom hosts passed in by user. - */ - public void setCustomHosts(@Nonnull String[] customHosts) { - if(this.customHosts == null){ - this.customHosts = new HashSet(); - } - for(String host: customHosts){ - this.customHosts.add(host.toLowerCase(Locale.ROOT)); - } - } - /** - * Get the custom hosts set by user. - * @return the custom hosts set by user. - */ - @Nullable - public String[] getCustomHosts(){ - return customHosts.toArray(new String[customHosts.size()]); - } - /** - * Determines whether a request should be authenticated or not based on it's url. - * If you're implementing a custom provider, call that method first before getting the token - * @param requestUrl request URL that is about to be executed - * @return whether a token should be attached to this request - */ - protected boolean shouldAuthenticateRequestWithUrl(@Nonnull final URL requestUrl) { - if (requestUrl == null || !requestUrl.getProtocol().toLowerCase(Locale.ROOT).equals("https")) - return false; - final String hostName = requestUrl.getHost().toLowerCase(Locale.ROOT); - return customHosts == null ? (validGraphHostNames.contains(hostName)) : (customHosts.contains(hostName)); - } -} diff --git a/src/main/java/com/microsoft/graph/authentication/IAuthenticationProvider.java b/src/main/java/com/microsoft/graph/authentication/IAuthenticationProvider.java deleted file mode 100644 index ae1f478f4..000000000 --- a/src/main/java/com/microsoft/graph/authentication/IAuthenticationProvider.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.microsoft.graph.authentication; - -import java.net.URL; -import java.util.concurrent.CompletableFuture; - -import javax.annotation.Nonnull; - -/** - * Authenticates requests to be sent to the API - */ -public interface IAuthenticationProvider { - /** - * Authenticates the request - * - * @param requestUrl the outgoing request URL - * @return a future with the token - */ - @Nonnull - CompletableFuture getAuthorizationTokenAsync(@Nonnull final URL requestUrl); -} diff --git a/src/main/java/com/microsoft/graph/authentication/TokenCredentialAuthProvider.java b/src/main/java/com/microsoft/graph/authentication/TokenCredentialAuthProvider.java deleted file mode 100644 index de9a5d9b3..000000000 --- a/src/main/java/com/microsoft/graph/authentication/TokenCredentialAuthProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.microsoft.graph.authentication; - -import com.azure.core.credential.AccessToken; -import com.azure.core.credential.TokenCredential; -import com.azure.core.credential.TokenRequestContext; - -import javax.annotation.Nonnull; -import java.net.URL; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.CompletableFuture; - -/** - * An implementation of the Authentication Provider with Azure-identity - */ -public class TokenCredentialAuthProvider extends BaseAuthenticationProvider { - /** TokenCredential expected from user */ - private final TokenCredential tokenCredential; - /** Context options which can be optionally set by the user */ - private final TokenRequestContext context; - /** Default scope to use when no scopes are provided */ - private static final String DEFAULT_GRAPH_SCOPE = "https://graph.microsoft.com/.default"; - - /** - * Creates an Authentication provider using a passed in TokenCredential - * - * @param tokenCredential Credential object inheriting the TokenCredential interface used to instantiate the Auth Provider - */ - public TokenCredentialAuthProvider(@Nonnull final TokenCredential tokenCredential) { - this(Collections.singletonList(DEFAULT_GRAPH_SCOPE), tokenCredential); - } - - /** - * Creates an Authentication provider using a TokenCredential and list of scopes - * - * @param tokenCredential Credential object inheriting the TokenCredential interface used to instantiate the Auth Provider - * @param scopes Specified desired scopes of the Auth Provider - */ - public TokenCredentialAuthProvider(@Nonnull final List scopes, @Nonnull final TokenCredential tokenCredential) { - if(scopes == null || scopes.isEmpty()) { - throw new IllegalArgumentException("scopes parameter cannot be null or empty"); - } - this.context = new TokenRequestContext(); - this.context.setScopes(scopes); - this.tokenCredential = Objects.requireNonNull(tokenCredential, "tokenCredential parameter cannot be null."); - } - - /** - * Returns an AccessToken as a string - * - * @return String representing the retrieved AccessToken - */ - @Nonnull - public CompletableFuture getAuthorizationTokenAsync(@Nonnull final URL requestUrl) { - if(shouldAuthenticateRequestWithUrl(Objects.requireNonNull(requestUrl, "requestUrl parameter cannot be null"))) - return this.tokenCredential - .getToken(this.context) - .toFuture() - .thenApply(AccessToken::getToken); - else - return CompletableFuture.completedFuture((String)null); - } -} diff --git a/src/main/java/com/microsoft/graph/content/BatchRequest.java b/src/main/java/com/microsoft/graph/content/BatchRequest.java deleted file mode 100644 index ae7b732c4..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchRequest.java +++ /dev/null @@ -1,85 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.content; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.microsoft.graph.core.ClientException; -import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.http.BaseRequest; -import com.microsoft.graph.http.HttpMethod; -import com.microsoft.graph.options.Option; - -/** Request for batch requests */ -public class BatchRequest extends BaseRequest { - - /** - * Instantiates a new batch request - * - * @param requestUrl the URL to send the request to - * @param client the client to use to execute the request - * @param options the options to apply to the request - */ - public BatchRequest(@Nonnull final String requestUrl, @Nonnull final IBaseClient client, @Nonnull final List options) { - super(requestUrl, client, options, BatchResponseContent.class); - } - - /** - * Send this request - * - * @return the response object - * @param content content of the batch request to execute - * @throws ClientException an exception occurs if there was an error while the request was sent - */ - @Nullable - public BatchResponseContent post(@Nullable final BatchRequestContent content) throws ClientException { - this.setHttpMethod(HttpMethod.POST); - final BatchResponseContent response = this.getClient().getHttpProvider().send(this, BatchResponseContent.class, content); - setSerializerOnSteps(response); - return response; - } - /** - * Send this request - * - * @return the response object - * @param content content of the batch request to execute - * @throws ClientException an exception occurs if there was an error while the request was sent - */ - @Nullable - public java.util.concurrent.CompletableFuture postAsync(@Nullable final BatchRequestContent content) throws ClientException { - this.setHttpMethod(HttpMethod.POST); - return this.getClient().getHttpProvider().sendAsync(this, BatchResponseContent.class, content).thenApply(response -> { - setSerializerOnSteps(response); - return response; - }); - } - private void setSerializerOnSteps(final BatchResponseContent response) { - if(response.responses != null) - for(final BatchResponseStep step : response.responses) { - step.serializer = this.getClient().getSerializer(); - } - } -} diff --git a/src/main/java/com/microsoft/graph/content/BatchRequestBuilder.java b/src/main/java/com/microsoft/graph/content/BatchRequestBuilder.java deleted file mode 100644 index c6ceda75d..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchRequestBuilder.java +++ /dev/null @@ -1,66 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.content; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.http.BaseRequestBuilder; -import com.microsoft.graph.options.Option; - -/** Request builder for batch requests */ -public class BatchRequestBuilder extends BaseRequestBuilder { - /** - * Instantiates a new batch request builder - * @param requestUrl the URL for the request - * @param client the client to use to execute the request - * @param options the request options - */ - public BatchRequestBuilder(@Nonnull final String requestUrl, @Nonnull final IBaseClient client, @Nonnull final List options) { - super(requestUrl, client, options); - } - /** - * Creates the request - * - * @param requestOptions the options for this request - * @return the IUserRequest instance - */ - @Nonnull - public BatchRequest buildRequest(@Nullable final com.microsoft.graph.options.Option... requestOptions) { - return buildRequest(getOptions(requestOptions)); - } - - /** - * Creates the request - * - * @param requestOptions the options for this request - * @return the IUserRequest instance - */ - @Nonnull - public BatchRequest buildRequest(@Nonnull final java.util.List requestOptions) { - return new BatchRequest(this.getRequestUrl(), getClient(), requestOptions); - } -} diff --git a/src/main/java/com/microsoft/graph/content/BatchRequestContent.java b/src/main/java/com/microsoft/graph/content/BatchRequestContent.java deleted file mode 100644 index 31c0ac766..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchRequestContent.java +++ /dev/null @@ -1,186 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.content; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.concurrent.ThreadLocalRandom; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; -import com.microsoft.graph.http.HttpMethod; -import com.microsoft.graph.http.IHttpRequest; -import com.microsoft.graph.options.HeaderOption; -import com.microsoft.graph.serializer.IJsonBackedObject; - -/** Respresents the content of a JSON batch request */ -public class BatchRequestContent { - /** Steps part of the batch request */ - @Expose - @Nullable - @SerializedName("requests") - public List> requests; - - /** - * Adds a request as a step to the current batch. Defaults to GET if the HTTP method is not set in the request. - * @param request the request to add as a step - * @return the id of the step that was just added to the batch - */ - @Nonnull - public String addBatchRequestStep(@Nonnull final IHttpRequest request) { - Objects.requireNonNull(request, "request parameter cannot be null"); - return addBatchRequestStep(request, request.getHttpMethod() == null ? HttpMethod.GET : request.getHttpMethod()); - } - /** - * Adds a request as a step to the current batch - * @param request the request to add as a step - * @param httpMethod the HttpMethod to execute the request with - * @return the id of the step that was just added to the batch - */ - @Nonnull - public String addBatchRequestStep(@Nonnull final IHttpRequest request, @Nonnull final HttpMethod httpMethod) { - return addBatchRequestStep(request, httpMethod, null); - } - /** - * Adds a request as a step to the current batch - * @param request the request to add as a step - * @param httpMethod the HttpMethod to execute the request with - * @param the type of the request body - * @param serializableBody the body of the request to be serialized - * @return the id of the step that was just added to the batch - */ - @Nonnull - public String addBatchRequestStep(@Nonnull final IHttpRequest request, @Nonnull final HttpMethod httpMethod, @Nullable final T serializableBody) { - return addBatchRequestStep(request, httpMethod, serializableBody, (String[])null); - } - /** - * Adds a request as a step to the current batch - * @param request the request to add as a step - * @param httpMethod the HttpMethod to execute the request with - * @param the type of the request body - * @param serializableBody the body of the request to be serialized - * @param dependsOnRequestsIds the ids of steps this request depends on - * @return the id of the step that was just added to the batch - */ - @Nonnull - public String addBatchRequestStep(@Nonnull final IHttpRequest request, @Nonnull final HttpMethod httpMethod, @Nullable final T serializableBody, @Nullable final String ...dependsOnRequestsIds) { - Objects.requireNonNull(request, "request parameter cannot be null"); - Objects.requireNonNull(httpMethod, "httpMethod parameter cannot be null"); - if(dependsOnRequestsIds != null) - for(final String id : dependsOnRequestsIds) { - if(getStepById(id) == null) - throw new IllegalArgumentException("the current request depends on a inexisting request"); - } - - if(requests == null) - requests = new ArrayList<>(); - - final Matcher protocolAndHostReplacementMatcher = protocolAndHostReplacementPattern.matcher(request.getRequestUrl().toString()); - final BatchRequestStep step = new BatchRequestStep() {{ - url = protocolAndHostReplacementMatcher.replaceAll(""); - body = serializableBody; - method = httpMethod.toString().toUpperCase(Locale.getDefault()); - dependsOn = dependsOnRequestsIds != null && dependsOnRequestsIds.length > 0 ? new HashSet<>(Arrays.asList(dependsOnRequestsIds)) : null; - id = getNextRequestId(); - }}; - - if(!request.getHeaders().isEmpty()) { - step.headers = new HashMap<>(); - for(final HeaderOption headerOption : request.getHeaders()) - step.headers.putIfAbsent(headerOption.getName().toLowerCase(Locale.getDefault()), headerOption.getValue().toString()); - } - if(step.body != null && step.body instanceof IJsonBackedObject && - (step.headers == null || !step.headers.containsKey(contentTypeHeaderKey))) { - if(step.headers == null) - step.headers = new HashMap<>(); - step.headers.putIfAbsent(contentTypeHeaderKey, "application/json"); - } - requests.add(step); - return step.id; - } - private static final String contentTypeHeaderKey = "content-type"; - /** - * Removes requests from the requests to be executed by the batch. Also removes any dependency references that might exist. - * @param stepIds ids of steps to be removed. - */ - public void removeBatchRequestStepWithId(@Nonnull final String ...stepIds) { - if(requests == null) return; - - for(final String stepId : stepIds) { - Objects.requireNonNull(stepId, "parameter stepIds cannot contain null values"); - requests.removeIf(x -> stepId.equals(x.id)); - for(final BatchRequestStep step : requests) { - if(step.dependsOn != null) { - step.dependsOn.removeIf(stepId::equals); - if(step.dependsOn.isEmpty()) - step.dependsOn = null; // so we don't send dependsOn: [] over the wire - } - } - } - } - /** - * Gets a step by its step id - * @param the type of the request body - * @param stepId the request step id returned from the add method - * @return the request corresponding to the provided id or null - */ - @Nullable - @SuppressWarnings("unchecked") - public BatchRequestStep getStepById(@Nonnull final String stepId) { - Objects.requireNonNull(stepId, "parameter stepId cannot be null"); - if(requests == null) return null; - - for(final BatchRequestStep step : requests) { - if(stepId.equals(step.id)) - return (BatchRequestStep)step; - } - return null; - } - /** pattern to replace the protocol and host part of the request if specified */ - @Nonnull - protected static final Pattern protocolAndHostReplacementPattern = - Pattern.compile("(?i)^http[s]?:\\/\\/(?:graph|dod-graph|microsoftgraph)\\.(?:microsoft|chinacloudapi)\\.(?:com|cn|us|de)\\/(?:v1\\.0|beta)"); // (?i) case insensitive - //https://docs.microsoft.com/en-us/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints - /** - * Generates a randomly available request id - * @return a random request id - */ - @Nonnull - protected String getNextRequestId() { - String requestId; - do { - requestId = Integer.toString(ThreadLocalRandom.current().nextInt(1, Integer.MAX_VALUE)); - } while(getStepById(requestId) != null); - return requestId; - } -} diff --git a/src/main/java/com/microsoft/graph/content/BatchRequestStep.java b/src/main/java/com/microsoft/graph/content/BatchRequestStep.java deleted file mode 100644 index cb6ae415a..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchRequestStep.java +++ /dev/null @@ -1,49 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.content; - -import java.util.HashSet; - -import javax.annotation.Nullable; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -/** the http request for the batch step */ -public class BatchRequestStep extends BatchStep { - /** The URL to query for the step */ - @Nullable - @Expose - @SerializedName("url") - public String url; - /** The HTTP method to use to execute the request */ - @Nullable - @Expose - @SerializedName("method") - public String method; - /** The IDs of the steps this step depends on before being executed */ - @Nullable - @Expose - @SerializedName("dependsOn") - public HashSet dependsOn; -} diff --git a/src/main/java/com/microsoft/graph/content/BatchResponseContent.java b/src/main/java/com/microsoft/graph/content/BatchResponseContent.java deleted file mode 100644 index fe8022524..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchResponseContent.java +++ /dev/null @@ -1,59 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.content; - -import java.util.List; -import java.util.Objects; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.google.gson.JsonElement; -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -/** Respresents the result of a JSON batch request */ -public class BatchResponseContent { - /** Responses to the steps from the request */ - @Nullable - @Expose - @SerializedName("responses") - public List> responses; - - /** - * Gets a response to a request in the batch by its id - * @param stepId Id of the request step in the batch request - * @return The step response corresponding to the ID or null - */ - @Nullable - public BatchResponseStep getResponseById(@Nonnull final String stepId) { - Objects.requireNonNull(stepId, "parameter stepId cannot be null"); - if(responses == null) return null; - - for(final BatchResponseStep step : responses) { - if(stepId.equals(step.id)) - return step; - } - return null; - } -} diff --git a/src/main/java/com/microsoft/graph/content/BatchResponseStep.java b/src/main/java/com/microsoft/graph/content/BatchResponseStep.java deleted file mode 100644 index 659761385..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchResponseStep.java +++ /dev/null @@ -1,76 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ -package com.microsoft.graph.content; - -import java.util.ArrayList; -import java.util.Objects; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.google.gson.JsonElement; -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; -import com.microsoft.graph.http.GraphErrorResponse; -import com.microsoft.graph.http.GraphFatalServiceException; -import com.microsoft.graph.http.GraphServiceException; -import com.microsoft.graph.logger.ILogger; -import com.microsoft.graph.logger.LoggerLevel; -import com.microsoft.graph.serializer.DefaultSerializer; -import com.microsoft.graph.serializer.ISerializer; - -/** Response for the batch step */ -public class BatchResponseStep extends BatchStep { - /** Http status code of the response */ - @Expose - @SerializedName("status") - public int status; - /** Serializer to use for response deserialization */ - @Nullable - protected ISerializer serializer; - - /** - * Returned the deserialized response body of the current step - * @param type of the response body - * @param resultClass class of the resulting response body - * @return the deserialized response body - * @throws GraphServiceException when a bad request was sent - * @throws GraphFatalServiceException when the service did not complete the operation as expected because of an internal error - */ - @Nullable - public T2 getDeserializedBody(@Nonnull final Class resultClass) throws GraphServiceException, GraphFatalServiceException { - Objects.requireNonNull(resultClass, "parameter resultClass cannot be null"); - if(serializer == null || body == null || !(body instanceof JsonElement)) return null; - - final GraphErrorResponse error = serializer.deserializeObject((JsonElement)body, GraphErrorResponse.class); - if(error == null || error.error == null) { - return serializer.deserializeObject((JsonElement)body, resultClass); - } else { - boolean verboseError = false; - if(serializer instanceof DefaultSerializer) { - final ILogger logger = ((DefaultSerializer)serializer).getLogger(); - verboseError = logger != null && logger.getLoggingLevel() == LoggerLevel.DEBUG; - } - throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, verboseError); - } - } -} diff --git a/src/main/java/com/microsoft/graph/content/BatchStep.java b/src/main/java/com/microsoft/graph/content/BatchStep.java deleted file mode 100644 index 89773904e..000000000 --- a/src/main/java/com/microsoft/graph/content/BatchStep.java +++ /dev/null @@ -1,49 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2021 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.content; - -import java.util.HashMap; - -import javax.annotation.Nullable; - -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; - -/** Common abstractions between batch request steps and batch response steps */ -public abstract class BatchStep { - /** The Id of the step */ - @Expose - @Nullable - @SerializedName("id") - public String id; - /** The request/response headers for the step */ - @Expose - @Nullable - @SerializedName("headers") - public HashMap headers; - /** The body of request/response for the step */ - @Nullable - @Expose - @SerializedName("body") - public T body; -} diff --git a/src/main/java/com/microsoft/graph/core/BaseClient.java b/src/main/java/com/microsoft/graph/core/BaseClient.java deleted file mode 100644 index 116a8e0e4..000000000 --- a/src/main/java/com/microsoft/graph/core/BaseClient.java +++ /dev/null @@ -1,382 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2017 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.core; - -import com.google.gson.JsonElement; -import com.microsoft.graph.http.CoreHttpProvider; -import com.microsoft.graph.http.IHttpProvider; -import com.microsoft.graph.httpcore.HttpClients; -import com.microsoft.graph.authentication.IAuthenticationProvider; -import com.microsoft.graph.content.BatchRequestBuilder; -import com.microsoft.graph.logger.DefaultLogger; -import com.microsoft.graph.logger.ILogger; -import com.microsoft.graph.serializer.DefaultSerializer; -import com.microsoft.graph.serializer.ISerializer; - -import javax.annotation.Nullable; - -import java.util.Collections; -import java.util.Objects; - -import javax.annotation.Nonnull; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import okhttp3.OkHttpClient; -import okhttp3.Request; - -/** - * A client that communications with an OData service - * @param type of a request for the native http client - */ -public class BaseClient implements IBaseClient { - /** - * Restricted constructor - */ - protected BaseClient() { - } - - /** - * The default endpoint for the Microsoft Graph Service - */ - public static final String DEFAULT_GRAPH_ENDPOINT = "https://graph.microsoft.com/v1.0"; - - /** - * The current endpoint - */ - private String endpoint; - - @Override - @Nonnull - public String getServiceRoot() { - if (endpoint == null) { - endpoint = DEFAULT_GRAPH_ENDPOINT; - } - return endpoint; - } - - @Override - public void setServiceRoot(@Nonnull final String value) { - Objects.requireNonNull(value, "value parameter cannot be null"); - endpoint = String.valueOf(value); - } - - /** - * Send a custom request to Graph - * - * @param url - * the full URL to make a request with - * @param responseType - * the response class to deserialize the response into - * @return the instance of this builder - */ - @Nonnull - public CustomRequestBuilder customRequest(@Nonnull final String url, @Nonnull final Class responseType) { - Objects.requireNonNull(url, "url parameter cannot be null"); - Objects.requireNonNull(responseType, "responseType parameter cannot be null"); - return new CustomRequestBuilder<>(getServiceRoot() + url, this, null, responseType); - } - - /** - * Send a custom request to Graph - * - * @param url - * the full URL to make a request with - * @return the instance of this builder - */ - @Nonnull - public CustomRequestBuilder customRequest(@Nonnull final String url) { - return this.customRequest(url, JsonElement.class); - } - - /** - * Get the batch request builder. - * @return a request builder to execute a batch. - */ - @Nonnull - public BatchRequestBuilder batch() { - return new BatchRequestBuilder(getServiceRoot() + "/$batch", this, Collections.emptyList()); - } - - /** - * Gets the builder to start configuring the client - * - * @return builder to start configuring the client - */ - @Nonnull - public static Builder builder() { - return builder(OkHttpClient.class, Request.class); - } - - /** - * Gets the builder to start configuring the client - * - * @param the type of the native http client - * @param the type of the native http request - * @param nativeClientClass the class of the native http client - * @param nativeRequestClass the class of the native http request - * @return builder to start configuring the client - */ - @Nonnull - public static Builder builder(@Nonnull final Class nativeClientClass, @Nonnull final Class nativeRequestClass) { - return new Builder<>(); - } - - /** - * Builder to help configure the Graph service client - * @param type of the native http library client - * @param type of a request for the native http client - */ - public static class Builder { - private ISerializer serializer; - private IHttpProvider httpProvider; - private ILogger logger; - private httpClientType httpClient; - private IAuthenticationProvider auth; - - private IAuthenticationProvider getAuthenticationProvider() { - if(auth == null) { - throw new NullPointerException("auth"); - } else { - return auth; - } - } - private ILogger getLogger() { - if(logger == null) { - return new DefaultLogger(); - } else { - return logger; - } - } - private ISerializer getSerializer() { - if(serializer == null) { - return new DefaultSerializer(getLogger()); - } else { - return serializer; - } - } - @SuppressWarnings("unchecked") - private httpClientType getHttpClient() { - if(httpClient == null) { - return (httpClientType)HttpClients.createDefault(getAuthenticationProvider()); - } else { - return httpClient; - } - } - @SuppressWarnings("unchecked") - private IHttpProvider getHttpProvider() { - if(httpProvider == null) { - return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), (OkHttpClient)getHttpClient()); - } else { - return httpProvider; - } - } - - /** - * Sets the serializer. - * - * @param serializer - * the serializer - * @return the instance of this builder - */ - @Nonnull - public Builder serializer(@Nonnull final ISerializer serializer) { - Objects.requireNonNull(serializer, "parameter serializer cannot be null"); - this.serializer = serializer; - return this; - } - - /** - * Sets the httpProvider - * - * @param httpProvider - * the httpProvider - * @return the instance of this builder - */ - @Nonnull - public Builder httpProvider(@Nonnull final IHttpProvider httpProvider) { - Objects.requireNonNull(httpProvider, "parameter httpProvider cannot be null"); - this.httpProvider = httpProvider; - return this; - } - - /** - * Sets the logger - * - * @param logger - * the logger - * @return the instance of this builder - */ - @Nonnull - @SuppressFBWarnings - public Builder logger(@Nonnull final ILogger logger) { - Objects.requireNonNull(logger, "parameter logger cannot be null"); - this.logger = logger; - return this; - } - - /** - * Sets the http client - * - * @param client the http client - * - * @return the instance of this builder - */ - @Nonnull - public Builder httpClient(@Nonnull final httpClientType client) { - Objects.requireNonNull(client, "parameter client cannot be null"); - this.httpClient = client; - return this; - } - - /** - * Sets the authentication provider - * - * @param auth the authentication provider - * @return the instance of this builder - */ - @Nonnull - public Builder authenticationProvider(@Nonnull final IAuthenticationProvider auth) { - Objects.requireNonNull(auth, "parameter auth cannot be null"); - this.auth = auth; - return this; - } - - /** - * Builds and returns the Graph service client. - * - * @param instance the instance to set the information for - * @param the type of the client to return - * @return the Graph service client object - * @throws ClientException - * if there was an exception creating the client - */ - @Nonnull - protected > ClientType buildClient(@Nonnull ClientType instance) throws ClientException { - Objects.requireNonNull(instance, "The instance cannot be null"); - instance.setHttpProvider(this.getHttpProvider()); - instance.setLogger(this.getLogger()); - instance.setSerializer(this.getSerializer()); - return instance; - } - - /** - * Builds and returns the Graph service client. - * - * @return the Graph service client object - * @throws ClientException - * if there was an exception creating the client - */ - @Nonnull - public IBaseClient buildClient() throws ClientException { - return buildClient(new BaseClient<>()); - } - } - - /** - * The HTTP provider instance - */ - private IHttpProvider httpProvider; - - /** - * The logger - */ - private ILogger logger; - - /** - * The serializer instance - */ - private ISerializer serializer; - - /** - * Gets the HTTP provider - * - * @return The HTTP provider - */ - @Override - @Nullable - public IHttpProvider getHttpProvider() { - return httpProvider; - } - - /** - * Gets the logger - * - * @return The logger - */ - @Nullable - @SuppressFBWarnings - public ILogger getLogger() { - return logger; - } - - /** - * Gets the serializer - * - * @return The serializer - */ - @Override - @Nullable - public ISerializer getSerializer() { - return serializer; - } - - /** - * Sets the logger - * - * @param logger The logger - */ - protected void setLogger(@Nonnull final ILogger logger) { - Objects.requireNonNull(logger, "parameter logger cannot be null"); - this.logger = logger; - } - - /** - * Sets the HTTP provider - * - * @param httpProvider The HTTP provider - */ - protected void setHttpProvider(@Nonnull final IHttpProvider httpProvider) { - Objects.requireNonNull(httpProvider, "parameter httpProvider cannot be null"); - this.httpProvider = httpProvider; - } - - /** - * Sets the serializer - * - * @param serializer The serializer - */ - public void setSerializer(@Nonnull final ISerializer serializer) { - Objects.requireNonNull(serializer, "parameter serializer cannot be null"); - this.serializer = serializer; - } - - /** - * Gets the service SDK version if the service SDK is in use, null otherwise - * @return the service SDK version if the service SDK is in use, null otherwise - */ - @Override - @Nullable - public String getServiceSDKVersion() { - return null; - } -} diff --git a/src/main/java/com/microsoft/graph/core/CustomRequestBuilder.java b/src/main/java/com/microsoft/graph/core/CustomRequestBuilder.java deleted file mode 100644 index 468dcdde8..000000000 --- a/src/main/java/com/microsoft/graph/core/CustomRequestBuilder.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.microsoft.graph.core; - -import java.util.List; -import java.util.Objects; - -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -import com.microsoft.graph.http.BaseRequestBuilder; -import com.microsoft.graph.http.CustomRequest; -import com.microsoft.graph.options.Option; - -/** - * The class for the CustomRequestBuilder - * - * If the provided URL is malformed, the ClientException will contain a MalformedURLException - */ -public class CustomRequestBuilder extends BaseRequestBuilder { - /** Type to use for response deserialization */ - public final Class responseType; - - /** - * Instanciates a new custom request builder - * - * @param requestUrl the URL to send the request to - * @param client the client to use for the request - * @param requestOptions options to apply to the request - * @param responseType type to use for response deserialization - */ - public CustomRequestBuilder(@Nonnull final String requestUrl, @Nonnull final IBaseClient client, @Nullable final List requestOptions, @Nonnull final Class responseType) { - super(requestUrl, client, requestOptions); - this.responseType = Objects.requireNonNull(responseType, "parameter responseType cannot be null"); - } - - /** - * Builds the request to be executed - * - * @return the request to be executed - * @param requestOptions the options to apply to the request - */ - @Nonnull - public CustomRequest buildRequest(@Nullable final com.microsoft.graph.options.Option... requestOptions) { - return buildRequest(getOptions(requestOptions)); - } - - /** - * Builds the request to be executed - * - * @return the request to be executed - * @param requestOptions the options to apply to the request - */ - @Nonnull - public CustomRequest buildRequest(@Nullable final List requestOptions) { - return new CustomRequest<>(getRequestUrl(), getClient(), requestOptions, responseType); - } -} diff --git a/src/main/java/com/microsoft/graph/core/IBaseClient.java b/src/main/java/com/microsoft/graph/core/IBaseClient.java deleted file mode 100644 index b3b0e7d32..000000000 --- a/src/main/java/com/microsoft/graph/core/IBaseClient.java +++ /dev/null @@ -1,111 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2017 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.core; - -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -import com.google.gson.JsonElement; -import com.microsoft.graph.content.BatchRequestBuilder; -import com.microsoft.graph.http.IHttpProvider; -import com.microsoft.graph.logger.ILogger; -import com.microsoft.graph.serializer.ISerializer; - -/** - * A client that communications with an OData service - * @param type of a request for the native http client - */ -public interface IBaseClient { - /** - * Gets the service root - * - * @return the service root - */ - @Nonnull - String getServiceRoot(); - - /** - * Sets the service root - * - * @param value the service root - */ - void setServiceRoot(@Nonnull final String value); - - /** - * Gets the HTTP provider - * - * @return the HTTP provider - */ - @Nullable - IHttpProvider getHttpProvider(); - - /** - * Gets the logger - * - * @return the logger - */ - @Nullable - ILogger getLogger(); - - /** - * Gets the serializer - * - * @return the serializer - */ - @Nullable - ISerializer getSerializer(); - - /** - * Gets a builder to execute a custom request - * - * @return the custom request builder - * @param url the url to send the request to - * @param responseType the class to deserialize the response to - * @param the type to deserialize the response to - */ - @Nonnull - CustomRequestBuilder customRequest(@Nonnull final String url, @Nonnull final Class responseType); - - /** - * Gets a builder to execute a custom request with a generic JSONObject response - * - * @return the custom request builder - * @param url the url to send the request to - */ - @Nonnull - CustomRequestBuilder customRequest(@Nonnull final String url); - - /** - * Get the batch request builder. - * @return a request builder to execute a batch. - */ - @Nonnull - BatchRequestBuilder batch(); - - /** - * Gets the service SDK version if the service SDK is in use, null otherwise - * @return the service SDK version if the service SDK is in use, null otherwise - */ - @Nullable - String getServiceSDKVersion(); -} diff --git a/src/main/java/com/microsoft/graph/http/BaseActionCollectionRequest.java b/src/main/java/com/microsoft/graph/http/BaseActionCollectionRequest.java deleted file mode 100644 index caff0a918..000000000 --- a/src/main/java/com/microsoft/graph/http/BaseActionCollectionRequest.java +++ /dev/null @@ -1,107 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2020 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.http; - -import java.lang.NoSuchFieldException; -import java.lang.IllegalAccessException; -import java.util.List; -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -import com.microsoft.graph.core.ClientException; -import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.options.Option; - -/** - * A request against a collection bound action - * - * @param the type of the object in the collection - * @param the response collection type - * @param the collection page type - */ -public abstract class BaseActionCollectionRequest, - T3 extends BaseCollectionPage>> extends BaseCollectionRequest { - - - /** - * Create the collection request - * - * @param requestUrl the URL to make the request against - * @param client the client which can issue the request - * @param options the options for this request - * @param responseCollectionClass the class for the response collection - * @param collectionPageClass the class for the collection page - * @param collectionRequestBuilderClass the class for the collection request builder - */ - public BaseActionCollectionRequest(@Nonnull final String requestUrl, - @Nonnull final IBaseClient client, - @Nullable final List options, - @Nonnull final Class responseCollectionClass, - @Nonnull final Class collectionPageClass, - @Nonnull final Class, T2, T3, ? extends BaseCollectionRequest>> collectionRequestBuilderClass) { - super(requestUrl, client, options, responseCollectionClass, collectionPageClass, collectionRequestBuilderClass); - } - - /** - * Invokes the method and calls the callback with the resulting collection of objects - * @return a future with the result - */ - @Nonnull - public java.util.concurrent.CompletableFuture postAsync() { - getBaseRequest().setHttpMethod(HttpMethod.POST); - Object bodyToSend = null; - try { - bodyToSend = this.getClass().getField("body").get(this); - } catch (NoSuchFieldException | IllegalAccessException ex) { - // this action doesn't body arguments, expected, no-op - } - return getBaseRequest() - .getClient() - .getHttpProvider() - .sendAsync(this, - responseCollectionClass, - bodyToSend) - .thenApply(this::buildFromResponse); - } - /** - * Invokes the method and returns the resulting collection of objects - * @return a collection of objects returned by the method - */ - @Nullable - public T3 post() throws ClientException { - getBaseRequest().setHttpMethod(HttpMethod.POST); - Object bodyToSend = null; - try { - bodyToSend = this.getClass().getField("body").get(this); - } catch (NoSuchFieldException | IllegalAccessException ex) { - // this action doesn't body arguments, expected, no-op - } - return buildFromResponse(getBaseRequest() - .getClient() - .getHttpProvider() - .send(this, - responseCollectionClass, - bodyToSend) - ); - } -} diff --git a/src/main/java/com/microsoft/graph/http/BaseActionCollectionRequestBuilder.java b/src/main/java/com/microsoft/graph/http/BaseActionCollectionRequestBuilder.java deleted file mode 100644 index 000cac4cd..000000000 --- a/src/main/java/com/microsoft/graph/http/BaseActionCollectionRequestBuilder.java +++ /dev/null @@ -1,41 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.http; - -import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.options.Option; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * The base method request builder class used for POST actions - */ -public class BaseActionCollectionRequestBuilder, - T3 extends ICollectionResponse, - T4 extends BaseCollectionPage>, - T5 extends BaseCollectionRequest> extends BaseCollectionRequestBuilder { - - /** - * Constructs a new {@link BaseActionCollectionRequestBuilder} - * - * @param requestUrl the URL for the request - * @param client the {@link IBaseClient} for handling requests - * @param options {@link List} of {@link Option}s to add to this request - * @param requestBuilderClass the class for the request builder - * @param collectionRequestClass the class for the collection request - */ - public BaseActionCollectionRequestBuilder( - @Nonnull final String requestUrl, - @Nonnull final IBaseClient client, - @Nullable final List options, - @Nonnull final Class requestBuilderClass, - @Nonnull final Class collectionRequestClass - ) { - super(requestUrl, client, options, requestBuilderClass, collectionRequestClass); - } -} diff --git a/src/main/java/com/microsoft/graph/http/BaseActionRequestBuilder.java b/src/main/java/com/microsoft/graph/http/BaseActionRequestBuilder.java deleted file mode 100644 index 17aff1f98..000000000 --- a/src/main/java/com/microsoft/graph/http/BaseActionRequestBuilder.java +++ /dev/null @@ -1,33 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.http; - -import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.options.Option; - -import java.util.List; - -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -/** - * The base method request builder class used for POST actions - */ -public class BaseActionRequestBuilder extends BaseRequestBuilder { - /** - * Constructs a new {@link BaseActionRequestBuilder} - * - * @param requestUrl the URL for the request - * @param client the {@link IBaseClient} for handling requests - * @param options {@link List} of {@link Option}s to add to this request - */ - public BaseActionRequestBuilder( - @Nonnull final String requestUrl, - @Nonnull final IBaseClient client, - @Nullable final List options - ) { - super(requestUrl, client, options); - } -} diff --git a/src/main/java/com/microsoft/graph/http/BaseCollectionPage.java b/src/main/java/com/microsoft/graph/http/BaseCollectionPage.java deleted file mode 100644 index 4d72bf0a1..000000000 --- a/src/main/java/com/microsoft/graph/http/BaseCollectionPage.java +++ /dev/null @@ -1,139 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2017 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.http; - -import com.google.gson.JsonObject; -import com.microsoft.graph.serializer.AdditionalDataManager; -import com.microsoft.graph.serializer.ISerializer; -import com.microsoft.graph.serializer.IJsonBackedObject; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -/** - * A page of results from a collection - * - * @param the type of the item contained within the collection - */ -public class BaseCollectionPage> implements IJsonBackedObject { - - private AdditionalDataManager additionalDataManager = new AdditionalDataManager(this); - - /** - * The contents of this page - */ - private final List pageContents; - - /** - * The request builder for the next page - */ - private final T2 requestBuilder; - - /** - * A collection page for WorkforceIntegration - * - * @param response the serialized WorkforceIntegrationCollectionResponse from the service - * @param builder the request builder for the next collection page - */ - public BaseCollectionPage(@Nonnull final ICollectionResponse response, @Nullable final T2 builder) { - this(response.values(), builder, response.additionalDataManager()); - } - - /** - * Creates the collection page - * - * @param pageContents the contents of this page - * @param nextRequestBuilder the request builder for the next page - */ - public BaseCollectionPage(@Nonnull final List pageContents, @Nullable final T2 nextRequestBuilder) { - // CollectionPages are never directly modifiable, either 'update'/'delete' the specific child or 'add' the new - // object to the 'children' of the collection. - this.pageContents = Collections.unmodifiableList(pageContents == null ? new ArrayList<>() : pageContents); - requestBuilder = nextRequestBuilder; - } - - /** - * Creates the collection page - * - * @param pageContents the contents of this page - * @param nextRequestBuilder the request builder for the next page - * @param responseAdditionalData the additional data returned by the response - */ - public BaseCollectionPage(@Nonnull final List pageContents, @Nullable final T2 nextRequestBuilder, @Nonnull final AdditionalDataManager responseAdditionalData) { - this(pageContents, nextRequestBuilder); - this.additionalDataManager().putAll(responseAdditionalData); - } - - /** - * Gets the next page request builder - * - * @return the next page request builder - */ - @Nullable - public T2 getNextPage() { - return requestBuilder; - } - - /** - * Gets the current page - * - * @return the current page - */ - @Nonnull - public List getCurrentPage() { - return new ArrayList<>(pageContents); - } - - /** - * Sets the raw JSON object - * - * @param serializer the serializer - * @param json the JSON object to set this object to - */ - public void setRawObject(@Nonnull final ISerializer serializer, @Nonnull final JsonObject json) { - } - - @Override - @Nullable - @SuppressFBWarnings - public final AdditionalDataManager additionalDataManager() { - return additionalDataManager; - } - - private final static String odataCountKey = "@odata.count"; - /** - * Returns the odata count value if it has been requested, null otherwise - * @return the odata count value if it has been requested, null otherwise - */ - @Nullable - public final Long getCount() { - return additionalDataManager == null || !additionalDataManager.containsKey(odataCountKey) || !additionalDataManager.get(odataCountKey).isJsonPrimitive() ? - null : - additionalDataManager.get(odataCountKey).getAsLong(); - } -} diff --git a/src/main/java/com/microsoft/graph/http/BaseCollectionReferenceRequestBuilder.java b/src/main/java/com/microsoft/graph/http/BaseCollectionReferenceRequestBuilder.java deleted file mode 100644 index ae833394c..000000000 --- a/src/main/java/com/microsoft/graph/http/BaseCollectionReferenceRequestBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2017 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.http; - -import com.microsoft.graph.core.IBaseClient; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** - * A request builder - */ -public class BaseCollectionReferenceRequestBuilder, - T3 extends ICollectionResponse, - T4 extends BaseCollectionPage>, - T5 extends BaseEntityCollectionRequest> extends BaseCollectionRequestBuilder { - /** - * The request builder for this collection - * - * @param requestUrl the request URL - * @param client the service client - * @param requestOptions the options for this request - * @param requestBuilderClass the class for the request builder - * @param collectionRequestClass the class for the collection request - */ - public BaseCollectionReferenceRequestBuilder(@Nonnull final String requestUrl, @Nonnull final IBaseClient client, @Nullable final java.util.List requestOptions, - @Nonnull final Class requestBuilderClass, - @Nonnull final Class collectionRequestClass) { - super(requestUrl, client, requestOptions, requestBuilderClass, collectionRequestClass); - } -} diff --git a/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java b/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java deleted file mode 100644 index 090a2ab89..000000000 --- a/src/main/java/com/microsoft/graph/http/BaseCollectionRequest.java +++ /dev/null @@ -1,449 +0,0 @@ -// ------------------------------------------------------------------------------ -// Copyright (c) 2017 Microsoft Corporation -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// ------------------------------------------------------------------------------ - -package com.microsoft.graph.http; - -import java.net.URL; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import javax.annotation.Nullable; -import javax.annotation.Nonnull; - -import com.microsoft.graph.core.ClientException; -import com.microsoft.graph.core.IBaseClient; -import com.microsoft.graph.httpcore.middlewareoption.IShouldRedirect; -import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry; -import com.microsoft.graph.options.FunctionOption; -import com.microsoft.graph.options.HeaderOption; -import com.microsoft.graph.options.Option; -import com.microsoft.graph.options.QueryOption; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; - -/** - * A request against a collection - * - * @param the type of the object in the collection - * @param the response collection type - * @param the collection page type - */ -public abstract class BaseCollectionRequest, - T3 extends BaseCollectionPage>> implements IHttpRequest { - - /** - * The base request for this collection request - */ - private final BaseRequest baseRequest; - - /** - * The class for the response collection - */ - protected final Class responseCollectionClass; - - /** - * The class for the collection page - */ - private final Class collectionPageClass; - - private final Class, T2, T3, ? extends BaseCollectionRequest>> collRequestBuilderClass; - - - /** - * Create the collection request - * - * @param requestUrl the URL to make the request against - * @param client the client which can issue the request - * @param options the options for this request - * @param responseCollectionClass the class for the response collection - * @param collectionPageClass the class for the collection page - * @param collectionRequestBuilderClass the class for the collection request builder - */ - public BaseCollectionRequest(@Nonnull final String requestUrl, - @Nonnull final IBaseClient client, - @Nullable final List options, - @Nonnull final Class responseCollectionClass, - @Nonnull final Class collectionPageClass, - @Nonnull final Class, T2, T3, ? extends BaseCollectionRequest>> collectionRequestBuilderClass) { - this.responseCollectionClass = Objects.requireNonNull(responseCollectionClass, "parameter responseCollectionClass cannot be null"); - this.collectionPageClass = Objects.requireNonNull(collectionPageClass, "parameter collectionPageClass cannot be null"); - this.collRequestBuilderClass = Objects.requireNonNull(collectionRequestBuilderClass, "parameter collectionRequestBuilderClass cannot be null"); - baseRequest = new BaseRequest(requestUrl, client, options, responseCollectionClass) {}; - } - - /** - * Send this request - * - * @return the response object - * @throws ClientException an exception occurs if there was an error while the request was sent - */ - @Nullable - protected T2 send() throws ClientException { - baseRequest.setHttpMethod(HttpMethod.GET); - return baseRequest.getClient().getHttpProvider().send(this, responseCollectionClass, null); - } - /** - * Send this request - * - * @return the response object - * @throws ClientException an exception occurs if there was an error while the request was sent - */ - @Nullable - protected java.util.concurrent.CompletableFuture sendAsync() throws ClientException { - baseRequest.setHttpMethod(HttpMethod.GET); - return baseRequest.getClient().getHttpProvider().sendAsync(this, responseCollectionClass, null); - } - - /** - * Deserializes the collection from the response object - * - * @param response the collection response - * @return the collection page - */ - @Nullable - public T3 buildFromResponse(@Nonnull final T2 response) { - Objects.requireNonNull(response, "parameter response cannot be null"); - try { - final Object builder = response.nextLink() == null ? null : this.collRequestBuilderClass - .getConstructor(String.class, IBaseClient.class, java.util.List.class) - .newInstance(response.nextLink(), getBaseRequest().getClient(), Collections.emptyList()); - final T3 page = (T3)this.collectionPageClass.getConstructor(response.getClass(), this.collRequestBuilderClass).newInstance(response, builder); - return page; - } catch(IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException ex) { - throw new ClientException("Could not find the required class", ex); - } - } - - /** - * Gets the request URL - * - * @return the request URL - */ - @Override - @Nonnull - public URL getRequestUrl() { - return baseRequest.getRequestUrl(); - } - - /** - * Gets the HTTP method - * - * @return the HTTP method - */ - @Override - @Nullable - public HttpMethod getHttpMethod() { - return baseRequest.getHttpMethod(); - } - - /** - * Gets the headers - * - * @return the headers - */ - @Override - @Nullable - public List getHeaders() { - return baseRequest.getHeaders(); - } - - /** - * Adds a header to this request - * - * @param header the name of the header - * @param value the value of the header - */ - @Override - public void addHeader(@Nonnull final String header, @Nullable final String value) { - Objects.requireNonNull(header, "parameter header cannot be null"); - baseRequest.addHeader(header, value); - } - - /** - * Sets useCaches parameter to cache the response - * - * @param useCaches the value of useCaches - */ - @Override - public void setUseCaches(boolean useCaches) { - baseRequest.setUseCaches(useCaches); - } - - /** - * Gets useCaches parameter - * - * @return the value of useCaches - */ - @Override - public boolean getUseCaches() { - return baseRequest.getUseCaches(); - } - - /** - * Gets the full list of options for this request - * - * @return the full list of options for this request - */ - @Nullable - public List