diff --git a/.github/workflows/api-level-lint.yml b/.github/workflows/api-level-lint.yml index 5fdc02ebd..cf0413555 100644 --- a/.github/workflows/api-level-lint.yml +++ b/.github/workflows/api-level-lint.yml @@ -14,13 +14,13 @@ jobs: lint-api-level: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2.3.4 - uses: actions/setup-java@v2 with: distribution: 'adopt' java-version: 16 - name: Setup Android SDK - uses: android-actions/setup-android@v2 + uses: android-actions/setup-android@v2.0.7 - name: Add execution right to the script run: chmod +x gradlew working-directory: ./android diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7ed1ab092..7d984b319 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/sample-build-check.yml b/.github/workflows/sample-build-check.yml index 960d89731..be4146069 100644 --- a/.github/workflows/sample-build-check.yml +++ b/.github/workflows/sample-build-check.yml @@ -10,7 +10,7 @@ jobs: samples-build-check-device-code: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2.3.4 - uses: actions/setup-java@v2 with: distribution: 'adopt' @@ -24,7 +24,7 @@ jobs: samples-build-check-interactive: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2.3.4 - uses: actions/setup-java@v2 with: distribution: 'adopt' diff --git a/gradle.properties b/gradle.properties index 93527857c..f3c38535b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 2 mavenMinorVersion = 0 -mavenPatchVersion = 2 +mavenPatchVersion = 3 mavenArtifactSuffix = #These values are used to run functional tests diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 23858b144..fac6a9c11 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -1,13 +1,13 @@ dependencies { // Use JUnit test framework - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1' - testImplementation 'org.mockito:mockito-inline:3.9.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' + testImplementation 'org.mockito:mockito-inline:3.10.0' api 'com.squareup.okhttp3:okhttp:4.9.1' implementation 'com.google.guava:guava:30.1.1-jre' - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' api 'com.azure:azure-core:1.16.0' } \ No newline at end of file diff --git a/pom.xml b/pom.xml index d0659c0cc..7984c278d 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ com.google.code.gson gson - 2.8.6 + 2.8.7 com.google.guava @@ -40,13 +40,13 @@ org.junit.jupiter junit-jupiter-api - 5.7.1 + 5.7.2 test org.mockito mockito-inline - 3.9.0 + 3.10.0 test diff --git a/readme.md b/readme.md index 41f48045e..815a9d2af 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ repositories { dependencies { // Include the sdk as a dependency - implementation 'com.microsoft.graph:microsoft-graph-core:2.0.2' + implementation 'com.microsoft.graph:microsoft-graph-core:2.0.3' // This dependency is only needed if you are using the TokenCrendentialAuthProvider implementation 'com.azure:azure-identity:1.2.5' } @@ -35,7 +35,7 @@ Add the dependency in `dependencies` in pom.xml com.microsoft.graph microsoft-graph-core - 2.0.2 + 2.0.3 com.azure azure-identity diff --git a/src/main/java/com/microsoft/graph/content/BatchResponseStep.java b/src/main/java/com/microsoft/graph/content/BatchResponseStep.java index feb1d13a1..659761385 100644 --- a/src/main/java/com/microsoft/graph/content/BatchResponseStep.java +++ b/src/main/java/com/microsoft/graph/content/BatchResponseStep.java @@ -33,6 +33,9 @@ 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 */ @@ -61,7 +64,13 @@ public T2 getDeserializedBody(@Nonnull final Class resultClass) throws final GraphErrorResponse error = serializer.deserializeObject((JsonElement)body, GraphErrorResponse.class); if(error == null || error.error == null) { return serializer.deserializeObject((JsonElement)body, resultClass); - } else - throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, false); + } 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/http/BaseCollectionRequestBuilder.java b/src/main/java/com/microsoft/graph/http/BaseCollectionRequestBuilder.java index 977fc8255..eb2239a39 100644 --- a/src/main/java/com/microsoft/graph/http/BaseCollectionRequestBuilder.java +++ b/src/main/java/com/microsoft/graph/http/BaseCollectionRequestBuilder.java @@ -46,7 +46,7 @@ public BaseCollectionRequestBuilder(@Nonnull final String requestUrl, @Nonnull f * @param requestOptions the options for this request * @return the IUserRequest instance */ - @Nullable + @Nonnull public T5 buildRequest(@Nullable final com.microsoft.graph.options.Option... requestOptions) { return buildRequest(getOptions(requestOptions)); } @@ -57,7 +57,7 @@ public T5 buildRequest(@Nullable final com.microsoft.graph.options.Option... req * @param requestOptions the options for this request * @return the IUserRequest instance */ - @Nullable + @Nonnull public T5 buildRequest(@Nullable final java.util.List requestOptions) { try { return collRequestClass.getConstructor(String.class, IBaseClient.class, java.util.List.class) diff --git a/src/main/java/com/microsoft/graph/http/BaseReferenceRequestBuilder.java b/src/main/java/com/microsoft/graph/http/BaseReferenceRequestBuilder.java index 0f584c462..ccb81c043 100644 --- a/src/main/java/com/microsoft/graph/http/BaseReferenceRequestBuilder.java +++ b/src/main/java/com/microsoft/graph/http/BaseReferenceRequestBuilder.java @@ -57,7 +57,7 @@ public BaseReferenceRequestBuilder(@Nonnull final String requestUrl, @Nonnull fi * @param requestOptions the options for this request * @return The ReferenceRequest instance */ - @Nullable + @Nonnull public T2 buildRequest(@Nullable final com.microsoft.graph.options.Option... requestOptions) { return buildRequest(getOptions(requestOptions)); } @@ -68,7 +68,7 @@ public T2 buildRequest(@Nullable final com.microsoft.graph.options.Option... req * @param requestOptions the options for this request * @return the ReferenceRequest instance */ - @Nullable + @Nonnull public T2 buildRequest(@Nullable final java.util.List requestOptions) { try { return refRequestClass.getConstructor(String.class, IBaseClient.class, java.util.List.class) diff --git a/src/main/java/com/microsoft/graph/http/BaseWithReferenceRequestBuilder.java b/src/main/java/com/microsoft/graph/http/BaseWithReferenceRequestBuilder.java index b1ffe4d09..a6132c512 100644 --- a/src/main/java/com/microsoft/graph/http/BaseWithReferenceRequestBuilder.java +++ b/src/main/java/com/microsoft/graph/http/BaseWithReferenceRequestBuilder.java @@ -63,7 +63,7 @@ public BaseWithReferenceRequestBuilder(@Nonnull final String requestUrl, @Nonnul * @param requestOptions the options for this request * @return the ReferenceRequest instance */ - @Nullable + @Nonnull public T2 buildRequest(@Nullable final com.microsoft.graph.options.Option... requestOptions) { return buildRequest(getOptions(requestOptions)); } @@ -74,7 +74,7 @@ public T2 buildRequest(@Nullable final com.microsoft.graph.options.Option... req * @param requestOptions the options for this request * @return the ReferenceRequest instance */ - @Nullable + @Nonnull public T2 buildRequest(@Nullable final java.util.List requestOptions) { try { return wReferenceRequestClass.getConstructor(String.class, IBaseClient.class, java.util.List.class) diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index 0d8f04962..a8f18be66 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -25,7 +25,7 @@ public class TelemetryHandler implements Interceptor{ /** * Current SDK version */ - public static final String VERSION = "v2.0.2"; + public static final String VERSION = "v2.0.3"; /** * Verion prefix */ diff --git a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java index bf520e224..ec9f7999c 100644 --- a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java +++ b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java @@ -393,7 +393,6 @@ public Class getDerivedClass(@Nonnull final JsonObject jsonObject, @Nullable * * @return a logger */ - @VisibleForTesting @Nullable public ILogger getLogger() { return logger; diff --git a/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java b/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java index 6414b7252..a39b9255b 100644 --- a/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java +++ b/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java @@ -14,7 +14,9 @@ import com.google.gson.JsonElement; import com.microsoft.graph.http.GraphErrorResponse; import com.microsoft.graph.http.GraphServiceException; +import com.microsoft.graph.logger.DefaultLogger; import com.microsoft.graph.logger.ILogger; +import com.microsoft.graph.logger.LoggerLevel; import com.microsoft.graph.serializer.DefaultSerializer; import com.microsoft.graph.serializer.ISerializer; @@ -114,4 +116,52 @@ public void deserializesErrorsProperly() { } else fail("batch response was null"); } + @Test + public void includeVerboseInformation() { + String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}"; + ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{ + setLoggingLevel(LoggerLevel.DEBUG); + }}); + BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class); + if(batchresponse != null) { + if(batchresponse.responses != null) // this is done by the batch request in the fluent API + for(final BatchResponseStep step : batchresponse.responses) { + step.serializer = serializer; + } + try { + batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class); + } catch(GraphServiceException ex) { + final GraphErrorResponse response = ex.getError(); + assertNotNull(response); + assertNotNull(response.error); + assertNotNull(response.error.message); + assertEquals(ex.getMessage(true), ex.getMessage()); + } + } else + fail("batch response was null"); + } + @Test + public void doesNotIncludeVerboseInformation() { + String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}"; + ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{ + setLoggingLevel(LoggerLevel.ERROR); + }}); + BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class); + if(batchresponse != null) { + if(batchresponse.responses != null) // this is done by the batch request in the fluent API + for(final BatchResponseStep step : batchresponse.responses) { + step.serializer = serializer; + } + try { + batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class); + } catch(GraphServiceException ex) { + final GraphErrorResponse response = ex.getError(); + assertNotNull(response); + assertNotNull(response.error); + assertNotNull(response.error.message); + assertEquals(ex.getMessage(false), ex.getMessage()); + } + } else + fail("batch response was null"); + } }