From 9ce719f2f144c2bfc2dcfdabebebd3b531df26ad Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 09:15:42 -0400 Subject: [PATCH 1/3] - fixes long responses parsing Signed-off-by: Vincent Biret --- CHANGELOG.md | 6 +++++ .../kiota/http/OkHttpRequestAdapter.java | 20 ++++++++-------- .../http/TelemetrySemanticConventions.java | 23 ++++++++++--------- .../options/UserAgentHandlerOption.java | 2 +- gradle.properties | 2 +- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ea7521e7..a5555835a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.12] - 2024-05-21 + +### Changed + +- Fixed a bug where large responses would make the client fail. [microsoftgraph/msgraph-sdk-java#2009](https://github.com/microsoftgraph/msgraph-sdk-java/issues/2009) + ## [1.1.11] - 2024-05-07 ### Changed diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index d2b030d40..a59c041a3 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -53,8 +53,8 @@ /** RequestAdapter implementation for OkHttp */ public class OkHttpRequestAdapter implements com.microsoft.kiota.RequestAdapter { - private static final String contentTypeHeaderKey = "Content-Type"; - private static final String contentLengthHeaderKey = "Content-Length"; + private static final String CONTENT_LENGTH_HEADER_KEY = "Content-Length"; + private static final String CONTENT_TYPE_HEADER_KEY = "Content-Type"; @Nonnull private final Call.Factory client; @Nonnull private final AuthenticationProvider authProvider; @Nonnull private final ObservabilityOptions obsOptions; @@ -715,14 +715,16 @@ private Response getHttpResponseMessage( getRequestFromRequestInformation( requestInfo, span, spanForAttributes)) .execute(); - final String contentLengthHeaderValue = getHeaderValue(response, "Content-Length"); + final String contentLengthHeaderValue = + getHeaderValue(response, CONTENT_LENGTH_HEADER_KEY); if (contentLengthHeaderValue != null && !contentLengthHeaderValue.isEmpty()) { - final int contentLengthHeaderValueAsInt = - Integer.parseInt(contentLengthHeaderValue); + final long contentLengthHeaderValueAsLong = + Long.parseLong(contentLengthHeaderValue); spanForAttributes.setAttribute( - EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsInt); + EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsLong); } - final String contentTypeHeaderValue = getHeaderValue(response, "Content-Length"); + final String contentTypeHeaderValue = + getHeaderValue(response, CONTENT_LENGTH_HEADER_KEY); if (contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) { spanForAttributes.setAttribute( "http.response_content_type", contentTypeHeaderValue); @@ -886,7 +888,7 @@ private void setBaseUrlForRequestInformation(@Nonnull final RequestInformation r public MediaType contentType() { final Set contentTypes = requestInfo.headers.getOrDefault( - contentTypeHeaderKey, new HashSet<>()); + CONTENT_TYPE_HEADER_KEY, new HashSet<>()); if (contentTypes.isEmpty()) { return null; } else { @@ -902,7 +904,7 @@ public MediaType contentType() { public long contentLength() throws IOException { final Set contentLength = requestInfo.headers.getOrDefault( - contentLengthHeaderKey, new HashSet<>()); + CONTENT_LENGTH_HEADER_KEY, new HashSet<>()); if (!contentLength.isEmpty()) { return Long.parseLong( contentLength.toArray(new String[] {})[0]); diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java index 02e8ef458..beda96888 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java @@ -5,24 +5,25 @@ import io.opentelemetry.api.common.AttributeKey; -public class TelemetrySemanticConventions { +public final class TelemetrySemanticConventions { + private TelemetrySemanticConventions() {} // https://opentelemetry.io/docs/specs/semconv/attributes-registry/ - public static final AttributeKey HTTP_RESPONSE_STATUS_CODE = + public static final AttributeKey HTTP_RESPONSE_STATUS_CODE = longKey("http.response.status_code"); // stable - public static final AttributeKey HTTP_REQUEST_RESEND_COUNT = + public static final AttributeKey HTTP_REQUEST_RESEND_COUNT = longKey("http.request.resend_count"); // stable - public static final AttributeKey HTTP_REQUEST_METHOD = + public static final AttributeKey HTTP_REQUEST_METHOD = stringKey("http.request.method"); // stable - public static final AttributeKey NETWORK_PROTOCOL_VERSION = + public static final AttributeKey NETWORK_PROTOCOL_VERSION = stringKey("network.protocol.version"); // stable - public static final AttributeKey URL_FULL = stringKey("url.full"); // stable - public static final AttributeKey URL_SCHEME = stringKey("url.scheme"); // stable - public static final AttributeKey SERVER_ADDRESS = stringKey("server.address"); // stable - public static final AttributeKey SERVER_PORT = longKey("server.port"); // stable + public static final AttributeKey URL_FULL = stringKey("url.full"); // stable + public static final AttributeKey URL_SCHEME = stringKey("url.scheme"); // stable + public static final AttributeKey SERVER_ADDRESS = stringKey("server.address"); // stable + public static final AttributeKey SERVER_PORT = longKey("server.port"); // stable - public static final AttributeKey EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE = + public static final AttributeKey EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE = longKey("http.response.body.size"); // experimental - public static final AttributeKey EXPERIMENTAL_HTTP_REQUEST_BODY_SIZE = + public static final AttributeKey EXPERIMENTAL_HTTP_REQUEST_BODY_SIZE = longKey("http.request.body.size"); // experimental } diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/options/UserAgentHandlerOption.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/options/UserAgentHandlerOption.java index 28039daac..f01bddc01 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/options/UserAgentHandlerOption.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/options/UserAgentHandlerOption.java @@ -13,7 +13,7 @@ public UserAgentHandlerOption() {} private boolean enabled = true; @Nonnull private String productName = "kiota-java"; - @Nonnull private String productVersion = "1.1.11"; + @Nonnull private String productVersion = "1.1.12"; /** * Gets the product name to be used in the user agent header diff --git a/gradle.properties b/gradle.properties index 40cda2f94..a1a2306e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ org.gradle.caching=true mavenGroupId = com.microsoft.kiota mavenMajorVersion = 1 mavenMinorVersion = 1 -mavenPatchVersion = 11 +mavenPatchVersion = 12 mavenArtifactSuffix = #These values are used to run functional tests From 37cf2a7424f6799a218ad1b011905755cbcda70f Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 09:24:11 -0400 Subject: [PATCH 2/3] bugfix: fixes wrong attribute to header mapping Signed-off-by: Vincent Biret --- .../java/com/microsoft/kiota/http/OkHttpRequestAdapter.java | 6 +++--- .../microsoft/kiota/http/TelemetrySemanticConventions.java | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index a59c041a3..d6f405b23 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -724,10 +724,10 @@ private Response getHttpResponseMessage( EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsLong); } final String contentTypeHeaderValue = - getHeaderValue(response, CONTENT_LENGTH_HEADER_KEY); + getHeaderValue(response, CONTENT_TYPE_HEADER_KEY); if (contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) { spanForAttributes.setAttribute( - "http.response_content_type", contentTypeHeaderValue); + CUSTOM_HTTP_RESPONSE_CONTENT_TYPE, contentTypeHeaderValue); } spanForAttributes.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code()); spanForAttributes.setAttribute( @@ -895,7 +895,7 @@ public MediaType contentType() { final String contentType = contentTypes.toArray(new String[] {})[0]; spanForAttributes.setAttribute( - "http.request_content_type", contentType); + CUSTOM_HTTP_REQUEST_CONTENT_TYPE, contentType); return MediaType.parse(contentType); } } diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java index beda96888..fc8d7fbf4 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java @@ -26,4 +26,7 @@ private TelemetrySemanticConventions() {} longKey("http.response.body.size"); // experimental public static final AttributeKey EXPERIMENTAL_HTTP_REQUEST_BODY_SIZE = longKey("http.request.body.size"); // experimental + + public static final AttributeKey CUSTOM_HTTP_RESPONSE_CONTENT_TYPE = stringKey("http.response_content_type"); // custom + public static final AttributeKey CUSTOM_HTTP_REQUEST_CONTENT_TYPE = stringKey("http.request_content_type"); // custom } From 93c51f5124cf90ae10f01faafb272d23b038f671 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 09:42:44 -0400 Subject: [PATCH 3/3] chore: linting --- .../com/microsoft/kiota/http/OkHttpRequestAdapter.java | 7 +++---- .../microsoft/kiota/http/TelemetrySemanticConventions.java | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index d6f405b23..602f64567 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -723,11 +723,10 @@ private Response getHttpResponseMessage( spanForAttributes.setAttribute( EXPERIMENTAL_HTTP_RESPONSE_BODY_SIZE, contentLengthHeaderValueAsLong); } - final String contentTypeHeaderValue = - getHeaderValue(response, CONTENT_TYPE_HEADER_KEY); + final String contentTypeHeaderValue = getHeaderValue(response, CONTENT_TYPE_HEADER_KEY); if (contentTypeHeaderValue != null && !contentTypeHeaderValue.isEmpty()) { spanForAttributes.setAttribute( - CUSTOM_HTTP_RESPONSE_CONTENT_TYPE, contentTypeHeaderValue); + CUSTOM_HTTP_RESPONSE_CONTENT_TYPE, contentTypeHeaderValue); } spanForAttributes.setAttribute(HTTP_RESPONSE_STATUS_CODE, response.code()); spanForAttributes.setAttribute( @@ -895,7 +894,7 @@ public MediaType contentType() { final String contentType = contentTypes.toArray(new String[] {})[0]; spanForAttributes.setAttribute( - CUSTOM_HTTP_REQUEST_CONTENT_TYPE, contentType); + CUSTOM_HTTP_REQUEST_CONTENT_TYPE, contentType); return MediaType.parse(contentType); } } diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java index fc8d7fbf4..d5546409a 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/TelemetrySemanticConventions.java @@ -27,6 +27,8 @@ private TelemetrySemanticConventions() {} public static final AttributeKey EXPERIMENTAL_HTTP_REQUEST_BODY_SIZE = longKey("http.request.body.size"); // experimental - public static final AttributeKey CUSTOM_HTTP_RESPONSE_CONTENT_TYPE = stringKey("http.response_content_type"); // custom - public static final AttributeKey CUSTOM_HTTP_REQUEST_CONTENT_TYPE = stringKey("http.request_content_type"); // custom + public static final AttributeKey CUSTOM_HTTP_RESPONSE_CONTENT_TYPE = + stringKey("http.response_content_type"); // custom + public static final AttributeKey CUSTOM_HTTP_REQUEST_CONTENT_TYPE = + stringKey("http.request_content_type"); // custom }