From abeb1a2f014d27f41c8ec6a5bb1f0cba1628847a Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Tue, 3 Sep 2024 11:10:45 +0530 Subject: [PATCH 1/7] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 74d4c64fd9..805cd6d732 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" authors = ["Ballerina"] keywords = ["http", "network", "service", "listener", "client"] repository = "https://github.com/ballerina-platform/module-ballerina-http" @@ -16,8 +16,8 @@ graalvmCompatible = true [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "http-native" -version = "2.12.0" -path = "../native/build/libs/http-native-2.12.0.jar" +version = "2.12.1" +path = "../native/build/libs/http-native-2.12.1-SNAPSHOT.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index d97cfe7aac..751236dbb9 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "http-compiler-plugin" class = "io.ballerina.stdlib.http.compiler.HttpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/http-compiler-plugin-2.12.0.jar" +path = "../compiler-plugin/build/libs/http-compiler-plugin-2.12.1-SNAPSHOT.jar" [[dependency]] path = "../compiler-plugin/build/libs/ballerina-to-openapi-2.1.0.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 13938875f8..66f8ee6cbc 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -76,7 +76,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, From 6c72110e1886032c4972cf7d78b3d2483a3bedbe Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Tue, 3 Sep 2024 12:08:55 +0530 Subject: [PATCH 2/7] [Automated] Update the native jar versions --- ballerina-tests/http-advanced-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-advanced-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-client-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-client-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-dispatching-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-dispatching-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-interceptor-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-interceptor-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-misc-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-misc-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-resiliency-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-resiliency-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-security-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-security-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-service-tests/Ballerina.toml | 6 +++--- ballerina-tests/http-service-tests/Dependencies.toml | 6 +++--- ballerina-tests/http-test-common/Ballerina.toml | 2 +- ballerina-tests/http-test-common/Dependencies.toml | 4 ++-- ballerina-tests/http2-tests/Ballerina.toml | 6 +++--- ballerina-tests/http2-tests/Dependencies.toml | 6 +++--- 20 files changed, 57 insertions(+), 57 deletions(-) diff --git a/ballerina-tests/http-advanced-tests/Ballerina.toml b/ballerina-tests/http-advanced-tests/Ballerina.toml index 66be801eed..3ee0bd35f6 100644 --- a/ballerina-tests/http-advanced-tests/Ballerina.toml +++ b/ballerina-tests/http-advanced-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_advanced_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-advanced-tests/Dependencies.toml b/ballerina-tests/http-advanced-tests/Dependencies.toml index 31bd887626..85999a0f16 100644 --- a/ballerina-tests/http-advanced-tests/Dependencies.toml +++ b/ballerina-tests/http-advanced-tests/Dependencies.toml @@ -72,7 +72,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -105,7 +105,7 @@ modules = [ [[package]] org = "ballerina" name = "http_advanced_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "file"}, @@ -125,7 +125,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-client-tests/Ballerina.toml b/ballerina-tests/http-client-tests/Ballerina.toml index 84bd5e1d70..c6fafc1909 100644 --- a/ballerina-tests/http-client-tests/Ballerina.toml +++ b/ballerina-tests/http-client-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_client_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-client-tests/Dependencies.toml b/ballerina-tests/http-client-tests/Dependencies.toml index a5863e87a6..553a084e96 100644 --- a/ballerina-tests/http-client-tests/Dependencies.toml +++ b/ballerina-tests/http-client-tests/Dependencies.toml @@ -69,7 +69,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_client_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-dispatching-tests/Ballerina.toml b/ballerina-tests/http-dispatching-tests/Ballerina.toml index 498a07ef1a..6b409df4f0 100644 --- a/ballerina-tests/http-dispatching-tests/Ballerina.toml +++ b/ballerina-tests/http-dispatching-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_dispatching_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-dispatching-tests/Dependencies.toml b/ballerina-tests/http-dispatching-tests/Dependencies.toml index 40c03f7108..068a65b76d 100644 --- a/ballerina-tests/http-dispatching-tests/Dependencies.toml +++ b/ballerina-tests/http-dispatching-tests/Dependencies.toml @@ -69,7 +69,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_dispatching_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "http"}, @@ -124,7 +124,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-interceptor-tests/Ballerina.toml b/ballerina-tests/http-interceptor-tests/Ballerina.toml index 4707d2d3f0..c9e750b259 100644 --- a/ballerina-tests/http-interceptor-tests/Ballerina.toml +++ b/ballerina-tests/http-interceptor-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_interceptor_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-interceptor-tests/Dependencies.toml b/ballerina-tests/http-interceptor-tests/Dependencies.toml index 7fdfbb7b27..2a310bff4c 100644 --- a/ballerina-tests/http-interceptor-tests/Dependencies.toml +++ b/ballerina-tests/http-interceptor-tests/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_interceptor_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -115,7 +115,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-misc-tests/Ballerina.toml b/ballerina-tests/http-misc-tests/Ballerina.toml index cc7a746bc5..fd660d3f52 100644 --- a/ballerina-tests/http-misc-tests/Ballerina.toml +++ b/ballerina-tests/http-misc-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_misc_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-misc-tests/Dependencies.toml b/ballerina-tests/http-misc-tests/Dependencies.toml index 7335a721b5..a6267e2744 100644 --- a/ballerina-tests/http-misc-tests/Dependencies.toml +++ b/ballerina-tests/http-misc-tests/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_misc_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -118,7 +118,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-resiliency-tests/Ballerina.toml b/ballerina-tests/http-resiliency-tests/Ballerina.toml index 6936bb354f..afa1e84565 100644 --- a/ballerina-tests/http-resiliency-tests/Ballerina.toml +++ b/ballerina-tests/http-resiliency-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_resiliency_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-resiliency-tests/Dependencies.toml b/ballerina-tests/http-resiliency-tests/Dependencies.toml index 6bfa5d95b3..6d14fa50a7 100644 --- a/ballerina-tests/http-resiliency-tests/Dependencies.toml +++ b/ballerina-tests/http-resiliency-tests/Dependencies.toml @@ -66,7 +66,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -99,7 +99,7 @@ modules = [ [[package]] org = "ballerina" name = "http_resiliency_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "http_test_common"}, @@ -116,7 +116,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-security-tests/Ballerina.toml b/ballerina-tests/http-security-tests/Ballerina.toml index 05d5be7466..ca398c1cc0 100644 --- a/ballerina-tests/http-security-tests/Ballerina.toml +++ b/ballerina-tests/http-security-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_security_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-security-tests/Dependencies.toml b/ballerina-tests/http-security-tests/Dependencies.toml index 212b85437d..bfa664fc5d 100644 --- a/ballerina-tests/http-security-tests/Dependencies.toml +++ b/ballerina-tests/http-security-tests/Dependencies.toml @@ -69,7 +69,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_security_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "http"}, @@ -120,7 +120,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-service-tests/Ballerina.toml b/ballerina-tests/http-service-tests/Ballerina.toml index 3e79d2473b..019d2dc081 100644 --- a/ballerina-tests/http-service-tests/Ballerina.toml +++ b/ballerina-tests/http-service-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http_service_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http-service-tests/Dependencies.toml b/ballerina-tests/http-service-tests/Dependencies.toml index 391edde651..61aebf9302 100644 --- a/ballerina-tests/http-service-tests/Dependencies.toml +++ b/ballerina-tests/http-service-tests/Dependencies.toml @@ -69,7 +69,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http_service_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, diff --git a/ballerina-tests/http-test-common/Ballerina.toml b/ballerina-tests/http-test-common/Ballerina.toml index e165475d52..a58967ad4e 100644 --- a/ballerina-tests/http-test-common/Ballerina.toml +++ b/ballerina-tests/http-test-common/Ballerina.toml @@ -1,4 +1,4 @@ [package] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" diff --git a/ballerina-tests/http-test-common/Dependencies.toml b/ballerina-tests/http-test-common/Dependencies.toml index 9c868d85bb..3442357bdf 100644 --- a/ballerina-tests/http-test-common/Dependencies.toml +++ b/ballerina-tests/http-test-common/Dependencies.toml @@ -61,7 +61,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -93,7 +93,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "http"}, {org = "ballerina", name = "lang.string"}, diff --git a/ballerina-tests/http2-tests/Ballerina.toml b/ballerina-tests/http2-tests/Ballerina.toml index d48f6aefe5..89b8f31e5b 100644 --- a/ballerina-tests/http2-tests/Ballerina.toml +++ b/ballerina-tests/http2-tests/Ballerina.toml @@ -1,17 +1,17 @@ [package] org = "ballerina" name = "http2_tests" -version = "2.12.0" +version = "2.12.1" [[dependency]] org = "ballerina" name = "http_test_common" repository = "local" -version = "2.12.0" +version = "2.12.1" [platform.java17] graalvmCompatible = true [[platform.java17.dependency]] scope = "testOnly" -path = "../../test-utils/build/libs/http-test-utils-2.12.0.jar" +path = "../../test-utils/build/libs/http-test-utils-2.12.1-SNAPSHOT.jar" diff --git a/ballerina-tests/http2-tests/Dependencies.toml b/ballerina-tests/http2-tests/Dependencies.toml index b90fa5cd65..768d787af9 100644 --- a/ballerina-tests/http2-tests/Dependencies.toml +++ b/ballerina-tests/http2-tests/Dependencies.toml @@ -69,7 +69,7 @@ modules = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, @@ -102,7 +102,7 @@ modules = [ [[package]] org = "ballerina" name = "http2_tests" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "file"}, {org = "ballerina", name = "http"}, @@ -121,7 +121,7 @@ modules = [ [[package]] org = "ballerina" name = "http_test_common" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "http"}, From 25dc953b8e0279df572cc3c621a593c0181566e7 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Tue, 3 Sep 2024 12:31:54 +0530 Subject: [PATCH 3/7] Add `anydata` support for `setPayload` method --- ballerina/http_request.bal | 7 +++++-- ballerina/http_response.bal | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ballerina/http_request.bal b/ballerina/http_request.bal index 38ad126bf2..2f8d9c8fc0 100644 --- a/ballerina/http_request.bal +++ b/ballerina/http_request.bal @@ -514,11 +514,12 @@ public class Request { # as an optional parameter. If the content type parameter is not provided then the default value derived # from the payload will be used as content-type only when there are no existing content-type header. # - # + payload - Payload can be of type `string`, `xml`, `json`, `byte[]`, `stream` + # + payload - Payload can be of type `anydata`, `stream` # or `Entity[]` (i.e., a set of body parts). # + contentType - Content-type to be used with the payload. This is an optional parameter - public isolated function setPayload(string|xml|json|byte[]|mime:Entity[]|stream payload, + public isolated function setPayload(anydata|mime:Entity[]|stream payload, string? contentType = ()) { + if contentType is string { error? err = self.setContentType(contentType); if err is error { @@ -538,6 +539,8 @@ public class Request { self.setByteStream(payload); } else if payload is mime:Entity[] { self.setBodyParts(payload); + } else if payload is anydata { + self.setJsonPayload(payload.toJson()); } else { panic error Error("invalid entity body type." + "expected one of the types: string|xml|json|byte[]|mime:Entity[]|stream"); diff --git a/ballerina/http_response.bal b/ballerina/http_response.bal index df3273424b..53ca4524e1 100644 --- a/ballerina/http_response.bal +++ b/ballerina/http_response.bal @@ -491,10 +491,10 @@ public class Response { # as an optional parameter. If the content type parameter is not provided then the default value derived # from the payload will be used as content-type only when there are no existing content-type header. # - # + payload - Payload can be of type `string`, `xml`, `json`, `byte[]`, `stream` + # + payload - Payload can be of type `anydata`, `stream`, stream, # or `Entity[]` (i.e., a set of body parts). # + contentType - Content-type to be used with the payload. This is an optional parameter - public isolated function setPayload(string|xml|json|byte[]|mime:Entity[]|stream|stream payload, + public isolated function setPayload(anydata|mime:Entity[]|stream|stream payload, string? contentType = ()) { if contentType is string { error? err = self.setContentType(contentType); @@ -517,6 +517,8 @@ public class Response { self.setBodyParts(payload); } else if payload is stream { self.setSseEventStream(payload); + } else if payload is anydata { + self.setJsonPayload(payload.toJson()); } else { panic error Error("invalid entity body type." + "expected one of the types: string|xml|json|byte[]|mime:Entity[]|stream"); From 89f5139d9288da048d8c0bf1ecf240b113464f14 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Tue, 3 Sep 2024 12:32:03 +0530 Subject: [PATCH 4/7] Add test cases --- .../tests/entity_body_with_charset_test.bal | 34 +++++++++++++++++++ .../tests/http_request_setPayload_test.bal | 15 ++++++++ .../tests/http_response_setPayload_test.bal | 10 ++++++ 3 files changed, 59 insertions(+) diff --git a/ballerina-tests/http-misc-tests/tests/entity_body_with_charset_test.bal b/ballerina-tests/http-misc-tests/tests/entity_body_with_charset_test.bal index bf392c447d..8fe1630ae3 100644 --- a/ballerina-tests/http-misc-tests/tests/entity_body_with_charset_test.bal +++ b/ballerina-tests/http-misc-tests/tests/entity_body_with_charset_test.bal @@ -314,6 +314,12 @@ service /entityService on generalListener { } check caller->respond(response); } + + resource function post anydataTest(AnydataRecord rec) returns http:Response { + http:Response response = new; + response.setPayload(rec); + return response; + } } final http:Client entityClient = check new ("http://localhost:" + generalPort.toString()); @@ -334,3 +340,31 @@ function jsonTest() { test:assertFail(msg = "Test Failed! " + response.message()); } } + +@test:Config {} +function setPayloadWithAnydata() { + string path = "/entityService/anydataTest"; + http:Request request = new; + AnydataRecord rec = {a: "ballerina", b: 1}; + request.setPayload(rec); + http:Response|error response = entityClient->post(path, request); + if response is http:Response { + common:assertJsonPayload(response.getJsonPayload(), rec.toJson()); + } else { + test:assertFail(msg = "Test Failed! " + response.message()); + } +} + +@test:Config {} +function setPayloadWithAnydataDataBinding() { + string path = "/entityService/anydataTest"; + http:Request request = new; + AnydataRecord rec = {a: "ballerina", b: 1}; + request.setPayload(rec); + AnydataRecord|error response = entityClient->post(path, request); + if response is AnydataRecord { + test:assertEquals(response, rec); + } else { + test:assertFail(msg = "Test Failed! " + response.message()); + } +} diff --git a/ballerina-tests/http-misc-tests/tests/http_request_setPayload_test.bal b/ballerina-tests/http-misc-tests/tests/http_request_setPayload_test.bal index dd4787294d..3ed8241e87 100644 --- a/ballerina-tests/http-misc-tests/tests/http_request_setPayload_test.bal +++ b/ballerina-tests/http-misc-tests/tests/http_request_setPayload_test.bal @@ -145,3 +145,18 @@ function testRequestSetBinaryPayload() returns error? { test:assertEquals(req.getContentType(), "binary/test2", msg = "Found unexpected headerValue"); return; } + +type AnydataRecord record { + string a; + int b; +}; + +@test:Config {} +function testRequestSetAnydataPayload() returns error? { + http:Request req = new; + AnydataRecord testValue = {a: "ballerina", b: 1}; + req.setPayload(testValue); + test:assertEquals(req.getContentType(), "application/json", msg = "Found unexpected headerValue"); + json payload = check req.getJsonPayload(); + test:assertEquals(payload, testValue.toJson(), msg = "Found unexpected payload"); +} diff --git a/ballerina-tests/http-misc-tests/tests/http_response_setPayload_test.bal b/ballerina-tests/http-misc-tests/tests/http_response_setPayload_test.bal index 55a4250ebd..c6135b2f98 100644 --- a/ballerina-tests/http-misc-tests/tests/http_response_setPayload_test.bal +++ b/ballerina-tests/http-misc-tests/tests/http_response_setPayload_test.bal @@ -186,3 +186,13 @@ function testResponseSetByteStream() returns error? { test:assertEquals(res.getContentType(), "stream/test2", msg = "Found unexpected headerValue"); return; } + +@test:Config {} +function testResponseSetAnydataPayload() returns error? { + http:Response res = new; + AnydataRecord testValue = {a: "ballerina", b: 1}; + res.setPayload(testValue); + test:assertEquals(res.getContentType(), "application/json", msg = "Found unexpected headerValue"); + json payload = check res.getJsonPayload(); + test:assertEquals(payload, testValue.toJson(), msg = "Found unexpected payload"); +} From 2ee1e18d332e1934dccc474ec8bd34863c7b9a56 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Tue, 3 Sep 2024 12:33:23 +0530 Subject: [PATCH 5/7] Update change log --- changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index 5c0dd57114..0e061b132d 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,12 @@ This file contains all the notable changes done to the Ballerina HTTP package th The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- [Add `anydata` support for `setPayload` methods in the request and response objects](https://github.com/ballerina-platform/ballerina-library/issues/6954) + ## [2.12.0] - 2024-08-20 ### Added From 0c9bbbe9648f36d30e2804bdb63b41a5d9e7f866 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Thu, 5 Sep 2024 15:08:18 +0530 Subject: [PATCH 6/7] Add information about the conversion for non-json types --- ballerina/http_request.bal | 3 ++- ballerina/http_response.bal | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ballerina/http_request.bal b/ballerina/http_request.bal index 2f8d9c8fc0..40799c55f0 100644 --- a/ballerina/http_request.bal +++ b/ballerina/http_request.bal @@ -512,7 +512,8 @@ public class Request { # Sets the request payload. This method overrides any existing content-type by passing the content-type # as an optional parameter. If the content type parameter is not provided then the default value derived - # from the payload will be used as content-type only when there are no existing content-type header. + # from the payload will be used as content-type only when there are no existing content-type header. If + # the payload is non-json typed value then the value is converted to json using the `toJson` method. # # + payload - Payload can be of type `anydata`, `stream` # or `Entity[]` (i.e., a set of body parts). diff --git a/ballerina/http_response.bal b/ballerina/http_response.bal index 53ca4524e1..473cb3b1a2 100644 --- a/ballerina/http_response.bal +++ b/ballerina/http_response.bal @@ -489,7 +489,8 @@ public class Response { # Sets the response payload. This method overrides any existing content-type by passing the content-type # as an optional parameter. If the content type parameter is not provided then the default value derived - # from the payload will be used as content-type only when there are no existing content-type header. + # from the payload will be used as content-type only when there are no existing content-type header. If + # the payload is non-json typed value then the value is converted to json using the `toJson` method. # # + payload - Payload can be of type `anydata`, `stream`, stream, # or `Entity[]` (i.e., a set of body parts). From 35adbe0308e16d7cfd1f98cbeca0fe4298e50be3 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Fri, 6 Sep 2024 08:17:19 +0530 Subject: [PATCH 7/7] Update `setPayload` documentation comment --- ballerina/http_request.bal | 8 ++++---- ballerina/http_response.bal | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ballerina/http_request.bal b/ballerina/http_request.bal index 40799c55f0..9a1f35051a 100644 --- a/ballerina/http_request.bal +++ b/ballerina/http_request.bal @@ -512,11 +512,11 @@ public class Request { # Sets the request payload. This method overrides any existing content-type by passing the content-type # as an optional parameter. If the content type parameter is not provided then the default value derived - # from the payload will be used as content-type only when there are no existing content-type header. If - # the payload is non-json typed value then the value is converted to json using the `toJson` method. + # from the payload will be used as content-type only when there are no existing content-type header. # - # + payload - Payload can be of type `anydata`, `stream` - # or `Entity[]` (i.e., a set of body parts). + # + payload - Payload can be of type `string`, `xml`, `byte[]`, `json`, `stream`, + # `Entity[]` (i.e., a set of body parts) or any other value of type `anydata` which will + # be converted to `json` using the `toJson` method. # + contentType - Content-type to be used with the payload. This is an optional parameter public isolated function setPayload(anydata|mime:Entity[]|stream payload, string? contentType = ()) { diff --git a/ballerina/http_response.bal b/ballerina/http_response.bal index 473cb3b1a2..e1f9c08ad1 100644 --- a/ballerina/http_response.bal +++ b/ballerina/http_response.bal @@ -492,8 +492,10 @@ public class Response { # from the payload will be used as content-type only when there are no existing content-type header. If # the payload is non-json typed value then the value is converted to json using the `toJson` method. # - # + payload - Payload can be of type `anydata`, `stream`, stream, - # or `Entity[]` (i.e., a set of body parts). + # + payload - Payload can be of type `string`, `xml`, `byte[]`, `json`, `stream`, + # stream(represents Server-Sent events), `Entity[]` (i.e., a set of body + # parts) or any other value of type `anydata` which will be converted to `json` using the + # `toJson` method. # + contentType - Content-type to be used with the payload. This is an optional parameter public isolated function setPayload(anydata|mime:Entity[]|stream|stream payload, string? contentType = ()) {