Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Invalid runtime API usage when retrieving binary payload from a mime-datasource #1364

Merged
merged 12 commits into from
Dec 14, 2022
2 changes: 1 addition & 1 deletion ballerina-tests/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.5.0"
version = "2.5.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "io"},
Expand Down
53 changes: 53 additions & 0 deletions ballerina-tests/tests/http_request_payload_retrieval_test.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;
import ballerina/test;

@test:Config {
groups: ["binaryPayloadRetrieval"]
}
function testStringToBinaryPayloadRetrieval() returns error? {
http:Request req = new;
string payload = "This is a sample message";
req.setTextPayload(payload);
byte[] binaryPayload = check req.getBinaryPayload();
test:assertEquals(payload.toBytes().length(), binaryPayload.length());
}

@test:Config {
groups: ["binaryPayloadRetrieval"]
}
function testXmlToBinaryPayloadRetrieval() returns error? {
http:Request req = new;
xml payload = xml `<StorageServiceProperties><HourMetrics><Version>1.0</Version><Enabled>false</Enabled><RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></HourMetrics></StorageServiceProperties>`;
req.setXmlPayload(payload);
byte[] binaryPayload = check req.getBinaryPayload();
test:assertEquals(payload.toString().toBytes().length(), binaryPayload.length());
}

@test:Config {
groups: ["binaryPayloadRetrieval"]
}
function testJsonToBinaryPayloadRetrieval() returns error? {
http:Request req = new;
json payload = {
"message": "This is a sample message"
};
req.setJsonPayload(payload);
byte[] binaryPayload = check req.getBinaryPayload();
test:assertEquals(payload.toString().toBytes().length(), binaryPayload.length());
}
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ path = "../native/build/libs/http-native-2.5.2-SNAPSHOT.jar"
[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "mime-native"
version = "2.5.0"
path = "./lib/mime-native-2.5.0.jar"
version = "2.5.1"
path = "./lib/mime-native-2.5.1-20221213-143100-2be7554.jar"

[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ modules = [
[[package]]
org = "ballerina"
name = "mime"
version = "2.5.0"
version = "2.5.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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]

## Fixed
- [Binary payload retrieved from the `http:Request` has different content-length than the original payload](https://github.com/ballerina-platform/ballerina-standard-library/issues/3662)

## [2.5.1] - 2022-12-01

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ stdlibTaskVersion=2.3.0
stdlibLogVersion=2.5.0
stdlibCryptoVersion=2.3.0
stdlibFileVersion=1.5.0
stdlibMimeVersion=2.5.0
stdlibMimeVersion=2.5.1-20221213-143100-2be7554
stdlibCacheVersion=3.3.0
stdlibUuidVersion=1.4.0
stdlibAuthVersion=2.5.0
Expand Down