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
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.1.0",
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671",
"integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671"
},
"ghcr.io/devcontainers/features/java:1": {
"version": "1.8.0",
"resolved": "ghcr.io/devcontainers/features/java@sha256:9663ce0219ff85786e87901ce5f0a59f488edd5f99b46015192cda48468b233a",
"integrity": "sha256:9663ce0219ff85786e87901ce5f0a59f488edd5f99b46015192cda48468b233a"
},
"ghcr.io/devcontainers/features/node:2": {
"version": "2.0.0",
"resolved": "ghcr.io/devcontainers/features/node@sha256:fedd4c11f7adfb64283b578dddc7da906728daa25fa293351c9d913231acf12f",
"integrity": "sha256:fedd4c11f7adfb64283b578dddc7da906728daa25fa293351c9d913231acf12f"
},
"ghcr.io/devcontainers/features/powershell:2": {
"version": "2.0.2",
"resolved": "ghcr.io/devcontainers/features/powershell@sha256:82ea3880c5706ac3963f1b5e940a7f5871835393a5472f80008148b995d58d61",
"integrity": "sha256:82ea3880c5706ac3963f1b5e940a7f5871835393a5472f80008148b995d58d61"
}
}
}
11 changes: 7 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "Java",
"image": "mcr.microsoft.com/devcontainers/java:17",
"name": "Java 21 & Gradle",
"image": "mcr.microsoft.com/devcontainers/java:21-bookworm",
"features": {
"ghcr.io/devcontainers/features/java:1": {
"version": "none",
"installMaven": "true",
"installGradle": "true"
},
"ghcr.io/devcontainers/features/node:1": {
"ghcr.io/devcontainers/features/node:2": {
"version": "lts"
},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/powershell:1": {}
"ghcr.io/devcontainers/features/powershell:2": {}
},
"containerEnv": {
"WAYLAND_DISPLAY": "disabled"
},
// Configure tool-specific properties.
"customizations": {
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ updates:
open-telemetry:
patterns:
- "*opentelemetry*"
- package-ecosystem: devcontainers
directory: "/.devcontainer"
schedule:
interval: daily
open-pull-requests-limit: 10
13 changes: 13 additions & 0 deletions components/abstractions/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,17 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
<Bug pattern="SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR" />
<Class name="com.microsoft.kiota.store.BackingStoreFactorySingleton" />
</Match>
<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Or>
<Class name="com.microsoft.kiota.ApiExceptionBuilder" />
<Class name="com.microsoft.kiota.BaseRequestBuilder" />
<Class name="com.microsoft.kiota.Headers" />
<Class name="com.microsoft.kiota.RequestInformation" />
<Class name="com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider" />
<Class name="com.microsoft.kiota.authentication.BasicAccessAuthenticationProvider" />
<Class name="com.microsoft.kiota.serialization.ParseNodeProxyFactory" />
<Class name="com.microsoft.kiota.serialization.SerializationWriterProxyFactory" />
</Or>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public <T extends BaseRequestConfiguration> void configure(
@Nullable public String urlTemplate;

/** The path parameters for the current request */
@Nullable public Map<String, Object> pathParameters = new HashMap<>();
@Nonnull public Map<String, Object> pathParameters = new HashMap<>();

private URI uri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void authenticateRequest(
} catch (URISyntaxException e) {
throw new RuntimeException("Malformed URI.", e);
}
if (targetUri == null) {
throw new IllegalStateException("Request URI cannot be null.");
}
String accessToken =
this.accessTokenProvider.getAuthorizationToken(
targetUri, additionalAuthenticationContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -259,6 +260,7 @@ private static InputStream getInputStreamFromString(@Nonnull final String value)
@Nonnull final InputStream stream,
@Nonnull final ParsableFactory<T> parsableFactory) {
final ParseNode parseNode = getRootParseNode(contentType, stream, parsableFactory);
return parseNode.getCollectionOfObjectValues(parsableFactory);
final List<T> values = parseNode.getCollectionOfObjectValues(parsableFactory);
return values != null ? values : new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ void testOptions() {

RequestOption requestOption =
new RequestOption() {
@SuppressWarnings("unchecked")
@Override
public <T extends RequestOption> Class<T> getType() {
return null;
return (Class<T>) RequestOption.class;
}
};
// options should be mutable list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
requestInfo.urlTemplate = "{+baseurl}/users{?%24count}";

// Act
assertNotNull(requestInfo.pathParameters);
requestInfo.pathParameters.put("baseurl", "http://localhost");

// Assert
Expand Down Expand Up @@ -101,8 +102,8 @@
requestInfo.urlTemplate =
"http://localhost/getCalendarView(startLocalDate='{startLocalDate}',endLocalDate='{endLocalDate}')";

final LocalDate startLocalDate = LocalDate.of(2022, 8, 1);

Check warning on line 105 in components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a "java.time.Month" enum constant instead of this int literal.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ6xtOlww99KUS_gzpsk&open=AZ6xtOlww99KUS_gzpsk&pullRequest=2124
final LocalDate endLocalDate = LocalDate.of(2022, 8, 2);

Check warning on line 106 in components/abstractions/src/test/java/com/microsoft/kiota/RequestInformationTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a "java.time.Month" enum constant instead of this int literal.

See more on https://sonarcloud.io/project/issues?id=microsoft_kiota-java&issues=AZ6xtOlww99KUS_gzpsl&open=AZ6xtOlww99KUS_gzpsl&pullRequest=2124

requestInfo.pathParameters.put("startLocalDate", startLocalDate);
requestInfo.pathParameters.put("endLocalDate", endLocalDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ void TestsBackingStoreUpdateToItemInNestedCollectionWithAnotherBackedModel() {
manager.setId("2fe22fe5-1132-42cf-90f9-1dc17e325a74");
manager.getBackingStore().setIsInitializationCompleted(true);
var collectionValues = testUserCollectionResponse.getValue();
assertNotNull(collectionValues);
collectionValues.get(0).setManager(manager);

// Assert by retrieving only changed values
Expand Down Expand Up @@ -504,7 +505,9 @@ void testInitializationCompletedIsPropagatedToCollectionItems() {
testUser.setValue(colleagues);

testUser.getBackingStore().setIsInitializationCompleted(true);
for (TestEntity colleague : testUser.getValue()) {
final var values = testUser.getValue();
assertNotNull(values);
for (TestEntity colleague : values) {
assertTrue(colleague.getBackingStore().getIsInitializationCompleted());
}
}
Expand Down
8 changes: 8 additions & 0 deletions components/authentication/azure/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
<Bug pattern="EI_EXPOSE_REP" />
<Class name="com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider" />
</Match>
<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Class name="com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider" />
</Match>
<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Class name="com.microsoft.kiota.authentication.AzureIdentityAccessTokenProviderTest" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void testLocalhostHttpUrlIsValid(String urlString) throws URISyntaxException {
var tokenCredential = mock(TokenCredential.class);
when(tokenCredential.getTokenSync(any(TokenRequestContext.class)))
.thenReturn(new AccessToken("token", null));
var accessTokenProvider = new AzureIdentityAccessTokenProvider(tokenCredential, null, "");
var accessTokenProvider =
new AzureIdentityAccessTokenProvider(tokenCredential, new String[] {}, "");
assertEquals(
"token",
accessTokenProvider.getAuthorizationToken(new URI(urlString), new HashMap<>()));
Expand All @@ -42,7 +43,8 @@ void testLocalhostHttpUrlIsValid(String urlString) throws URISyntaxException {
@ValueSource(strings = {"http://graph.microsoft.com/me"})
void testNonLocalhostHttpUrlIsInvalid(String urlString) {
var tokenCredential = mock(TokenCredential.class);
var accessTokenProvider = new AzureIdentityAccessTokenProvider(tokenCredential, null, "");
var accessTokenProvider =
new AzureIdentityAccessTokenProvider(tokenCredential, new String[] {}, "");
assertThrows(
IllegalArgumentException.class,
() ->
Expand Down
11 changes: 11 additions & 0 deletions components/http/okHttp/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,15 @@
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Class name="com.microsoft.kiota.http.middleware.UserAgentHandlerTest" />
</Match>
<Match>
<Bug pattern="CT_CONSTRUCTOR_THROW" />
<Or>
<Class name="com.microsoft.kiota.http.OkHttpRequestAdapter" />
<Class name="com.microsoft.kiota.http.middleware.AuthorizationHandler" />
<Class name="com.microsoft.kiota.http.middleware.HeadersInspectionHandler" />
<Class name="com.microsoft.kiota.http.middleware.ParametersNameDecodingHandler" />
<Class name="com.microsoft.kiota.http.middleware.UrlReplaceHandler" />
<Class name="com.microsoft.kiota.http.middleware.options.UrlReplaceHandlerOption" />
</Or>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -879,17 +879,22 @@ private void setBaseUrlForRequestInformation(@Nonnull final RequestInformation r
.setParent(Context.current().with(parentSpan))
.startSpan();
try (final Scope scope = span.makeCurrent()) {
spanForAttributes.setAttribute(HTTP_REQUEST_METHOD, requestInfo.httpMethod.toString());
final URL requestURL = requestInfo.getUri().toURL();
final HttpMethod requestMethod =
Objects.requireNonNull(requestInfo.httpMethod, "httpMethod cannot be null");
spanForAttributes.setAttribute(HTTP_REQUEST_METHOD, requestMethod.toString());
final java.net.URI requestUri =
Objects.requireNonNull(requestInfo.getUri(), "request URI cannot be null");
final URL requestURL = requestUri.toURL();
if (obsOptions.getIncludeEUIIAttributes()) {
spanForAttributes.setAttribute(URL_FULL, requestURL.toString());
}
spanForAttributes.setAttribute(SERVER_PORT, requestURL.getPort());
spanForAttributes.setAttribute(SERVER_ADDRESS, requestURL.getHost());
spanForAttributes.setAttribute(URL_SCHEME, requestURL.getProtocol());

final InputStream requestContent = requestInfo.content;
RequestBody body =
requestInfo.content == null
requestContent == null
? null
: new RequestBody() {
@Override
Expand All @@ -910,7 +915,8 @@ public MediaType contentType() {

@Override
public boolean isOneShot() {
return !requestInfo.content.markSupported();
return requestContent == null
|| !requestContent.markSupported();
}

@Override
Expand All @@ -924,9 +930,9 @@ public long contentLength() throws IOException {
}
// super.contentLength() is not relied on since it defaults to
// -1L, causing wrong telemetry added to the attributes.
if (requestInfo.content instanceof ByteArrayInputStream) {
if (requestContent instanceof ByteArrayInputStream) {
final ByteArrayInputStream contentStream =
(ByteArrayInputStream) requestInfo.content;
(ByteArrayInputStream) requestContent;
// using available() on a byte-array backed input stream is
// reliable because array size is defined.
return contentStream.available();
Expand All @@ -936,14 +942,14 @@ public long contentLength() throws IOException {

@Override
public void writeTo(@Nonnull BufferedSink sink) throws IOException {
long contentLength = contentLength();
final long contentLength = contentLength();
if (contentLength > 0) {
requestInfo.content.mark((int) contentLength);
requestContent.mark((int) contentLength);
}
sink.writeAll(Okio.source(requestInfo.content));
sink.writeAll(Okio.source(requestContent));
if (!isOneShot()) {
try {
requestInfo.content.reset();
requestContent.reset();
} catch (Exception ex) {
spanForAttributes.recordException(ex);
// we don't want to fail the request if reset() fails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ boolean retryRequest(
int executionCount,
@Nonnull final Request request,
@Nonnull final RetryHandlerOption retryOption,
@Nonnull final Span span) {
@Nullable final Span span) {

// Should retry option
// Use should retry common for all requests
Expand All @@ -110,7 +110,9 @@ && isBuffered(request)

if (shouldRetry) {
long retryInterval = getRetryAfter(response, retryOption.delay(), executionCount);
span.setAttribute(HTTP_REQUEST_RESEND_DELAY, Math.round(retryInterval / 1000f));
if (span != null) {
span.setAttribute(HTTP_REQUEST_RESEND_DELAY, Math.round(retryInterval / 1000f));
}
try {
Thread.sleep(retryInterval);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -258,17 +260,15 @@ boolean isBuffered(final Request request) {
}

int executionCount = 1;
while (retryRequest(response, executionCount, request, retryOption, span)) {
while (retryRequest(
response, executionCount, request, Objects.requireNonNull(retryOption), span)) {
final Request.Builder builder =
request.newBuilder()
.addHeader(RETRY_ATTEMPT_HEADER, String.valueOf(executionCount));
if (span != null) {
builder.tag(Span.class, span);
}
request = builder.build();
if (request == null) {
throw new IllegalArgumentException("request cannot be null");
}
executionCount++;
final ResponseBody body = response.body();
if (body != null) body.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ private String sanitizeKey(@Nonnull final String key) {
}

@Nullable public <T> List<T> getCollectionOfPrimitiveValues(@Nonnull final Class<T> targetClass) {
final String[] primitiveStringCollection = getStringValue().split(",");
final String rawValue = getStringValue();
if (rawValue == null) {
return null;
}
final String[] primitiveStringCollection = rawValue.split(",");
final List<T> result = new ArrayList<>(primitiveStringCollection.length);
for (final String item : primitiveStringCollection) {
String decodedItem;
Expand Down
Loading
Loading