Skip to content

Commit

Permalink
Merge pull request #246 from microsoft/andrueastman/jsonReader
Browse files Browse the repository at this point in the history
Aligns http client timeout defaults
  • Loading branch information
andrueastman authored Mar 20, 2023
2 parents afa9e96 + 35e3626 commit 26e9359
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

## [0.3.3] - 2023-03-20

### Changed

- Aligns default http client timeout to be 100 seconds
- Updates the JsonParseNodeFactory to pass a JsonElement using `JsonParser.parseReader` rather than creating a string when creating the root parseNode.

## [0.3.2] - 2023-03-16

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

import java.time.Duration;
import com.microsoft.kiota.http.middleware.RedirectHandler;
import com.microsoft.kiota.http.middleware.RetryHandler;
import com.microsoft.kiota.http.middleware.UserAgentHandler;
Expand All @@ -29,7 +29,11 @@ public static OkHttpClient.Builder create() {
*/
@Nonnull
public static OkHttpClient.Builder create(@Nullable final Interceptor[] interceptors) {
final OkHttpClient.Builder builder = new OkHttpClient.Builder(); //TODO configure the default client options.
final OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(Duration.ofSeconds(100))
.readTimeout(Duration.ofSeconds(100))
.callTimeout(Duration.ofSeconds(100)); //TODO configure the default client options.

final Interceptor[] interceptorsOrDefault = interceptors != null ? interceptors : createDefaultInterceptors();
for (final Interceptor interceptor : interceptorsOrDefault) {
builder.addInterceptor(interceptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@
/** ParseNode implementation for JSON */
public class JsonParseNode implements ParseNode {
private final JsonElement currentNode;
/**
* Creates a new instance of the JsonParseNode class.
* @param rawJson the raw json to parse.
*/
public JsonParseNode(@Nonnull final String rawJson) {
Objects.requireNonNull(rawJson, "parameter node cannot be null");
currentNode = JsonParser.parseString(rawJson);
}
/**
* Creates a new instance of the JsonParseNode class.
* @param node the node to wrap.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.microsoft.kiota.serialization;

import java.io.BufferedReader;
import com.google.gson.JsonParser;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

Expand All @@ -31,16 +31,11 @@ public ParseNode getParseNode(@Nonnull final String contentType, @Nonnull final
} else if (!contentType.equals(validContentType)) {
throw new IllegalArgumentException("expected a " + validContentType + " content type");
}
String rawText;
try(final InputStreamReader reader = new InputStreamReader(rawResponse, StandardCharsets.UTF_8)) {
try(final BufferedReader buff = new BufferedReader(reader)) {
rawText = buff.lines()
.collect(Collectors.joining("\n"));
}
return new JsonParseNode(JsonParser.parseReader(reader));
} catch (IOException ex) {
throw new RuntimeException("could not close the reader", ex);
}
return new JsonParseNode(rawText);
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ org.gradle.caching=true
mavenGroupId = com.microsoft.kiota
mavenMajorVersion = 0
mavenMinorVersion = 3
mavenPatchVersion = 2
mavenPatchVersion = 3
mavenArtifactSuffix =

#These values are used to run functional tests
Expand Down

0 comments on commit 26e9359

Please sign in to comment.