Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import javax.annotation.Nonnull;

/**
* An implementation of the Authentication Provider with Azure-identity
*/
Expand All @@ -27,7 +27,7 @@ public class TokenCredentialAuthProvider extends BaseAuthenticationProvider {
* @param tokenCredential Credential object inheriting the TokenCredential interface used to instantiate the Auth Provider
*/
public TokenCredentialAuthProvider(@Nonnull final TokenCredential tokenCredential) {
this(Arrays.asList(DEFAULT_GRAPH_SCOPE), tokenCredential);
this(Collections.singletonList(DEFAULT_GRAPH_SCOPE), tokenCredential);
}

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ public CompletableFuture<String> getAuthorizationTokenAsync(@Nonnull final URL r
return this.tokenCredential
.getToken(this.context)
.toFuture()
.thenApply(resp -> resp.getToken());
.thenApply(AccessToken::getToken);
else
return CompletableFuture.completedFuture((String)null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public <T> String addBatchRequestStep(@Nonnull final IHttpRequest request, @Nonn
url = protocolAndHostReplacementMatcher.replaceAll("");
body = serializableBody;
method = httpMethod.toString().toUpperCase(Locale.getDefault());
dependsOn = dependsOnRequestsIds != null && dependsOnRequestsIds.length > 0 ? new HashSet<String>(Arrays.asList(dependsOnRequestsIds)) : null;
dependsOn = dependsOnRequestsIds != null && dependsOnRequestsIds.length > 0 ? new HashSet<>(Arrays.asList(dependsOnRequestsIds)) : null;
id = getNextRequestId();
}};

Expand Down Expand Up @@ -141,7 +141,7 @@ public void removeBatchRequestStepWithId(@Nonnull final String ...stepIds) {
requests.removeIf(x -> stepId.equals(x.id));
for(final BatchRequestStep<?> step : requests) {
if(step.dependsOn != null) {
step.dependsOn.removeIf(x -> stepId.equals(x));
step.dependsOn.removeIf(stepId::equals);
if(step.dependsOn.isEmpty())
step.dependsOn = null; // so we don't send dependsOn: [] over the wire
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public CustomRequest<T> buildRequest(@Nullable final com.microsoft.graph.options
*/
@Nonnull
public CustomRequest<T> buildRequest(@Nullable final List<? extends Option> requestOptions) {
return new CustomRequest<T>(getRequestUrl(), getClient(), requestOptions, responseType);
return new CustomRequest<>(getRequestUrl(), getClient(), requestOptions, responseType);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/graph/core/IBaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public interface IBaseClient<nativeRequestType> {
* @return a request builder to execute a batch.
*/
@Nonnull
public BatchRequestBuilder batch();
BatchRequestBuilder batch();

/**
* Gets the service SDK version if the service SDK is in use, null otherwise
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/microsoft/graph/core/Multipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Multipart {
*/
public Multipart() {
out = new ByteArrayOutputStream();
boundary = "part_" + new BigInteger(130, new SecureRandom()).toString();
boundary = "part_" + new BigInteger(130, new SecureRandom());
}

/**
Expand Down Expand Up @@ -125,7 +125,7 @@ public static String createContentHeaderValue(@Nonnull final String contentValue

if(contentDispParameter != null) {
for(Map.Entry<String,String> entry : contentDispParameter.entrySet())
builder.append(";" + entry.getKey() + "=\"" + entry.getValue() + "\"");
builder.append(";").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
}
return builder.toString();
}
Expand All @@ -140,7 +140,7 @@ private String createPartHeader(Map<String, String> headers) {

if(headers != null) {
for(Map.Entry<String,String> entry : headers.entrySet())
builder.append(entry.getKey() +": "+entry.getValue() + RETURN);
builder.append(entry.getKey()).append(": ").append(entry.getValue()).append(RETURN);
builder.append(RETURN);
} else
builder.append(defaultPartContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public java.util.concurrent.CompletableFuture<T3> postAsync() {
.sendAsync(this,
responseCollectionClass,
bodyToSend)
.thenApply(r -> buildFromResponse(r));
.thenApply(this::buildFromResponse);
}
/**
* Invokes the method and returns the resulting collection of objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public BaseCollectionPage(@Nonnull final ICollectionResponse<T> response, @Nulla
public BaseCollectionPage(@Nonnull final List<T> 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<T>() : pageContents);
this.pageContents = Collections.unmodifiableList(pageContents == null ? new ArrayList<>() : pageContents);
requestBuilder = nextRequestBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BaseEntityCollectionRequest(@Nonnull final String requestUrl,
*/
@Nonnull
public java.util.concurrent.CompletableFuture<T3> getAsync() {
return sendAsync().thenApply(r -> buildFromResponse(r));
return sendAsync().thenApply(this::buildFromResponse);
}
/**
* Gets the collection of items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BaseFunctionCollectionRequest(@Nonnull final String requestUrl,
*/
@Nonnull
public java.util.concurrent.CompletableFuture<T3> getAsync() {
return sendAsync().thenApply(r -> buildFromResponse(r));
return sendAsync().thenApply(this::buildFromResponse);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/microsoft/graph/http/BaseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ public URL getRequestUrl() {
return new URL(uriBuilder.build().toString());
} catch (final MalformedURLException e) {
if (this instanceof CustomRequest) {
this.getClient().getLogger().logError("Invalid custom URL: " + uriBuilder.toString(), e);
this.getClient().getLogger().logError("Invalid custom URL: " + uriBuilder, e);
} else {
throw new ClientException("Invalid URL: " + uriBuilder.toString(), e);
throw new ClientException("Invalid URL: " + uriBuilder, e);
}
}
return null;
Expand Down Expand Up @@ -228,7 +228,7 @@ private String addFunctionParameters() {
requestUrl.append("=");
if (option.getValue() != null) {
if (option.getValue() instanceof String) {
requestUrl.append("'" + option.getValue() + "'");
requestUrl.append("'").append(option.getValue()).append("'");
} else {
requestUrl.append(option.getValue());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/graph/http/CustomRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CustomRequest(@Nonnull final String requestUrl, @Nonnull final IBaseClien
*/
@Nonnull
public static CustomRequest<JsonObject> create(@Nonnull final String requestUrl, @Nonnull final IBaseClient<?> client, @Nullable final java.util.List<? extends Option> requestOptions) {
return new CustomRequest<JsonObject>(requestUrl, client, requestOptions, JsonObject.class);
return new CustomRequest<>(requestUrl, client, requestOptions, JsonObject.class);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/microsoft/graph/http/GraphInnerError.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// ------------------------------------------------------------------------------
// 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
Expand All @@ -25,7 +25,6 @@
import com.google.gson.annotations.SerializedName;

import javax.annotation.Nullable;
import javax.annotation.Nonnull;

/**
* Represents an inner error returned by the service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public Response intercept(@Nonnull final Chain chain) throws IOException {
.build());
}
} catch (InterruptedException | ExecutionException ex) {
if (ex instanceof InterruptedException)
Thread.currentThread().interrupt();
throw new IOException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.concurrent.ThreadLocalRandom;

import javax.annotation.Nullable;
import javax.annotation.Nonnull;

import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType;
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/microsoft/graph/httpcore/HttpClients.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.microsoft.graph.httpcore;

import com.microsoft.graph.authentication.IAuthenticationProvider;

import java.util.Arrays;
import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.Nonnull;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.OkHttpClient.Builder;
import okhttp3.Protocol;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Objects;

/**
* Builder to get a custom HttpClient to be used for requests against Microsoft Graph
Expand All @@ -33,7 +31,7 @@ public static Builder custom() {
.addInterceptor(new TelemetryHandler())
.followRedirects(false)
.followSslRedirects(false)
.protocols(Arrays.asList(Protocol.HTTP_1_1)); //https://stackoverflow.com/questions/62031298/sockettimeout-on-java-11-but-not-on-java-8
.protocols(Collections.singletonList(Protocol.HTTP_1_1)); //https://stackoverflow.com/questions/62031298/sockettimeout-on-java-11-but-not-on-java-8
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ && checkStatus(statusCode) && isBuffered(request)
try {
Thread.sleep(retryInterval);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.logError("error retrying the request", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Objects;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -57,8 +58,8 @@ public Response intercept(@Nonnull final Chain chain) throws IOException {
final String javaVersion = System.getProperty("java.version");
final String androidVersion = getAndroidAPILevel();
final String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage +
(javaVersion == DEFAULT_VERSION_VALUE ? "" : (", " + JAVA_VERSION_PREFIX + "/" + javaVersion)) +
(androidVersion == DEFAULT_VERSION_VALUE ? "" : (", " + ANDROID_VERSION_PREFIX + "/" + androidVersion));
(DEFAULT_VERSION_VALUE.equals(javaVersion) ? "" : (", " + JAVA_VERSION_PREFIX + "/" + javaVersion)) +
(DEFAULT_VERSION_VALUE.equals(androidVersion) ? "" : (", " + ANDROID_VERSION_PREFIX + "/" + androidVersion));
telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value);

if(request.header(CLIENT_REQUEST_ID) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ public class RedirectOptions implements IMiddlewareControl{
/**
* Default redirect evaluation, always follow redirect information.
*/
public static final IShouldRedirect DEFAULT_SHOULD_REDIRECT = new IShouldRedirect() {
@Override
public boolean shouldRedirect(Response response) {
return true;
}
};
public static final IShouldRedirect DEFAULT_SHOULD_REDIRECT = response -> true;

/**
* Create default instance of redirect options, with default values of max redirects and should redirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ public class RetryOptions implements IMiddlewareControl {
/**
* Default retry evaluation, always retry.
*/
public static final IShouldRetry DEFAULT_SHOULD_RETRY = new IShouldRetry() {
@Override
public boolean shouldRetry(long delay, int executionCount, Request request, Response response) {
return true;
}
};
public static final IShouldRetry DEFAULT_SHOULD_RETRY = (delay, executionCount, request, response) -> true;

private int mMaxRetries;
/**
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -98,7 +99,7 @@ public <T> T deserializeObject(@Nonnull final String inputString, @Nonnull final
public <T> T deserializeObject(@Nonnull final InputStream inputStream, @Nonnull final Class<T> clazz, @Nullable final Map<String, List<String>> responseHeaders) {
Objects.requireNonNull(inputStream, "parameter inputStream cannot be null");
T result = null;
try (final InputStreamReader streamReader = new InputStreamReader(inputStream, "UTF-8")) {
try (final InputStreamReader streamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
final JsonElement rawElement = gson.fromJson(streamReader, JsonElement.class);
result = deserializeObject(rawElement, clazz, responseHeaders);
} catch (IOException ex) {
Expand Down Expand Up @@ -155,24 +156,22 @@ private void setChildAdditionalData(final IJsonBackedObject serializedObject, fi
// If the object is a HashMap, iterate through its children
@SuppressWarnings("unchecked")
final HashMap<String, Object> serializableChildren = (HashMap<String, Object>) fieldObject;
final Iterator<Entry<String, Object>> it = serializableChildren.entrySet().iterator();

while (it.hasNext()) {
final Map.Entry<String, Object> pair = (Map.Entry<String, Object>)it.next();
final Object child = pair.getValue();
for (Entry<String, Object> pair : serializableChildren.entrySet()) {
final Object child = pair.getValue();

// If the item is a valid Graph object, set its additional data
if (child instanceof IJsonBackedObject) {
final AdditionalDataManager childAdditionalDataManager = ((IJsonBackedObject) child).additionalDataManager();
final JsonElement fieldElement = rawJson.get(field.getName());
if(fieldElement != null && fieldElement.isJsonObject()
&& fieldElement.getAsJsonObject().get(pair.getKey()) != null
&& fieldElement.getAsJsonObject().get(pair.getKey()).isJsonObject()) {
childAdditionalDataManager.setAdditionalData(fieldElement.getAsJsonObject().get(pair.getKey()).getAsJsonObject());
setChildAdditionalData((IJsonBackedObject) child,fieldElement.getAsJsonObject().get(pair.getKey()).getAsJsonObject());
}
}
}
// If the item is a valid Graph object, set its additional data
if (child instanceof IJsonBackedObject) {
final AdditionalDataManager childAdditionalDataManager = ((IJsonBackedObject) child).additionalDataManager();
final JsonElement fieldElement = rawJson.get(field.getName());
if (fieldElement != null && fieldElement.isJsonObject()
&& fieldElement.getAsJsonObject().get(pair.getKey()) != null
&& fieldElement.getAsJsonObject().get(pair.getKey()).isJsonObject()) {
childAdditionalDataManager.setAdditionalData(fieldElement.getAsJsonObject().get(pair.getKey()).getAsJsonObject());
setChildAdditionalData((IJsonBackedObject) child, fieldElement.getAsJsonObject().get(pair.getKey()).getAsJsonObject());
}
}
}
}
// If the object is a list of Graph objects, iterate through elements
else if (fieldObject instanceof List) {
Expand Down
Loading