Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v2.8.x' into 2201.6.x-netty-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Jun 22, 2023
2 parents cce1740 + 0c083e7 commit a4116f5
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,66 @@ function testHeaderParamBindingCase9() returns error? {
http:Response res = check resourceHeaderParamBindingClient->/header/case9(headers);
test:assertEquals(res.statusCode, 400);
}

@test:Config {}
function testHeaderParamBindingCase10() returns error? {
int:Signed32 resPayload = check resourceHeaderParamBindingClient->/header/case10({header: "32"});
test:assertEquals(resPayload, 32);

resPayload = check resourceHeaderParamBindingClient->/header/case10({header: "-32"});
test:assertEquals(resPayload, -32);

http:Response res = check resourceHeaderParamBindingClient->/header/case10({header: "5000000000"});
test:assertEquals(res.statusCode, 400);
}

@test:Config {}
function testHeaderParamBindingCase11() returns error? {
int:Unsigned32 resPayload = check resourceHeaderParamBindingClient->/header/case11({header: "32"});
test:assertEquals(resPayload, 32);

http:Response res = check resourceHeaderParamBindingClient->/header/case11({header: "-32"});
test:assertEquals(res.statusCode, 400);

res = check resourceHeaderParamBindingClient->/header/case11({header: "5000000000"});
test:assertEquals(res.statusCode, 400);
}

@test:Config {}
function testHeaderParamBindingCase12() returns error? {
int:Signed8[] resPayload = check resourceHeaderParamBindingClient->/header/case12({header: ["32", "-38", "1", "-43"]});
test:assertEquals(resPayload, [32, -38, 1, -43]);

http:Response res = check resourceHeaderParamBindingClient->/header/case12({header: ["32", "-38", "1", "-43", "-50000000"]});
test:assertEquals(res.statusCode, 400);
}

@test:Config {}
function testHeaderParamBindingCase13() returns error? {
string:Char resPayload = check resourceHeaderParamBindingClient->/header/case13({header: "a"});
test:assertEquals(resPayload, "a");

resPayload = check resourceHeaderParamBindingClient->/header/case13({header: "*"});
test:assertEquals(resPayload, "*");

http:Response res = check resourceHeaderParamBindingClient->/header/case13({header: "ab"});
test:assertEquals(res.statusCode, 400);
}

@test:Config {}
function testHeaderParamBindingCase14() returns error? {
[StringCharacter, SmallInt] resPayload = check resourceHeaderParamBindingClient->/header/case14({header1: "a", header2: "32"});
test:assertEquals(resPayload, ["a", 32]);

resPayload = check resourceHeaderParamBindingClient->/header/case14({header1: "*", header2: "-32"});
test:assertEquals(resPayload, ["*", -32]);

http:Response res = check resourceHeaderParamBindingClient->/header/case14({header1: "ab", header2: "32"});
test:assertEquals(res.statusCode, 400);

res = check resourceHeaderParamBindingClient->/header/case14({header1: "a", header2: "5000000000"});
test:assertEquals(res.statusCode, 400);

res = check resourceHeaderParamBindingClient->/header/case14({header1: "ab", header2: "5000000000"});
test:assertEquals(res.statusCode, 400);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ballerina/test;
import ballerina/http;
import ballerina/http_test_common as common;
import ballerina/url;

final http:Client resourcePathParamBindingClient = check new("http://localhost:" + resourceParamBindingTestPort.toString());

Expand Down Expand Up @@ -145,3 +146,69 @@ function testPathParamBindingCase10() returns error? {
http:Response res = check resourcePathParamBindingClient->/path/case10/value1/value9/value3;
test:assertEquals(res.statusCode, 404, "Status code mismatched");
}

@test:Config {}
function testPathParamBindingCase11() returns error? {
int:Signed32 resPayload = check resourcePathParamBindingClient->/path/case11/'32;
test:assertEquals(resPayload, 32, "Payload mismatched");

resPayload = check resourcePathParamBindingClient->/path/case11/\-32;
test:assertEquals(resPayload, -32, "Payload mismatched");

http:Response res = check resourcePathParamBindingClient->/path/case11/'5000000000;
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testPathParamBindingCase12() returns error? {
int:Unsigned32 resPayload = check resourcePathParamBindingClient->/path/case12/'32;
test:assertEquals(resPayload, 32, "Payload mismatched");

http:Response res = check resourcePathParamBindingClient->/path/case12/\-32;
test:assertEquals(res.statusCode, 400, "Status code mismatched");

res = check resourcePathParamBindingClient->/path/case12/'5000000000;
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testPathParamBindingCase13() returns error? {
int:Signed8[] resPayload = check resourcePathParamBindingClient->/path/case13/'32/\-38/'1/\-43;
test:assertEquals(resPayload, [32, -38, 1, -43], "Payload mismatched");

http:Response res = check resourcePathParamBindingClient->/path/case13/'32/\-38/'1/\-43/'5000000000;
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testPathParamBindingCase14() returns error? {
string:Char resPayload = check resourcePathParamBindingClient->/path/case14/a;
test:assertEquals(resPayload, "a", "Payload mismatched");

resPayload = check resourcePathParamBindingClient->/path/case14/[check url:encode("*", "UTF-8")];
test:assertEquals(resPayload, "*", "Payload mismatched");

resPayload = check resourcePathParamBindingClient->/path/case14/[check url:encode(" ", "UTF-8")];
test:assertEquals(resPayload, " ", "Payload mismatched");

http:Response res = check resourcePathParamBindingClient->/path/case14/abc;
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testPathParamBindingCase15() returns error? {
[StringCharacter, SmallInt] resPayload = check resourcePathParamBindingClient->/path/case15/[check url:encode("*", "UTF-8")]/'34;
test:assertEquals(resPayload, ["*", 34], "Payload mismatched");

resPayload = check resourcePathParamBindingClient->/path/case15/[check url:encode(" ", "UTF-8")]/\-34;
test:assertEquals(resPayload, [" ", -34], "Payload mismatched");

http:Response res = check resourcePathParamBindingClient->/path/case15/a/'5000000;
test:assertEquals(res.statusCode, 400, "Status code mismatched");

res = check resourcePathParamBindingClient->/path/case15/ab/'32;
test:assertEquals(res.statusCode, 400, "Status code mismatched");

res = check resourcePathParamBindingClient->/path/case15/abc/'5000000;
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,68 @@ function testQueryParamBindingCase10() returns error? {
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testQueryParamBindingCase11() returns error? {
int:Signed32 resPayload = check resourceQueryParamBindingClient->/query/case11(query = 32);
test:assertEquals(resPayload, 32, "Payload mismatched");

resPayload = check resourceQueryParamBindingClient->/query/case11(query = -32);
test:assertEquals(resPayload, -32, "Payload mismatched");

http:Response res = check resourceQueryParamBindingClient->/query/case11(query = 5000000000);
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testQueryParamBindingCase12() returns error? {
int:Unsigned32 resPayload = check resourceQueryParamBindingClient->/query/case12(query = 32);
test:assertEquals(resPayload, 32, "Payload mismatched");

http:Response res = check resourceQueryParamBindingClient->/query/case12(query = -32);
test:assertEquals(res.statusCode, 400, "Status code mismatched");

res = check resourceQueryParamBindingClient->/query/case12(query = 5000000000);
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testQueryParamBindingCase13() returns error? {
int:Signed8[] resPayload = check resourceQueryParamBindingClient->/query/case13(query = [32, -38, 1, -43]);
test:assertEquals(resPayload, [32, -38, 1, -43], "Payload mismatched");

http:Response res = check resourceQueryParamBindingClient->/query/case13(query = [32, -38, 1, -43, 50000000]);
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testQueryParamBindingCase14() returns error? {
string:Char resPayload = check resourceQueryParamBindingClient->/query/case14(query = "a");
test:assertEquals(resPayload, "a", "Payload mismatched");

resPayload = check resourceQueryParamBindingClient->/query/case14(query = "*");
test:assertEquals(resPayload, "*", "Payload mismatched");

resPayload = check resourceQueryParamBindingClient->/query/case14(query = ".");
test:assertEquals(resPayload, ".", "Payload mismatched");

http:Response res = check resourceQueryParamBindingClient->/query/case14(query = "ab");
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}

@test:Config {}
function testQueryParamBindingCase15() returns error? {
[StringCharacter, SmallInt] resPayload = check resourceQueryParamBindingClient->/query/case15(query1 = "*", query2 = 34);
test:assertEquals(resPayload, ["*", 34], "Payload mismatched");

resPayload = check resourceQueryParamBindingClient->/query/case15(query1 = " ", query2 = -34);
test:assertEquals(resPayload, [" ", -34], "Payload mismatched");

http:Response res = check resourceQueryParamBindingClient->/query/case15(query1 = "ab", query2 = 34);
test:assertEquals(res.statusCode, 400, "Status code mismatched");

res = check resourceQueryParamBindingClient->/query/case15(query1 = "*", query2 = 500000);
test:assertEquals(res.statusCode, 400, "Status code mismatched");

res = check resourceQueryParamBindingClient->/query/case15(query1 = "abc", query2 = 500000);
test:assertEquals(res.statusCode, 400, "Status code mismatched");
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type QueryRecord record {|

type QueryRecordCombined QueryRecord|map<json>;

type StringCharacter string:Char;
type SmallInt int:Signed8;

listener http:Listener resourceParamBindingListener = new(resourceParamBindingTestPort);

service /path on resourceParamBindingListener {
Expand Down Expand Up @@ -104,6 +107,26 @@ service /path on resourceParamBindingListener {
}
return result;
}

resource function get case11/[int:Signed32 path]() returns int:Signed32 {
return path;
}

resource function get case12/[int:Unsigned32 path]() returns int:Unsigned32 {
return path;
}

resource function get case13/[int:Signed8... path]() returns int:Signed8[] {
return path;
}

resource function get case14/[string:Char path]() returns string:Char {
return path;
}

resource function get case15/[StringCharacter path1]/[SmallInt path2]() returns [StringCharacter, SmallInt] {
return [path1, path2];
}
}

service /query on resourceParamBindingListener {
Expand Down Expand Up @@ -176,6 +199,26 @@ service /query on resourceParamBindingListener {
}
return result;
}

resource function get case11(int:Signed32 query) returns int:Signed32 {
return query;
}

resource function get case12(int:Unsigned32 query) returns int:Unsigned32 {
return query;
}

resource function get case13(int:Signed8[] query) returns int:Signed8[] {
return query;
}

resource function get case14(string:Char query) returns string:Char {
return query;
}

resource function get case15(StringCharacter query1, SmallInt query2) returns [StringCharacter, SmallInt] {
return [query1, query2];
}
}

service /header on resourceParamBindingListener {
Expand Down Expand Up @@ -226,5 +269,25 @@ service /header on resourceParamBindingListener {
resource function get case9(@http:Header HeaderRecord? header) returns map<json>|string {
return header ?: "default";
}

resource function get case10(@http:Header int:Signed32 header) returns int:Signed32 {
return header;
}

resource function get case11(@http:Header int:Unsigned32 header) returns int:Unsigned32 {
return header;
}

resource function get case12(@http:Header int:Signed8[] header) returns int:Signed8[] {
return header;
}

resource function get case13(@http:Header string:Char header) returns string:Char {
return header;
}

resource function get case14(@http:Header StringCharacter header1, @http:Header SmallInt header2) returns [StringCharacter, SmallInt] {
return [header1, header2];
}
}

8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ 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]
## [2.8.0] - 2023-06-01

### Added

- [Add query,header and path parameter runtime support for Ballerina builtin types](https://github.com/ballerina-platform/ballerina-standard-library/issues/4526)

## [2.8.0] - 2023-06-01

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions load-tests/h1_h1_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,5 @@ HTTP Request,9586725,19,13,42,57,99,0,744,0.00%,2754.8,661.8,20.51,1685297679,50
HTTP Request,9348074,20,14,43,59,101,0,818,0.00%,2686.3,645.3,20.83,1685384091,50,60
HTTP Request,9507549,19,13,42,57,99,0,718,0.00%,2732.1,656.3,20.33,1685470479,50,60
HTTP Request,9924731,18,13,41,55,96,0,726,0.00%,2852.0,685.1,19.84,1685556867,50,60
HTTP Request,9470373,19,13,43,58,100,0,740,0.00%,2721.4,653.8,20.62,1685643309,50,60
HTTP Request,9520610,19,13,42,57,100,0,867,0.00%,2735.9,657.2,20.50,1685729722,50,60
2 changes: 2 additions & 0 deletions load-tests/h1_transformation/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,5 @@ HTTP Request,7557457,26,23,48,58,87,1,569,0.00%,2171.7,593.8,17.26,1685301648,50
HTTP Request,7717333,26,23,46,56,83,1,418,0.00%,2217.7,606.4,16.37,1685388074,50,60
HTTP Request,7826624,25,22,46,56,83,1,446,0.00%,2249.1,615.0,16.44,1685474432,50,60
HTTP Request,8283128,24,21,43,53,78,1,527,0.00%,2380.2,650.8,15.49,1685560824,50,60
HTTP Request,8064653,24,22,44,54,80,1,425,0.00%,2317.5,633.7,15.94,1685647272,50,60
HTTP Request,8278433,24,21,43,53,78,1,442,0.00%,2378.9,650.5,15.49,1685733707,50,60
2 changes: 2 additions & 0 deletions load-tests/h1c_h1c_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,5 @@ HTTP Request,11185587,16,12,35,47,76,0,350,0.00%,3214.3,571.3,15.40,1685305607,5
HTTP Request,10999720,17,12,36,47,77,0,594,0.00%,3160.9,561.8,15.72,1685392076,50,60
HTTP Request,9858732,18,14,40,52,86,0,537,0.00%,2833.0,503.5,17.66,1685478401,50,60
HTTP Request,11379278,16,12,35,46,75,0,428,0.00%,3269.9,581.2,15.22,1685564821,50,60
HTTP Request,11330698,16,12,35,46,75,0,347,0.00%,3256.0,578.7,15.36,1685651266,50,60
HTTP Request,11344755,16,12,35,46,75,0,450,0.00%,3260.1,579.4,15.33,1685737678,50,60
2 changes: 2 additions & 0 deletions load-tests/h1c_transformation/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,5 @@ HTTP Request,8778498,22,20,40,48,68,1,285,0.00%,2522.6,532.1,13.48,1685309609,50
HTTP Request,8799393,22,20,40,48,68,0,283,0.00%,2528.6,533.4,13.44,1685396085,50,60
HTTP Request,8044813,24,22,43,52,74,1,292,0.00%,2311.8,487.6,14.66,1685482374,50,60
HTTP Request,9112240,22,19,39,46,66,0,409,0.00%,2618.5,552.3,13.02,1685568777,50,60
HTTP Request,8840501,22,20,40,48,68,0,264,0.00%,2540.4,535.9,13.47,1685655252,50,60
HTTP Request,8791114,22,20,40,48,70,0,375,0.00%,2526.2,532.9,14.10,1685741629,50,60
2 changes: 2 additions & 0 deletions load-tests/h2_h1c_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,5 @@ H2-H1C Passthrough,5857,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1685310515,0,1
H2-H1C Passthrough,5831,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1685396992,0,1
H2-H1C Passthrough,5848,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1685483314,0,1
H2-H1C Passthrough,5861,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1685569803,0,1
H2-H1C Passthrough,5849,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1685656204,0,1
H2-H1C Passthrough,5858,0.0,0,0,0,0,0,0,1.0,0.0,0,0,1685742547,0,1
2 changes: 2 additions & 0 deletions load-tests/interceptors_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ Test Request,4595281,45,27,105,152,279,0,6214,1.82%,1320.5,140.6,56.21,168531444
Test Request,4628826,44,27,104,151,277,0,6959,1.87%,1330.2,141.8,55.65,1685400960,50,60
Test Request,4240938,48,29,112,163,298,0,1377,2.08%,1218.7,130.4,59.77,1685487251,50,60
Test Request,4748132,43,25,102,148,274,0,5815,1.68%,1364.4,144.9,55.10,1685573748,50,60
Test Request,4797149,43,26,100,145,267,0,1277,1.89%,1378.5,147.0,53.72,1685660148,50,60
Test Request,4646600,44,27,103,149,272,0,6660,1.71%,1335.3,141.8,54.94,1685746538,50,60
2 changes: 2 additions & 0 deletions load-tests/observability_enabled/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,5 @@ HTTP Request,13621321,14,5,38,61,125,0,685,0.00%,3914.2,584.8,25.32,1685318405,5
HTTP Request,14025510,14,5,37,59,123,0,730,0.00%,4030.4,602.2,25.01,1685404962,50,60
HTTP Request,12851823,15,6,39,63,128,0,698,0.00%,3693.1,551.8,26.00,1685491249,50,60
HTTP Request,14254814,13,5,36,59,125,0,1054,0.00%,4096.3,612.0,25.25,1685577733,50,60
HTTP Request,14088546,14,5,37,60,126,0,813,0.00%,4048.5,604.9,25.50,1685664126,50,60
HTTP Request,13861009,14,5,37,61,126,0,645,0.00%,3983.1,595.1,25.50,1685750537,50,60
2 changes: 2 additions & 0 deletions load-tests/snowpeak_passthrough/results/summary.csv
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@ Retrieve Available Locations,5528607,36,20,82,92,118,0,779,0.00%,1588.6,153.6,33
Retrieve Available Locations,5569175,36,19,82,93,120,0,509,0.00%,1600.4,154.7,33.68,1685408944,50,60
Retrieve Available Locations,5280123,38,22,83,94,120,1,496,0.00%,1517.3,146.7,33.57,1685495206,50,60
Retrieve Available Locations,5719924,35,19,81,90,113,0,624,0.00%,1643.6,158.9,32.74,1685581682,50,60
Retrieve Available Locations,5677009,36,19,82,92,125,0,529,0.00%,1631.3,157.7,33.85,1685668110,50,60
Retrieve Available Locations,5870926,34,18,80,91,117,0,465,0.00%,1687.1,163.1,33.02,1685754476,50,60
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ public static BError createHttpError(Throwable throwable) {
IOUtils.getIOPackage());
return createHttpError("Something wrong with the connection", HttpErrorType.GENERIC_CLIENT_ERROR, cause);
} else if (throwable instanceof ClientConnectorException) {
return HttpUtil.createHttpStatusCodeError(CLIENT_CONNECTOR_ERROR, "Something wrong with the connection");
cause = createErrorCause(throwable.getMessage(), IOConstants.ErrorCode.GenericError.errorCode(),
IOUtils.getIOPackage());
return HttpUtil.createHttpStatusCodeError(CLIENT_CONNECTOR_ERROR, "Something wrong with the connection",
null, cause);
} else if (throwable instanceof NullPointerException) {
return createHttpError("Exception occurred: null", HttpErrorType.GENERIC_CLIENT_ERROR,
createHttpError(throwable.toString()));
Expand Down
Loading

0 comments on commit a4116f5

Please sign in to comment.