diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 38ea4e7310..cc4972eb8c 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -14,5 +14,5 @@ jobs: call_workflow: name: Run Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main secrets: inherit diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 249d237485..64d074cde7 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -40,7 +40,7 @@ jobs: call_stdlib_workflow: name: Run StdLib Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 0dcae97c97..6bd74c449f 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -16,7 +16,7 @@ jobs: call_workflow: name: Run Central Publish Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main secrets: inherit with: environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/on-demand-urgent-build-timestamped-master-without-tests.yml b/.github/workflows/on-demand-urgent-build-timestamped-master-without-tests.yml index a2bb53d137..30470f7f8f 100644 --- a/.github/workflows/on-demand-urgent-build-timestamped-master-without-tests.yml +++ b/.github/workflows/on-demand-urgent-build-timestamped-master-without-tests.yml @@ -7,7 +7,7 @@ jobs: call_workflow: name: Run Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main with: additional-build-flags: '-x check -x test' secrets: inherit diff --git a/.github/workflows/process-load-test-result.yml b/.github/workflows/process-load-test-result.yml index e187bfd27e..67a30482df 100644 --- a/.github/workflows/process-load-test-result.yml +++ b/.github/workflows/process-load-test-result.yml @@ -6,7 +6,7 @@ on: jobs: call_stdlib_process_load_test_results_workflow: name: Run StdLib Process Load Test Results Workflow - uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@main with: results: ${{ toJson(github.event.client_payload.results) }} secrets: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 55214c4a4f..3119cf2777 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,7 +9,7 @@ jobs: call_workflow: name: Run Release Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main secrets: inherit with: package-name: http diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 806bcb0489..dbbc163ad9 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -6,5 +6,5 @@ jobs: call_workflow: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main secrets: inherit diff --git a/.github/workflows/trigger-load-tests.yml b/.github/workflows/trigger-load-tests.yml index 5cec3af227..66a910ca3d 100644 --- a/.github/workflows/trigger-load-tests.yml +++ b/.github/workflows/trigger-load-tests.yml @@ -22,7 +22,7 @@ jobs: call_stdlib_trigger_load_test_workflow: name: Run StdLib Load Test Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main with: repo_name: 'module-ballerina-http' runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-http/actions/artifacts' diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 684db29190..2f7999dedd 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,5 +9,5 @@ jobs: call_workflow: name: Run Trivy Scan Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_1/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_1/Ballerina.toml new file mode 100644 index 0000000000..2936f4c22a --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_1/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "codeaction_sample_1" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_1/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_1/service.bal new file mode 100644 index 0000000000..2bd8487c5d --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_1/service.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + + resource function get . (@http:Header json length) { + + } + + resource function get path1(http:Caller caller) returns string { + return ""; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_2/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_2/Ballerina.toml new file mode 100644 index 0000000000..c5e0746942 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_2/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "codeaction_sample_2" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_2/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_2/service.bal new file mode 100644 index 0000000000..b8bcb31c91 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_2/service.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /greeting on new http:Listener(0) { + resource function get hi() returns string { + return "hi"; + } + + resource function post hi(@http:Payload string payload) returns string { + return "hi"; + } + + resource function post hello() returns string { + return "hello"; + } + + resource function post hey(@http:Header string header) returns string { + return "hey"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_3/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_3/Ballerina.toml new file mode 100644 index 0000000000..2122d33109 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_3/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "codeaction_sample_3" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_3/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_3/service.bal new file mode 100644 index 0000000000..a8100a3654 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_3/service.bal @@ -0,0 +1,42 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service class RequestInterceptor { + *http:RequestInterceptor; +} + +service class RequestErrorInterceptor { + *http:RequestErrorInterceptor; +} + +service class ResponseInterceptor { + *http:ResponseInterceptor; +} + +service class ResponseErrorInterceptor { + *http:ResponseErrorInterceptor; +} + +service /greeting on new http:Listener(9090) { + resource function get hi() returns string { + return "hi"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_4/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_4/Ballerina.toml new file mode 100644 index 0000000000..0fba9fca75 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_4/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "codeaction_sample_4" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_4/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_4/service.bal new file mode 100644 index 0000000000..a7c0cea0bc --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_codeaction_package_4/service.bal @@ -0,0 +1,186 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). +// +// 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +import ballerina/http; +import ballerina/log; + +# The service type that handles the social media API +@http:ServiceConfig { + mediaTypeSubtypePrefix: "vnd.socialMedia", + basePath: "/socialMedia" +} +public type Service service object { + *http:ServiceContract; + *http:InterceptableService; + + public function createInterceptors() returns ErrorInterceptor; + + # Get all users + # + # + return - List of users(`User[]`) or an error + @http:ResourceConfig { + name: "users" + } + resource function get users() returns @http:Cache {maxAge: 10} User[]|error; + + # Get a user by ID + # + # + id - User ID + # + return - `User` or NotFound response(`UserNotFound`) when the user is not found or an error + @http:ResourceConfig { + name: "user", + linkedTo: [ + {name: "user", method: http:DELETE, relation: "delete-user"}, + {name: "posts", method: http:POST, relation: "create-posts"}, + {name: "posts", method: http:GET, relation: "get-posts"} + ] + } + resource function get users/[int id]() returns User|UserNotFound|error; + + # Create a new user + # + # + newUser - New user details(`NewUser`) as payload + # + return - Created(`http:Created`) response or an error + @http:ResourceConfig { + name: "users", + linkedTo: [ + {name: "user", method: http:GET, relation: "get-user"}, + {name: "user", method: http:DELETE, relation: "delete-user"}, + {name: "posts", method: http:POST, relation: "create-posts"}, + {name: "posts", method: http:GET, relation: "get-posts"} + ], + consumes: ["application/vnd.socialMedia+json"] + } + resource function post users(NewUser newUser) returns http:Created|error; + + # Delete a user by ID + # + # + id - User ID + # + return - NoContent response(`http:NoContent`) or an error + @http:ResourceConfig { + name: "user" + } + resource function delete users/[int id]() returns http:NoContent|error; + + # Get all posts of a user + # + # + id - User ID + # + return - List of posts with metadata(`PostWithMeta[]`) or NotFound response(`UserNotFound`) when the user is not found or an error + @http:ResourceConfig { + name: "posts" + } + resource function get users/[int id]/posts() returns @http:Cache {maxAge: 25} PostWithMeta[]|UserNotFound|error; + + # Create a new post for a user + # + # + id - User ID + # + newPost - New post details(`NewPost`) as payload + # + return - Created(`http:Created`) response or an error + @http:ResourceConfig { + name: "posts", + linkedTo: [ + {name: "posts", method: http:POST, relation: "create-posts"} + ], + consumes: ["application/vnd.socialMedia+json"] + } + resource function post users/[int id]/posts(@http:Payload NewPost newPost) returns http:Created|UserNotFound|PostForbidden|error; +}; + +public isolated service class ErrorInterceptor { + *http:ResponseErrorInterceptor; + + isolated remote function interceptResponseError(error err, http:Response res, http:RequestContext ctx) returns DefaultResponse { + log:printError("error occurred", err); + return { + body: err.message(), + status: new (res.statusCode) + }; + } +} + +# Represents a user in the system +# +# + id - user ID +# + name - user name +# + email - user email +public type User record { + int id; + string name; + string email; +}; + +# Represents a new user +# +# + name - user name +# + email - user email +public type NewUser record { + string name; + string email; +}; + +# Represents a user not found error +# +# + body - error message +public type UserNotFound record {| + *http:NotFound; + ErrorMessage body; +|}; + +# Represents a new post +# +# + content - post content +public type NewPost record { + string content; +}; + +# Represents a post with metadata +# +# + id - post ID +# + content - post content +# + createdAt - post creation time +public type PostWithMeta record { + int id; + string content; + string createdAt; +}; + +# Represents a post forbidden error +# +# + body - error message +public type PostForbidden record {| + *http:Forbidden; + ErrorMessage body; +|}; + +# Represents a default response +# +# + body - response body +public type DefaultResponse record {| + *http:DefaultStatusCodeResponse; + ErrorMessage body; +|}; + +# Represents a error message +public type ErrorMessage string; + +service Service on new http:Listener(9090) { + +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_1/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_1/Ballerina.toml new file mode 100644 index 0000000000..343cbe9aec --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_1/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "http_test" +name = "sample_completion_package_1" +version = "0.1.0" + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_1/main.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_1/main.bal new file mode 100644 index 0000000000..efcc19b9f9 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_1/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service /greeting on new http:Listener(9090) { + r +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_2/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_2/Ballerina.toml new file mode 100644 index 0000000000..0c2c5d78cc --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_2/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_completion_package_2" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_2/main.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_2/main.bal new file mode 100644 index 0000000000..fde46f74fd --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_completion_package_2/main.bal @@ -0,0 +1,37 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service /greeting on new http:Listener(9090) { + r + + resource function post() returns string { + return "Hello Ballerina"; + } +} + +service /greeting on new http:Listener(8080) { + + resource function post() returns string { + return "Hello Ballerina"; + } + + r +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_1/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_1/Ballerina.toml new file mode 100644 index 0000000000..23d86f4406 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_1/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_1" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_1/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_1/service.bal new file mode 100644 index 0000000000..25830e35b7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_1/service.bal @@ -0,0 +1,49 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service http:Service on new http:Listener(9090) { + + string abc = "as"; + + resource function get greeting() { + } + + isolated resource function post noGreeting() { + } + + private function hello() returns string { + return "yo"; + } + + isolated remote function greeting() returns string { + return "Hello"; + } + + function hello2() returns string { + return "yo"; + } + + remote function greeting2() returns string|http:Response { + return "Hello"; + } +} + +service http:Service on new http:Listener(9091) { + remote function greeting2(http:Caller caller) { + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_10/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_10/Ballerina.toml new file mode 100644 index 0000000000..c5bda67204 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_10/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_10" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_10/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_10/service.bal new file mode 100644 index 0000000000..a15271967e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_10/service.bal @@ -0,0 +1,155 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +type Person record {| + int id; + string name; +|}; + +type AA record {| + string a; +|}; + +type NewError http:Error; + +type StatusResponse http:Ok|http:BadRequest; + +service http:Service on new http:Listener(9090) { + resource function get callerInfo1(int xyz, @http:CallerInfo {respondType: string} http:Caller abc) { + checkpanic abc->respond("done"); + } + + resource function get callerInfo2(@http:CallerInfo {respondType: int} http:Caller abc) { + error? err = abc->respond(56); + } + + resource function get callerInfo3(@http:CallerInfo {respondType: int} http:Caller abc) { + var err = abc->respond({a:"abc"}); + if (err is error) { + } + } + + resource function get callerInfo4(@http:CallerInfo {respondType: decimal} http:Caller abc) returns error? { + return abc->respond(5.6); + } + + resource function get callerInfo5(@http:CallerInfo {respondType: string} http:Caller abc) returns error? { + var a = check abc->respond("done"); + } + + resource function get callerInfo6(@http:CallerInfo {respondType: decimal} http:Caller abc) returns error? { + return abc->respond(5565.6d); + } + + resource function get callerInfo7(@http:CallerInfo {} http:Caller abc) returns error? { + return abc->respond(54341.6); // no validation + } + + resource function get callerInfo8(@http:CallerInfo http:Caller abc) returns error? { + var a = abc->respond("ufww"); // no validation + if (a is error) { + } + } + + resource function get callerInfo9(@http:CallerInfo {respondType: Person}http:Caller abc) returns error? { + error? a = abc->respond({id:123, name:"elle"}); + } + + resource function get callerInfo10(@http:CallerInfo {} http:Caller abc) returns error? { + checkpanic abc->respond(); // empty annotation value exp + } + + resource function get callerInfo11(@http:CallerInfo {respondType: Person}http:Caller abc) returns error? { + return abc->'continue(); // different remote method call + } + + resource function get callerInfo12(int xyz, @http:CallerInfo {respondType: string} http:Caller abc) { + int a = 5; + if (a > 0) { + checkpanic abc->respond("Go"); + } else { + error? ab = abc->respond({a:"hello"}); //error + } + } + + resource function get callerInfo13(@http:CallerInfo {respondType: string} http:Caller abc, http:Caller xyz) { + checkpanic xyz->respond("done"); // error:multiple callers + } + + resource function get callerInfo14(@http:CallerInfo {respondType: string} http:Caller abc) { + checkpanic abc->respond("done"); // multiple annotations + } + + resource function get callerInfo15(@http:CallerInfo {respondType: string} http:Caller abc) returns error? { + http:Client c = check new("path"); + http:Response|error a = c->get("done"); // different remote method call + if (a is error) { + } + } + + resource function get callerInfo16(@http:CallerInfo {respondType: Person}http:Caller abc) returns error? { + Person p = {id:123, name:"elle"}; + error? a = abc->respond(p); + } + + resource function get callerInfo17(@http:CallerInfo {respondType: Person}http:Caller abc) returns error? { + error? a = abc->respond({school:1.23}); // This getting passed as map and this is a limitation + } + + resource function get callerInfo18(@http:CallerInfo {respondType: Person}http:Caller abc) returns error? { + AA val = { a: "hello" }; + error? a = abc->respond(val); // error + } + + resource function get callerInfo19(@http:CallerInfo {respondType: Person} http:Caller abc) returns error? { + check abc->respond(error("hello world")); // error + } + + resource function get callerInfo20(@http:CallerInfo {respondType: http:Error} http:Caller abc) returns error? { + check abc->respond( error("hello world")); + } + + resource function get callerInfo21(@http:CallerInfo {respondType: http:Error} http:Caller abc) returns error? { + check abc->respond(error("hello world")); // error + } + + resource function get callerInfo22(@http:CallerInfo{respondType: NewError} http:Caller caller) returns error? { + check caller->respond( error("New Error")); + } + + resource function get callerInfo23(@http:CallerInfo{respondType: http:Ok} http:Caller caller) returns error? { + check caller->respond(http:OK); + } + + resource function get callerInfo24(@http:CallerInfo{respondType: http:Ok} http:Caller caller) returns error? { + check caller->respond(http:NOT_FOUND); // error + } + + resource function get callerInfo25(@http:CallerInfo{respondType: http:StatusCodeResponse} http:Caller caller) returns error? { + check caller->respond(http:NOT_FOUND); + } + + resource function get callerInfo26(@http:CallerInfo{respondType: http:StatusCodeResponse} http:Caller caller) returns error? { + check caller->respond("hello wold"); // error + } + + resource function get callerInfo27(@http:CallerInfo{respondType: StatusResponse} http:Caller caller) returns error? { + http:BadRequest res = {body: {message: "Bad Request"}}; + check caller->respond(res); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_11/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_11/Ballerina.toml new file mode 100644 index 0000000000..56734fb6c3 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_11/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_11" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_11/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_11/service.bal new file mode 100644 index 0000000000..30713a2eca --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_11/service.bal @@ -0,0 +1,144 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/mime; +import ballerina/io; + +type RetEmployee record {| + readonly int id; + string name; +|}; + +type PersonTable table key(id); +type Xml xml; +type ByteArr byte[]; +type MapJson map; +type MapJsonArr map[]; +type EntityArr mime:Entity[]; +type PersonTableArr PersonTable[]; +type ByteStream stream; + +service http:Service on new http:Listener(9090) { + resource function get callerInfo17(int xyz, @http:CallerInfo {respondType: http:Response} http:Caller abc) { + http:Response res = new; + checkpanic abc->respond(res); + } + + resource function get callerInfo18(int xyz, @http:CallerInfo {respondType: http:Response} http:Caller abc) { + checkpanic abc->respond("res"); // error + } + + resource function get callerInfo20(int xyz, @http:CallerInfo {respondType: Xml} http:Caller abc) { + xml x = xml `Hello World`; + checkpanic abc->respond(x); + } + + resource function get callerInfo21(int xyz, @http:CallerInfo {respondType: Xml} http:Caller abc) { + checkpanic abc->respond("res"); // error + } + + resource function get callerInfo2_2(int xyz, @http:CallerInfo {respondType: json} http:Caller abc) { + json j = {hello: "world"}; + checkpanic abc->respond(j); + } + + resource function get callerInfo22(int xyz, @http:CallerInfo {respondType: json} http:Caller abc) { + checkpanic abc->respond({hello: "world"}); // this is also fails and a limitation for inline json + } + + resource function get callerInfo23(int xyz, @http:CallerInfo {respondType: json} http:Caller abc) { + http:Response res = new; + checkpanic abc->respond(res); // error + } + + resource function get callerInfo24(int xyz, @http:CallerInfo {respondType: ByteArr} http:Caller abc) { + checkpanic abc->respond("Sample Text".toBytes()); + } + + resource function get callerInfo25(int xyz, @http:CallerInfo {respondType: ByteArr} http:Caller abc) { + http:Response res = new; + checkpanic abc->respond(res); // error + } + + resource function get callerInfo26(int xyz, @http:CallerInfo {respondType: MapJson} http:Caller abc) { + map jj = {sam: {hello:"world"}, jon: {no:56}}; + checkpanic abc->respond(jj); + } + + resource function get callerInfo27(int xyz, @http:CallerInfo {respondType: MapJson} http:Caller abc) { + http:Response res = new; + checkpanic abc->respond(res); // error + } + + resource function get callerInfo28(int xyz, @http:CallerInfo {respondType: PersonTable} http:Caller abc) { + PersonTable tbPerson = table [ + {id: 1, name: "John"}, + {id: 2, name: "Bella"} + ]; + checkpanic abc->respond(tbPerson); + } + + resource function get callerInfo29(int xyz, @http:CallerInfo {respondType: PersonTable} http:Caller abc) { + checkpanic abc->respond("res"); // error + } + + resource function get callerInfo30(int xyz, @http:CallerInfo {respondType: MapJsonArr} http:Caller abc) { + map jj = {sam: {hello:"world"}, jon: {no:56}}; + map[] arr = [jj, jj]; + checkpanic abc->respond(arr); + } + + resource function get callerInfo31(int xyz, @http:CallerInfo {respondType: MapJsonArr} http:Caller abc) { + http:Response res = new; + checkpanic abc->respond(res); // error + } + + resource function get callerInfo32(int xyz, @http:CallerInfo {respondType: PersonTableArr} http:Caller abc) { + PersonTable tbPerson = table [ + {id: 1, name: "John"}, + {id: 2, name: "Bella"} + ]; + PersonTableArr arr = [tbPerson, tbPerson]; + checkpanic abc->respond(arr); + } + + resource function get callerInfo33(int xyz, @http:CallerInfo {respondType: PersonTableArr} http:Caller abc) { + checkpanic abc->respond("res"); // error + } + + resource function get callerInfo34(int xyz, @http:CallerInfo {respondType: EntityArr} http:Caller abc) { + mime:Entity bodyPart = new; + bodyPart.setJson({"bodyPart":"jsonPart"}); + checkpanic abc->respond([bodyPart, bodyPart]); + } + + resource function get callerInfo35(int xyz, @http:CallerInfo {respondType: EntityArr} http:Caller abc) { + checkpanic abc->respond("res"); // error + } + + resource function get callerInfo36(http:Request request, + @http:CallerInfo {respondType: ByteStream} http:Caller abc) { + var str = request.getByteStream(); + if (str is stream) { + error? err = abc->respond(str); + } + } + + resource function get callerInfo37(@http:CallerInfo {respondType: ByteStream} http:Caller abc) { + checkpanic abc->respond("res"); // error + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_12/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_12/Ballerina.toml new file mode 100644 index 0000000000..7cda7eff80 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_12/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_12" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_12/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_12/service.bal new file mode 100644 index 0000000000..f5d651e768 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_12/service.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service http:Service on new http:Listener(9090) { + + resource function get multiple1(@http:CallerInfo {respondType:string} http:Caller abc, http:Request req, + http:Headers head, http:Caller xyz, http:Headers noo, http:Request aaa) { + checkpanic xyz->respond("done"); + } + + resource function get multiple2(http:Caller abc, @http:CallerInfo http:Caller ccc) { + } + + resource function get multiple3(http:Request abc, @http:CallerInfo http:Caller ccc, http:Request fwdw) { + } + + resource function get multiple4(http:Headers abc, http:Headers ccc) { + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_13/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_13/Ballerina.toml new file mode 100644 index 0000000000..d6c13960b9 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_13/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_13" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_13/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_13/service.bal new file mode 100644 index 0000000000..2ba21f626e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_13/service.bal @@ -0,0 +1,55 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + resource function get invalid (http:Caller caller, string action) returns http:BadRequest? { + if action == "complete" { + error? result = caller->respond("This is successful"); + } else { + http:BadRequest result = { + body: "Provided `action` parameter is invalid" + }; + return result; + } + } + + resource function get valid (string action) returns http:Accepted|http:BadRequest { + if action == "complete" { + http:Accepted result = { + body: "Request was successfully processed" + }; + return result; + } else { + http:BadRequest result = { + body: "Provided `action` parameter is invalid" + }; + return result; + } + } + + resource function get validWithCaller (http:Caller caller, string action) returns error? { + check caller->respond("Hello, World..!"); + } + + resource function get validWithHttpErrors (http:Caller caller, http:Request request) returns http:ListenerError|http:ClientError? { + string payload = check request.getTextPayload(); + if payload == "sample content" { + check caller->respond("Received message"); + } + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_14/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_14/Ballerina.toml new file mode 100644 index 0000000000..d7e2fd98b8 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_14/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_14" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_14/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_14/service.bal new file mode 100644 index 0000000000..1f4a5ae3d7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_14/service.bal @@ -0,0 +1,90 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +@http:ServiceConfig {} +service /test1 on new http:Listener(9999) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} + +@http:ServiceConfig { + host : "b7a.default" +} +service /test2 on new http:Listener(9998) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} + +@http:ServiceConfig { + host : "b7a.default", + mediaTypeSubtypePrefix : "prefix.subType" +} +service /test3 on new http:Listener(9997) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} + +@http:ServiceConfig { + host : "b7a.default", + mediaTypeSubtypePrefix : "prefix.subType+suffix" +} +service /test4 on new http:Listener(9996) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} + +@http:ServiceConfig { + host : "b7a.default", + mediaTypeSubtypePrefix : "vnd.prefix.subType + suffix1 + suffix2" +} +service /test4 on new http:Listener(9996) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} + +@http:ServiceConfig { + host : "b7a.default", + mediaTypeSubtypePrefix : "+suffix" +} +service /test5 on new http:Listener(9995) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} + +@http:ServiceConfig { + host : "b7a.default", + mediaTypeSubtypePrefix : "vnd.prefix.subtype+ " +} +service /test6 on new http:Listener(9994) { + + resource function get test (http:Request req) returns string { + return "test"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_15/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_15/Ballerina.toml new file mode 100644 index 0000000000..b882df0cab --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_15/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_15" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_15/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_15/service.bal new file mode 100644 index 0000000000..a038762efe --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_15/service.bal @@ -0,0 +1,97 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// DO NOT CHANGE THE EXISTING CODE SINCE IT WILL CAUSE TEST FAILURES +// TESTS ARE SENSITIVE TO SINGLE LINE/CHARACTER CHANGES + +import ballerina/http; + +type Person record {| + readonly int id; +|}; + +public annotation Person Pp on parameter; + +service / on new http:Listener(9999) { + + resource function get test102() returns map { + http:Client httpClient = checkpanic new("path"); + return {name:httpClient}; + } + + @display { + label: "TestLabel", + iconPath: "label.png" + } + resource function get test103() returns int|error|string { + return error http:Error("hello") ; + } + + resource function post test104(int num, @http:Payload json abc, @Pp {id:0} string a) returns string { + return "done"; + } + + resource function get test106(table key(id) abc) returns string { + return "done"; + } + + resource function post test107(@http:Payload http:Caller[] abc) returns string { + return "done"; // error + } + + resource function post test108(@http:Payload @http:Header xml abc) returns string { + return "done"; + } + + resource function get test109(@http:Header {name: "x-type"} http:Request abc) returns string { + return "done"; //error + } + + resource function get test110(@http:Header {name: "x-type"} string|json abc) returns string { + return "done"; //error + } + + resource function get test111(@http:CallerInfo http:Caller abc) returns string { + return "done"; //error + } + + resource function get test112(map? c, map d) returns string { + return "done"; + } + resource function get test113(int[]|json c) returns string { + return "done"; + } + + @http:ResourceConfig { + consumes: ["fwhbw"] + } + resource function get test115(@http:CallerInfo {respondType:string} http:Caller abc, http:Request req, + http:Headers head, http:Caller xyz, http:Headers noo, http:Request aaa) { + checkpanic xyz->respond("done"); + } + + resource function get test118(http:Caller caller, string action) returns http:BadRequest? { + if action == "complete" { + error? result = caller->respond("This is successful"); + } else { + http:BadRequest result = { + body: "Provided `action` parameter is invalid" + }; + return result; + } + } + +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_16/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_16/Ballerina.toml new file mode 100644 index 0000000000..2313880bf6 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_16/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_16" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_16/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_16/service.bal new file mode 100644 index 0000000000..adff57d10e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_16/service.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service http:Service on new http:Listener(9090) { + + @http:ResourceConfig { + produces: ["fwhbw"] + } + @http:ResourceConfig { + consumes: ["fwhbw"] + } + resource function get greeting3() returns int|error|string { + return error http:Error("hello") ; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_17/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_17/Ballerina.toml new file mode 100644 index 0000000000..3811b3ce43 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_17/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_17" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_17/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_17/service.bal new file mode 100644 index 0000000000..54801e4849 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_17/service.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /path on new http:Listener(9090) { + + resource function get requestContext1(http:RequestContext a, http:Request req, http:Caller caller) returns error? { + check caller->respond("done"); + } + + resource function get requestContext2(http:RequestContext abc, http:RequestContext bcd) returns string { + return "done"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_18/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_18/Ballerina.toml new file mode 100644 index 0000000000..e70e102455 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_18/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_18" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_18/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_18/service.bal new file mode 100644 index 0000000000..b5ea226ac1 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_18/service.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /path on new http:Listener(9090) { + + resource function get requestContext1(error a, http:Request req, http:Caller caller) returns error? { + check caller->respond("done"); + } + + resource function get requestContext2(error abc, error bcd) returns string { + return "done"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_19/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_19/Ballerina.toml new file mode 100644 index 0000000000..d2974274bd --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_19/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_19" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_19/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_19/service.bal new file mode 100644 index 0000000000..7cddda1aab --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_19/service.bal @@ -0,0 +1,364 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +// Positive Cases + +class HelloWorld { + string hello = "HelloWorld"; + + function greeting() returns string{ + return self.hello; + } +} + +service class InterceptorService0 { + + resource function get greeting(http:RequestContext ctx, http:Request req, http:Caller caller) returns string { + req.setTextPayload("interceptor"); + return "HelloWorld"; + } +} + +service class InterceptorService1 { + *http:RequestInterceptor; + + resource function get greeting(http:RequestContext ctx, http:Request req, http:Caller caller) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService2 { + *http:RequestInterceptor; + + resource function post [string... path](http:Caller caller, http:Request req) returns error? { + req.setTextPayload("interceptor"); + check caller->respond(path); + } +} + +service class InterceptorService3 { + *http:RequestInterceptor; + + resource function 'default [string... path](http:Caller caller, http:RequestContext ctx, http:Request req) { + req.setTextPayload("interceptor"); + } +} + +service class InterceptorService4 { + *http:RequestInterceptor; + + resource function get [string... path](http:Caller caller, http:RequestContext ctx, http:Request req) returns error { + return error("new error"); + } +} + +service class InterceptorService5 { + *http:RequestErrorInterceptor; + + resource function 'default [string... path](http:RequestContext ctx, http:Request req, error err) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService6 { + *http:RequestInterceptor; + + resource function post [string... path](string q1, int q2, @http:Payload string payload, @http:Header string foo, http:Caller caller) returns error? { + check caller->respond(payload); + } +} + +service class RequestInterceptor1 { + *http:RequestInterceptor; + + resource function get greeting(http:RequestContext ctx, http:Request req, http:Caller caller) returns string { + req.setTextPayload("interceptor"); + return "HelloWorld"; + } +} + +service class ResponseInterceptor1 { + *http:ResponseInterceptor; + + remote function interceptResponse() { + } +} + +service class ResponseInterceptor2 { + *http:ResponseInterceptor; + + remote function interceptResponse (http:RequestContext ctx) returns http:NextService|error? { + return ctx.next(); + } +} + +service class ResponseInterceptor3 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx, http:Response res) returns http:NextService|error? { + res.setHeader("response-interceptor", "hello-world"); + return ctx.next(); + } +} + +service class ResponseInterceptor4 { + *http:ResponseInterceptor; + + remote function interceptResponse (http:Response res) { + res.setHeader("response-interceptor", "hello-world"); + } +} + +service class ResponseInterceptor5 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:Caller caller, http:Response res) returns error? { + res.setHeader("response-interceptor", "hello-world"); + check caller->respond(res); + } +} + +service class ResponseInterceptor6 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:Caller caller, http:Response res) returns error? { + res.setHeader("response-interceptor", "hello-world"); + return caller->respond(res); + } +} + +service class ResponseInterceptor7 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx, http:Caller caller) returns http:NextService|error? { + check caller->respond("greetings"); + return ctx.next(); + } +} + +service class ResponseErrorInterceptorService1 { + *http:ResponseErrorInterceptor; + + remote function interceptResponseError (error err, http:RequestContext ctx) returns http:NextService|error? { + return ctx.next(); + } +} + +service class ResponseInterceptor11 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx, http:Request req) returns http:NextService|error? { + return ctx.next(); + } +} + +// Negative Cases + +service class InterceptorService7 { + *http:RequestInterceptor; + *http:RequestErrorInterceptor; + + resource function 'default [string... path](http:RequestContext ctx, http:Request req, error err) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService8 { + *http:RequestErrorInterceptor; + + resource function 'default foo(http:RequestContext ctx, http:Request req, error err) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService9 { + *http:RequestErrorInterceptor; + + resource function get [string... path](http:RequestContext ctx, http:Request req, error err) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService10 { + *http:RequestErrorInterceptor; + + resource function get foo(http:RequestContext ctx, http:Request req, error err) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService11 { + *http:RequestInterceptor; + + resource function get greeting() returns error[] { + error e1 = error http:ListenerError("hello1"); + error e2 = error http:ListenerError("hello2"); + return [e1, e2]; + } +} + +service class InterceptorService12 { + *http:RequestInterceptor; + + resource function get greeting1(http:RequestContext ctx, http:Request req, http:Caller caller) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } + + resource function get greeting2(http:RequestContext ctx, http:Request req, http:Caller caller) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService13 { + *http:RequestInterceptor; + + @http:ResourceConfig{} + resource function get greeting1(http:RequestContext ctx, http:Request req, http:Caller caller) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService14 { + *http:RequestErrorInterceptor; + + resource function 'default [string path](http:RequestContext ctx, http:Request req, http:Caller caller) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service class InterceptorService15 { + *http:RequestInterceptor; + + resource function get greeting(http:RequestContext ctx, @http:Payload string abc) returns http:NextService|error? { + return ctx.next(); + } +} + +service class InterceptorService16 { + *http:RequestInterceptor; +} + +service class InterceptorService17 { + *http:RequestErrorInterceptor; +} + +service class InterceptorService18 { + *http:ResponseInterceptor; +} + +service class RequestInterceptorService1 { + *http:RequestInterceptor; + + remote function interceptResponse(http:RequestContext ctx) returns http:NextService|error? { + return ctx.next(); + } +} + +service class RequestErrorInterceptorService1 { + *http:RequestErrorInterceptor; + + remote function interceptResponse(http:RequestContext ctx) returns http:NextService|error? { + return ctx.next(); + } +} + +service class ResponseInterceptor8 { + *http:ResponseInterceptor; + + resource function post [string... path](http:Caller caller, http:Request req) returns error? { + req.setTextPayload("interceptor"); + check caller->respond(path); + } +} + +service class ResponseInterceptor9 { + *http:ResponseInterceptor; + + remote function returnResponse(http:RequestContext ctx, http:Response res) returns http:NextService|error? { + res.setHeader("response-interceptor", "hello-world"); + return ctx.next(); + } +} + +service class ResponseInterceptor10 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx, http:Response res1, http:Response res2) returns http:NextService|error? { + res1.setHeader("response-interceptor", "hello-world"); + return ctx.next(); + } +} + +service class ResponseInterceptor12 { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx, string payload) returns http:NextService|error? { + return ctx.next(); + } +} + +service class ResponseInterceptor13 { + *http:ResponseInterceptor; + + remote function interceptResponse() returns http:Client { + http:Client httpClient = checkpanic new("path"); + return httpClient; + } +} + +service class ResponseInterceptor14 { + *http:ResponseInterceptor; + + remote function interceptResponse() returns @http:Payload string { + return "hello"; + } +} + +service class RequestInterceptor2 { + *http:RequestInterceptor; + + resource function post [string... path]() returns @http:Cache string { + return "hello"; + } +} + +service class ResponseErrorInterceptorService2 { + *http:ResponseErrorInterceptor; + + remote function interceptError(error err, http:RequestContext ctx) returns http:NextService|error? { + return ctx.next(); + } +} + +service class ResponseErrorInterceptorService3 { + *http:ResponseErrorInterceptor; + + remote function interceptResponseError(http:RequestContext ctx) returns http:NextService|error? { + return ctx.next(); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_2/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_2/Ballerina.toml new file mode 100644 index 0000000000..e6f865d707 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_2/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_2" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_2/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_2/service.bal new file mode 100644 index 0000000000..68c76df9d2 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_2/service.bal @@ -0,0 +1,247 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +type Person record {| + readonly int id; + string name; +|}; + +type RetPerson record { + string name; + int age; +}; + +type PersonTable table key(id); +type newXml xml; +type newXmlElement xml:Element; + +type ReturnValueStrNilArray string?[]?; +type ReturnValuePrimitiveUnionArr (string|int)[]; +type ReturnValueNilPrimitiveUnionArr (string|int?)[]?; +type ReturnValueNilPrimitiveUnionArrAlt (string?|int?)[]?; + +service http:Service on new http:Listener(9090) { + resource function get greeting() returns int|error|string { + return error http:Error("hello") ; + } + + resource function get greeting2() returns http:Error { + return error http:ListenerError("hello") ; + } + + resource function post greeting3() returns () { + // Request hangs without a response + return; + } + + resource function get greeting5() returns Person { + return {id:123, name: "john"}; + } + + resource function get greeting6() returns string[] { + return ["Abc", "Xyz"]; + } + + resource function get greeting7() returns int[] { + return [15, 34]; + } + + resource function get greeting8() returns error[] { // Compiler error + error e1 = error http:ListenerError("hello1"); + error e2 = error http:ListenerError("hello2"); + return [e1, e2]; + } + + resource function get greeting9() returns byte[] { + byte[] binaryValue = "Sample Text".toBytes(); + return binaryValue; + } + + resource function get greeting10() returns map { + return {}; + } + + resource function get greeting11() returns PersonTable { + PersonTable tbPerson = table [ + {id: 1, name: "John"}, + {id: 2, name: "Bella"} + ]; + return tbPerson; + } + + resource function get greeting12() returns table key(id) { + PersonTable tbPerson = table [ + {id: 1, name: "John"}, + {id: 2, name: "Bella"} + ]; + return tbPerson; + } + + resource function get greeting13() returns map { + http:Client httpClient = checkpanic new("path"); + return {name:httpClient}; + } + + resource function get greeting14() returns http:Ok { + return {}; + } + + resource function get greeting15() returns Person[] { + return [{id:123, name: "john"}, {id:124, name: "khan"}]; + } + + resource function post greeting16() returns @http:Payload {mediaType:["application/json+123"]} json { + return {hello: "world"}; + } + + resource function post greeting17() returns @http:Payload {mediaType:["text/xml", "app/xml"]} xml { + return xml `Hello World`; + } + + resource function get greeting18() returns http:Response { + http:Response resp = new; + return resp; + } + + resource function post greeting19() returns @http:Payload {mediaType:["text/plain"]} int { + return 56; + } + + resource function get greeting20() returns float { + return 3.2456; + } + + resource function get greeting21() returns decimal { + return 3.2; + } + + resource function get greeting22() returns boolean { + return true; + } + + resource function post greeting23() returns @http:Payload {mediaType:"application/json"} http:Created|http:Ok { + http:Created cre = { body: {hello:"World"}, headers: { xtest: "Elle"}, mediaType:"application/json+id" }; + return cre; + } + + resource function get greeting24() returns record {|*http:Created; RetPerson body;|} { + RetPerson person = {age:1, name:"Joe"}; + return { + mediaType: "application/person+json", + headers: { + "X-Server": "myServer" + }, + body: person + }; + } + + resource function get greeting25() returns PersonTable[] { + PersonTable tbPerson = table [ + {id: 1, name: "John"}, + {id: 2, name: "Bella"} + ]; + return [tbPerson, tbPerson]; + } + + resource function get greeting26() returns map[]|string { + map jj = {sam: {hello:"world"}, jon: {no:56}}; + return [jj,jj]; + } + + resource function get greetings(http:Request req) returns readonly & error[] { + return [error("error1"), error("error2")]; + } + + resource function get element() returns xml:Element { + return xml ` + PLACED + ORD-1234 + `; + } + + resource function get text() returns xml:Text|json { + return {a:"hello"}; + } + + resource function get comment() returns xml:Comment|json { + return {a:"hello"}; + } + + resource function get processingInstruction() returns xml:ProcessingInstruction|json { + return {a:"hello"}; + } + + resource function get strChar() returns string:Char { + return "a"; + } + + resource function get intSigned32() returns int:Signed32 { + return -2147483648; + } + + resource function get intSigned16() returns int:Signed16 { + return -32768; + } + + resource function get intSigned8() returns int:Signed8 { + return -128; + } + + resource function get intUnsigned32() returns int:Unsigned32 { + return 4294967295; + } + + resource function get intUnsigned16() returns int:Unsigned16 { + return 65535; + } + + resource function get intUnsigned8() returns int:Unsigned8 { + return 255; + } + + resource function get customSubtypes() returns newXml { + return xml`Tharmigan`; + } + + resource function get customXmlElement() returns newXmlElement { + return xml ` + PLACED + ORD-1234 + `; + } + + resource function get resource1(string id) returns ReturnValueStrNilArray { + string?[]? values = ["val1", ()]; + return values; + } + + resource function get resource2(string id) returns ReturnValuePrimitiveUnionArr { + (string|int)[] values = ["val", 1]; + return values; + } + + resource function get resource3(string id) returns ReturnValueNilPrimitiveUnionArr { + (string|int?)[]? values = ["val", 1, ()]; + return values; + } + + resource function get resource4(string id) returns ReturnValueNilPrimitiveUnionArrAlt { + (string|int?)[]? values = ["val", 1, ()]; + return values; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_20/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_20/Ballerina.toml new file mode 100644 index 0000000000..5b5605bdf5 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_20/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_20" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_20/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_20/service.bal new file mode 100644 index 0000000000..25152ef674 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_20/service.bal @@ -0,0 +1,43 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +// Positive Cases + +type Album readonly & record {| + string id; + string title; + string artist; + decimal price; +|}; + +// albums table to seed record album data. +table key(id) albums = table [ + {id: "1", title: "Blue Train", artist: "John Coltrane", price: 56.99}, + {id: "2", title: "Jeru", artist: "Gerry Mulligan", price: 17.99}, + {id: "3", title: "Sarah Vaughan and Clifford Brown", artist: "Sarah Vaughan", price: 39.99} +]; + +service / on new http:Listener(8080) { + resource function get albums() returns Album[] { + return albums.toArray(); + } + + resource function get album/[int id]() returns Album { + return albums.toArray()[id]; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_21/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_21/Ballerina.toml new file mode 100644 index 0000000000..e6b080f5bb --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_21/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_21" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_21/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_21/service.bal new file mode 100644 index 0000000000..a5dc08458e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_21/service.bal @@ -0,0 +1,92 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +// Positive Cases + +type NewAlbum record {| + string id; + string title; + string artist; + decimal price; +|}; + +type Album readonly & record {| + string id; + string title; + string artist; + decimal price; +|}; + +// albums table to seed record album data. +table key(id) store = table [ + {id: "1", title: "Blue Train", artist: "John Coltrane", price: 56.99}, + {id: "2", title: "Jeru", artist: "Gerry Mulligan", price: 17.99}, + {id: "3", title: "Sarah Vaughan and Clifford Brown", artist: "Sarah Vaughan", price: 39.99} +]; + +service / on new http:Listener(8080) { + resource function post album(@http:Payload Album album) returns Album { + store.add(album); + return album; + } + + resource function post batchUpdate(@http:Payload Album[] albums) returns Album[] { + foreach Album album in albums { + store.add(album); + } + return albums; + } +} + +service / on new http:Listener(8090) { + resource function post album(@http:Payload readonly & NewAlbum album) returns string { + return "album"; + } + + resource function post albumArray(@http:Payload readonly & NewAlbum[] albums) returns string { + return "albumArray"; + } + + resource function post byteArray(@http:Payload readonly & byte[] albums) returns string { + return "byteArray"; + } + + resource function post readonlyString(@http:Payload readonly & string album) returns string { + return "string"; + } + + resource function post readonlyJson(@http:Payload readonly & json album) returns string { + return "json"; + } + + resource function post readonlyXml(@http:Payload readonly & xml album) returns string { + return "xml"; + } + + resource function post readonlyMapString(@http:Payload readonly & map album) returns string { + return "mapOfString"; + } + + resource function post inlineRecord(@http:Payload record {|string name; int age;|} person) returns string { + return "inlineRecord"; + } + + resource function post inlineReadOnlyRecord(@http:Payload readonly & record {|string name; int age;|} person) returns string { + return "inlineReadOnlyRecord"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_22/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_22/Ballerina.toml new file mode 100644 index 0000000000..b7b14af2c5 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_22/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_22" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_22/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_22/service.bal new file mode 100644 index 0000000000..bb642129d2 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_22/service.bal @@ -0,0 +1,31 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(8080) { + resource function get helloError() returns @http:Cache error { + return error("hello"); + } + + resource function get heyError() returns @http:Payload{mediaType: "mediaType"} error { + return error("hey"); + } + + resource function get greeting(http:Caller caller) returns @http:Payload{mediaType: "mediaType"} @http:Cache error? { + check caller->respond("Greetings!"); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_23/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_23/Ballerina.toml new file mode 100644 index 0000000000..733dbead03 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_23/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_23" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_23/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_23/service.bal new file mode 100644 index 0000000000..085ef755bc --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_23/service.bal @@ -0,0 +1,116 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/mime; + +type Person record {| + readonly int id; + string name; +|}; + +type PersonTable table key(id); + +service http:Service on new http:Listener(9090) { + + resource function get withCaller(readonly & http:Caller caller) returns string { //not allowed + return "done"; + } + + resource function get withRequest(readonly & http:Request request) returns string { //not allowed + return "done"; + } + + resource function get withHeadersObj(readonly & http:Headers headers) returns string { //not allowed + return "done"; + } + + resource function get withMimeEntity(readonly & mime:Entity entity) returns string { //not allowed + return "done"; + } + + resource function get withQuery(readonly & int a) returns string { //allowed + return "done"; + } + + resource function get withHeader(@http:Header readonly & string host) returns string { //allowed + return "done"; + } + + resource function get withHeaderArr(@http:Header readonly & string[] host) returns string { //allowed + return "done"; + } + + resource function get withHeaderArrInvalid(@http:Header readonly & json[] host) returns string { //not allowed + return "done"; + } + + resource function get withHeaderWithUnion(@http:Header readonly & string? host) returns string { //allowed + return "done"; + } + + resource function get withCallerInfo(@http:CallerInfo readonly & http:Caller host) returns error? { //allowed + return; + } + + resource function get withCallerInfoWithUnion(@http:CallerInfo readonly & http:Caller? host) returns error? { //not allowed + return; + } + + resource function get returnReadonlyJson() returns readonly & json { // allowed + return "done"; + } + + resource function get returnReadonlyOk() returns readonly & http:Ok { // allowed + http:Ok ok = {}; + return ok.cloneReadOnly(); + } + + resource function get returnReadonlyUnion() returns readonly & map[]|string[] { // allowed + map jj = {sam: {hello:"world"}, jon: {no:56}}; + return [jj,jj].cloneReadOnly(); + } + + resource function get returnReadonlyMap() returns readonly & map { // allowed + map jj = {sam: {hello:"world"}, jon: {no:56}}; + return jj.cloneReadOnly(); + } + + resource function get returnReadonlyTableArr() returns readonly & PersonTable[] { // allowed + PersonTable tbPerson = table [ + {id: 1, name: "John"}, + {id: 2, name: "Bella"} + ]; + return [tbPerson, tbPerson].cloneReadOnly(); + } + + resource function get returnReadonlyRecordArr() returns readonly & Person[] { // allowed + return [{id:123, name: "john"}, {id:124, name: "khan"}].cloneReadOnly(); + } + + // Currently following give error reported in https://github.com/ballerina-platform/ballerina-lang/issues/35332 + // Once it's fixed, uncomment the following case + //resource function get returnReadonlyInlineRecord() returns readonly & record {|*http:Created; Person body;|} { + // Person person = {id:123, name: "john"}; + // return { + // mediaType: "application/person+json", + // headers: { + // "X-Server": "myServer" + // }, + // body: person + // }.cloneReadOnly(); + //} +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_24/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_24/Ballerina.toml new file mode 100644 index 0000000000..7396e67d92 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_24/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_24" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_24/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_24/service.bal new file mode 100644 index 0000000000..4c2c9ac961 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_24/service.bal @@ -0,0 +1,36 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +type NewError error; + +service http:Service on new http:Listener(9090) { + + resource function get callerInfo20(@http:CallerInfo {respondType: http:Error} http:Caller caller) returns error? { + check caller->respond( error("hello world")); + } + + // Will give an error at the moment, since we only support only http:Error error type + resource function get callerInfo21(@http:CallerInfo {respondType: NewError} http:Caller caller) returns error? { + check caller->respond( error("New Error")); + } + + // Will give an error at the moment, since typedesc has a limitation to have error as type + resource function get greeting(@http:CallerInfo{respondType: error} http:Caller caller) returns error? { + check caller->respond(error("New Error")); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_25/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_25/Ballerina.toml new file mode 100644 index 0000000000..82d78b6b5b --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_25/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_25" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_25/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_25/service.bal new file mode 100644 index 0000000000..253864aa07 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_25/service.bal @@ -0,0 +1,122 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service on new http:Listener(9090) { + + @http:ResourceConfig { + name: "resource1", + linkedTo: [ + {name: "resource1", method: "GET"}, + {name: "resource1", method: "post", relation: "add"}, + {name: "resource2", relation: "get"} + ] + } + resource function get resource1/[int someInt]/path1() returns json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "Resource1", + linkedTo: [ + {name: "resource1", method: http:POST}, + {name: "resource3", method: http:GET, relation: "get"}, + {name: "resource3", method: "post", relation: "add"} + ] + } + resource function post resource1/[string someString]/path1() returns json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "resource2" + } + resource function 'default resource2/path1() returns json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "resource3" + } + resource function 'default resource3/path1() returns @http:Payload{mediaType: "application/json"} json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "RESOURCE3" + } + resource function get resource3/path1() returns json { + return {greeting: "hello"}; + } +} + +// Errors +service on new http:Listener(9091) { + + @http:ResourceConfig { + name: "resource1", + linkedTo: [ + {name: "resource1", method: "get"}, + {name: "resource2", method: "get"}, + {name: "resource3", method: "get", relation: "SELF"}, + {name: "resource5", method: "put", relation: "update"} + ] + } + resource function get resource1/[int someInt]/path1() returns json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "resource1", + linkedTo: [ + {name: "resource1", method: "post", relation: "add"}, + {name: "resource3", relation: "get"}, + {name: "resource3", method: "post", relation: "add"} + ] + } + resource function post resource1/[string someString]/path2() returns json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "resource2" + } + resource function get resource2/path1() returns json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "resource3" + } + resource function default resource3/path1() returns @http:Payload{mediaType: "application/json"} json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "resource3" + } + resource function put resource3/path1() returns @http:Payload{mediaType: "application/json"} json { + return {greeting: "hello"}; + } + + @http:ResourceConfig { + name: "Resource3" + } + resource function get resource3/path2() returns json { + return {greeting: "hello"}; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_26/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_26/Ballerina.toml new file mode 100644 index 0000000000..9be052d519 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_26/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_26" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_26/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_26/service.bal new file mode 100644 index 0000000000..48d8dd8cb5 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_26/service.bal @@ -0,0 +1,39 @@ +// Copyright (c) 2022 WSO2 LLC. (http://www.wso2.com) 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; + +type SupplierInfo record { + Quote[] quotes?; +}; + +type Quote record { + SupplierInfo supplier?; +}; + +service on new http:Listener(8081) { + resource function post quotes(@http:Payload Quote quote) returns Quote|error { + return quote; + } + + resource function post suppliers(@http:Payload SupplierInfo supplier) returns SupplierInfo|error { + return supplier; + } + + resource function post inline(@http:Payload record {string id; SupplierInfo supplier;} request) returns string|error { + return request.id; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_27/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_27/Ballerina.toml new file mode 100644 index 0000000000..70965c2717 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_27/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "http_test" +name = "sample_27" +version = "0.1.0" + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_27/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_27/service.bal new file mode 100644 index 0000000000..9ab7af37db --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_27/service.bal @@ -0,0 +1,32 @@ +// Copyright (c) 2022 WSO2 LLC. (http://www.wso2.com) 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; + +type SupplierInfo record { + Quote[] quotes?; +}; + +type Quote record { + SupplierInfo supplier?; +}; + +service on new http:Listener(8081) { + resource function post suppliers(@http:Payload record {string id; SupplierInfo supplier;} request) + returns SupplierInfo|error { + return request.supplier; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/Ballerina.toml new file mode 100644 index 0000000000..5e5697bbd1 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "http_test" +name = "sample_28" +version = "0.1.0" + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/modules/records/records.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/modules/records/records.bal new file mode 100644 index 0000000000..4d84ca79e3 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/modules/records/records.bal @@ -0,0 +1,40 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) 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. + +public enum Status { + OPEN, + CLOSED, + HOLD +} + +public type RecordC readonly & record {| + readonly string id; + string name; + Status status; + int capacity; + boolean night; + int elevationgain; +|}; + +public type RecordD readonly & record {| + readonly string id; + string name; + Status status; + string difficulty; + boolean groomed; + boolean trees; + boolean night; +|}; diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/service.bal new file mode 100644 index 0000000000..0b54707eb8 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_28/service.bal @@ -0,0 +1,85 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) 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 sample_28.records; + +type RecordA record {| + string name; +|}; + +type RecordB readonly & record {| + int age; +|}; + +type TestRecord1 RecordA; + +type TestRecord2 RecordA|RecordB; + +type TestRecord3 RecordA|string; + +type TestRecord4 RecordA|map; + +type TestRecord5 RecordA|table>; + +type TestRecord6 int|table>; + +type TestRecord7 records:RecordC|records:RecordD; + +type TestRecord8 records:RecordC|xml; + +service on new http:Listener(4000) { + + resource function hello1 [string... path]() returns TestRecord1[] { + return [{name: "Hello, World"}]; + } + + resource function hello2 [string... path]() returns TestRecord2[] { + return [{name: "Hello, World"}]; + } + + resource function hello3 [string... path]() returns TestRecord3[] { + return [{name: "Hello, World"}]; + } + + resource function hello4 [string... path]() returns TestRecord4[] { + return [{}]; + } + + resource function hello5 [string... path]() returns TestRecord5[] { + return [{name: "Hello, World"}]; + } + + resource function hello6 [string... path]() returns TestRecord6[] { + return [1]; + } + + resource function hello7 [string... path]() returns TestRecord7[] { + records:RecordC response = { + capacity: 10, + elevationgain: 120, + id: "2", + name: "Test", + night: false, + status: records:HOLD + }; + return [response]; + } + + resource function hello8 [string... path]() returns TestRecord8[] { + return [xml`Test`]; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_29/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_29/Ballerina.toml new file mode 100644 index 0000000000..1c3f0f739b --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_29/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "http_test" +name = "sample_29" +version = "0.1.0" + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_29/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_29/service.bal new file mode 100644 index 0000000000..404e0fa784 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_29/service.bal @@ -0,0 +1,78 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) 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; + +type RecordA record {| + string name; +|}; + +type RecordB readonly & record {| + int age; +|}; + +type TestRecord1 RecordA|http:Request; + +type TestRecord2 RecordA|http:Service; + +type TestRecord3 RecordA|http:Client; + +type TestRecord4 RecordB|http:Client; + +type TestRecord5 RecordA|http:Response; + +type TestRecord6 int|http:StatusCodeResponse; + +type TestRecord7 RecordA|error; + +service on new http:Listener(4000) { + + resource function hello1 [string... path]() returns TestRecord1[] { + return [{name: "Hello, World"}]; + } + + resource function hello2 [string... path]() returns TestRecord2[] { + return [{name: "Hello, World"}]; + } + + resource function hello3 [string... path]() returns TestRecord3[] { + return [{name: "Hello, World"}]; + } + + resource function hello4 [string... path]() returns TestRecord4[] { + return [{age: 12}]; + } + + resource function hello5 [string... path]() returns TestRecord5[] { + return [{name: "Hello, World"}]; + } + + resource function hello6 [string... path]() returns TestRecord6[] { + return [12]; + } + + resource function hello7 [string... path]() returns TestRecord7[] { + return [{name: "Hello, World"}]; + } + + resource function hello8 [string... path]() returns http:StatusCodeResponse[] { + return [http:ACCEPTED]; + } + + resource function hello9 [string... path]() returns error[] { + return [error("Test error")]; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_3/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_3/Ballerina.toml new file mode 100644 index 0000000000..f86be9b6c1 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_3/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_3" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_3/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_3/service.bal new file mode 100644 index 0000000000..04745451c7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_3/service.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service http:Service on new http:Listener(9090) { + @http:ResourceConfig { + consumes: ["fwhbw"] + } + resource function get greeting1() returns int|error|string { + return error http:Error("hello") ; + } + + @display { + label: "TestLabel", + iconPath: "label.png" + } + resource function get greeting2() returns int|error|string { + return error http:Error("hello") ; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_30/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_30/Ballerina.toml new file mode 100644 index 0000000000..52ddcc2b01 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_30/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "http_test" +name = "sample_30" +version = "0.1.0" + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_30/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_30/service.bal new file mode 100644 index 0000000000..8b5b91a927 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_30/service.bal @@ -0,0 +1,56 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) 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; + +public enum Status { + SUCCESS, + FAILURE +} + +public type NewStatus Status; +public type UpdatedStatus NewStatus; + +service / on new http:Listener(9090) { + + resource function get albums(Status status) returns string[] { + return []; + } + + resource function get artists(Status status, http:Caller caller) {} + + resource function get songs(Status status1, Status status2, http:Caller caller) {} + + resource function get tracks(Status[] status) returns string { + return "Track 1"; + } + + resource function get newAlbums(NewStatus status) returns string { + return "Track 1"; + } + + resource function get newTracks(NewStatus[] status) returns string { + return "Track 1"; + } + + resource function get updatedAlbums(UpdatedStatus status) returns string { + return "Track 1"; + } + + resource function get updatedTracks(UpdatedStatus[] status) returns string { + return "Track 1"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_31/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_31/Ballerina.toml new file mode 100644 index 0000000000..0ee79ba01f --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_31/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_31" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_31/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_31/service.bal new file mode 100644 index 0000000000..d549b87ef3 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_31/service.bal @@ -0,0 +1,52 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) 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/io; + +public type BaseMessage record {| + string mtype; + string id?; +|}; + +public type SimpleMessage record {| + *BaseMessage; + "stype" mtype = "stype"; + Meta meta?; + string message; +|}; + +public type MetaA record {| + string mversion; + Meta metadata?; + string strId; +|}; + +public type MetaB record {| + string mversion; + Meta metadata?; + int intId; +|}; + +public type Meta MetaA | MetaB; + +service / on new http:Listener(9090) { + resource function post greeting(@http:Payload SimpleMessage msg) returns string|error { + io:println(msg.message); + + return "Received"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_32/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_32/Ballerina.toml new file mode 100644 index 0000000000..0cdaa589f5 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_32/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_32" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_32/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_32/service.bal new file mode 100644 index 0000000000..dd3bbf49ac --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_32/service.bal @@ -0,0 +1,41 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com) 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; + +public type BaseMessage record {| + string mtype; + string id?; +|}; + +public type SimpleMessage record {| + *BaseMessage; + "stype" mtype = "stype"; + Meta meta?; + string message; +|}; + +public type Meta record {| + string mversion; + Meta metadata?; + string strId; +|}; + +service / on new http:Listener(9090) { + resource function post greeting(@http:Payload readonly & SimpleMessage msg) returns string|error { + return "Received"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_33/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_33/Ballerina.toml new file mode 100644 index 0000000000..a005670bfe --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_33/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_33" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_33/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_33/service.bal new file mode 100644 index 0000000000..9a7f45ce03 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_33/service.bal @@ -0,0 +1,94 @@ +// Copyright (c) 2023, 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; + +type Person record {| + readonly int id; +|}; + +type Pp Person; + +service http:Service on new http:Listener(9090) { + + resource function post singleStructured(Person p) returns string { + return "done"; // p is payload param + } + + resource function post singleStructuredArray(Person[] p) returns string { + return "done"; // p is payload param + } + + resource function post singleStructuredTypeRef(Pp p) returns string { + return "done"; // p is payload param + } + + resource function post singleStructuredWithBasicType(string q, Person p) returns string { + return "done"; // p is payload param + } + + resource function post singleBasicType(string q) returns string { + return "done"; // q is query param + } + + resource function post singleBasicTypeArray(string[] q) returns string { + return "done"; // q is query param + } + + resource function post xmlTest(xml p) returns string { + return "done"; // p is payload param + } + + resource function post xmlElementTest(xml:Element p) returns string { + return "done"; // p is payload param + } + + resource function post testUnion(Person|xml p) returns string { + return "done"; // p is payload param + } + + resource function post testNilableUnion(map? p) returns string { + return "done"; // p is payload param + } + + resource function post testReadonly(readonly & Person p) returns string { + return "done"; + } + + resource function post testReadonlyUnion(readonly & (Person|xml) p) returns string { + return "done"; + } + + resource function post testTable(table> abc) returns string { + return "done"; + } + + resource function post testByteArrArr(byte[][] abc) returns string { + return "done"; + } + + resource function post testTuple([int, string, Person] abc) returns string { + return "done"; + } + + resource function post testInlineRecord(@http:Payload record {|string abc;|} abc) returns string { + return "done"; + } + + resource function post okWithBody(string? xyz, Person abc) returns http:Ok { + return {body: abc}; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_34/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_34/Ballerina.toml new file mode 100644 index 0000000000..cb355528da --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_34/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_34" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_34/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_34/service.bal new file mode 100644 index 0000000000..a80e17f9e8 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_34/service.bal @@ -0,0 +1,148 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/mime; + +class Query {} + +type Caller record {| + int id; +|}; + +// This is user-defined type +public type Count int; +public type TypeJson json; +public type Name string; +public type FirstName Name; +public type FullName FirstName; + +service http:Service on new http:Listener(9090) { + + resource function get callerInfo1(@http:Query string a, @http:Query int[] b, @http:Query float? c, + @http:Query decimal[]? d) returns string { + return "done"; + } + + resource function get callerInfo2(@http:Query string a, @http:Query int[] b) returns string { + return "done"; + } + + resource function get callerInfo3(@http:Query string a, @http:Query int b, @http:Query float c, + @http:Query decimal d, @http:Query boolean e) returns string { + return "done"; + } + + resource function get callerInfo4(@http:Query string? a, @http:Query int? b, @http:Query float? c, + @http:Query decimal? d, @http:Query boolean? e) returns string { + return "done"; + } + + resource function get callerInfo5(@http:Query string[] a, @http:Query int[] b, @http:Query float[] c, + @http:Query decimal[] d, @http:Query boolean[] e) returns string { + return "done"; + } + + resource function get callerInfo6(@http:Query string[]? a, @http:Query int[]? b, @http:Query float[]? c, + @http:Query decimal[]? d, @http:Query boolean[]? e) returns string { + return "done"; + } + + resource function get callerInfo7(@http:Query map aa, @http:Query string? ab, + @http:Query boolean[] ac) returns string { + return "done"; + } + + resource function get callerInfo8(@http:Query map[] ba, @http:Query int bb, + @http:Query decimal[]? bc) returns string { + return "done"; + } + + resource function get callerInfo9(@http:Query float[] cb, @http:Query int[]? cc, + @http:Query map? ca) returns string { + return "done"; + } + + resource function get callerInfo10(@http:Query string[] db, @http:Query boolean dc, + @http:Query map[]? da) returns string { + return "done"; + } + + resource function get callerErr1(@http:Query mime:Entity abc) returns string { + return "done"; + } + + resource function get callerErr2(@http:Query int|string a) returns string { + return "done"; + } + + resource function get callerErr3(@http:Query int|string[]|float b) returns string { + return "done"; + } + + resource function get callerErr4(@http:Query int[]|json c) returns string { + return "done"; + } + + resource function get callerErr5(@http:Query xml? d, @http:Query string e) returns string { + return "done"; + } + + resource function get callerErr6(@http:Query int[]? b, @http:Query json a, @http:Query json[] aa) returns string { + return "done"; + } + + resource function get callerErr7(@http:Query string? b, @http:Query map a) returns string { + return "done"; + } + + resource function get callerErr8(@http:Query map[] b, @http:Query int[] c) returns string { + return "done"; + } + + resource function get callerErr9(@http:Query map? c, @http:Query map d) returns string { + return "done"; + } + + resource function get callerErr10(@http:Query json[] d, @http:Query xml e) returns string { + return "done"; + } + + resource function get pets(@http:Query Count count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get petsUnion(@http:Query Count? count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get petsArr(@http:Query Count[] count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get petsMap(@http:Query map count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get nestedTypeRef(@http:Query FullName names) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_35/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_35/Ballerina.toml new file mode 100644 index 0000000000..286f8283b2 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_35/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_35" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_35/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_35/service.bal new file mode 100644 index 0000000000..f7cffde16f --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_35/service.bal @@ -0,0 +1,75 @@ +// Copyright (c) 2023, 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; + +type Person record {| + readonly int id; +|}; + +type Pp Person; + +class WorkPlace {}; + +type Employee record { + int id; + string name; + WorkPlace workplace; +}; + +service http:Service on new http:Listener(9090) { + + resource function post ambiguous1(Person a, Person b) returns string { + return "done"; // ambiguous + } + + resource function post ambiguous2(map c, Person d) returns string { + return "done"; // ambiguous + } + + resource function post ambiguous3(byte[] e, Person f) returns string { + return "done"; // ambiguous + } + + resource function post ambiguous4(map|string g, Person h) returns string { + return "done"; // ambiguous + } + + resource function post multiple1(@http:Payload @http:Query map g) returns string { + return "done"; // multiple annotation + } + + resource function post unionError(http:Request|string p) returns string { + return "done"; // p is payload param + } + + resource function post testMultipleWithUnion(Person q, map? p) returns string { + return "done"; + } + + resource function post nonAnydataStructuredType1(Employee e) returns string { + return "done"; + } + + resource function post nonAnydataStructuredType2(Employee e, Person p) returns string { + return "done"; + } + + resource function post unionWithNonAnydataStructuredType(Employee|Person a) returns string { + return "done"; + } +} + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_36/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_36/Ballerina.toml new file mode 100644 index 0000000000..f1b079be9a --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_36/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_36" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_36/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_36/service.bal new file mode 100644 index 0000000000..c194ed6308 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_36/service.bal @@ -0,0 +1,60 @@ +// Copyright (c) 2023, 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; + +type Person record {| + readonly int id; +|}; + +class HelloWorld { + string hello = "HelloWorld"; + + function greeting() returns string{ + return self.hello; + } +} + +service class SClass { + *http:Service; + resource function post foo(map p) returns string { + return "done"; + } +} + +service class InterceptorService { + *http:RequestInterceptor; + + resource function post [string... path](string q1, int q2, Person payload, @http:Header string foo, http:Caller caller) returns error? { + check caller->respond(payload); + } +} + +service class ErrorInterceptorService { + *http:RequestErrorInterceptor; + + resource function 'default [string... path](http:RequestContext ctx, http:Request req, Person payload, error err) returns http:NextService|error? { + req.setTextPayload("interceptor"); + return ctx.next(); + } +} + +service http:Service on new http:Listener(9090) { + + resource function post singleStructured(Person p) returns string { + return "done"; // p is payload param + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_37/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_37/Ballerina.toml new file mode 100644 index 0000000000..3e0160c9f9 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_37/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_37" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_37/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_37/service.bal new file mode 100644 index 0000000000..10ef1a08c7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_37/service.bal @@ -0,0 +1,48 @@ +// Copyright (c) 2023, 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; + +enum Path { + PATH1, + PATH2, + PATH3 +} + +type Id string|int; + +service on new http:Listener(9999) { + + resource function get foo/[Path path]() {} + + // error + resource function get [string|int... path1]() {} + + // error + resource function get [boolean|decimal path2]() {} + + // error + resource function get foo/[int|decimal path3]/bar/[string|boolean path4]() {} + + // error + resource function get foo/[boolean|float path5]/[string|float|int... path6]() {} + + // error + resource function get foo/bar/[string|int... path7]() {} + + // error + resource function get bar/[Id id]() {} +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/Ballerina.toml new file mode 100644 index 0000000000..9673ffc58f --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_38" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/header_param.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/header_param.bal new file mode 100644 index 0000000000..0385deb0df --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/header_param.bal @@ -0,0 +1,121 @@ +// Copyright (c) 2023, 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; + +type Value "value1"|"value2"; + +type ValueNilable ("value1"|"value2"|"value3")?; + +enum EnumValue { + VALUE1, + VALUE2, + VALUE3 +} + +type EnumCombined EnumValue|"VALUE4"|"VALUE5"; + +type HeaderRecord record {| + "value1"|"value2" header1; + EnumValue header2; + (1|2|3)[] header3; + (EnumValue|Value)[] header4; +|}; + +type UnionType EnumValue|Value; + +service /header/positive on listenerEP { + + resource function get case1(@http:Header "value1"|"value2" header) {} + + resource function get case2(@http:Header (1.234d|12.34d|123.4d)? header) {} + + resource function get case3(@http:Header Value header) {} + + resource function get case4(@http:Header Value? header) {} + + resource function get case5(@http:Header ValueNilable header) {} + + resource function get case6(@http:Header EnumValue header) {} + + resource function get case7(@http:Header EnumValue? header) {} + + resource function get case8(@http:Header EnumCombined header) {} + + resource function get case9(@http:Header EnumValue|"VALUE4"|"VALUE5"? header) {} + + resource function get case10(@http:Header EnumValue|Value? header) {} + + resource function get case11(@http:Header (1|2|3)[] header) {} + + resource function get case12(@http:Header Value[]? header) {} + + resource function get case13(@http:Header EnumValue[] header) {} + + resource function get case14(@http:Header (EnumValue|"VALUE4")[]? header) {} + + resource function get case15(@http:Header UnionType[] header) {} + + resource function get case16(@http:Header (EnumValue|Value)[]? header) {} + + resource function get case17(@http:Header HeaderRecord? header) {} +} + +type MixedValue "value2"|4.56|true; + +type MixedValueNilable MixedValue?; + +type HeaderInvalidRecord record {| + "value1"|"value2"|4 header1; + 1.2|2.4|3? header2; + MixedValue header3; + MixedValue? header4; + MixedValueNilable header5; + EnumValue|4 header6; + EnumValue|true? header7; + EnumValue|Value? header8; + (1|2|3|3.2)[] header9; + MixedValue[]? header10; + UnionType[] header11; + (EnumValue|true)[]? header12; + (EnumValue|Value)[]? header13; +|}; + +service /header/negative on listenerEP { + resource function get case1(@http:Header "value1"|"value2"|4 header) {} + + resource function get case2(@http:Header 1.2|2.4|3? header) {} + + resource function get case3(@http:Header MixedValue header) {} + + resource function get case4(@http:Header MixedValue? header) {} + + resource function get case5(@http:Header MixedValueNilable header) {} + + resource function get case6(@http:Header EnumValue|4 header) {} + + resource function get case7(@http:Header EnumValue|true? header) {} + + resource function get case11(@http:Header (1|2|3|3.2)[] header) {} + + resource function get case12(@http:Header MixedValue[]? header) {} + + resource function get case15(@http:Header (EnumValue|true)[]? header) {} + + resource function get case17(@http:Header HeaderRecord|record {|string header;|} header) {} + + resource function get case18(@http:Header HeaderInvalidRecord header) {} +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/path_param.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/path_param.bal new file mode 100644 index 0000000000..9692a273a0 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/path_param.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2023, 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. + +service /path/positive on listenerEP { + + resource function get case1/["value1"|"value2" path]() {} + + resource function get case2/[Value path]() {} + + resource function get case3/[EnumValue path]() {} + + resource function get case4/[1|2... paths]() {} + + resource function get case5/[Value... paths]() {} + + resource function get case6/[EnumValue... paths]() {} + + resource function get case7/[EnumValue|string path]() {} + + resource function get case8/[EnumValue|"value3" path]() {} + + resource function get case9/[UnionType path]() {} + + resource function get case10/[(Value|EnumValue)... paths]() {} +} + +service /path/negative on listenerEP { + + resource function get case1/["value1"|4|3.5d path]() {} + + resource function get case2/[MixedValue path]() {} + + resource function get case3/[MixedValue... path]() {} +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/query_param.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/query_param.bal new file mode 100644 index 0000000000..9eff0fcb9f --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_38/query_param.bal @@ -0,0 +1,99 @@ +// Copyright (c) 2023, 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; + +type QueryRecord record {| + EnumValue enumValue; + "value1"|"value2" value; +|}; + +type QueryRecordCombined QueryRecord|map; + +listener http:Listener listenerEP = new (9090); + +service /query/positive on listenerEP { + + resource function get case1("value1"|"value2" query) {} + + resource function get case2((1.2|2.4|3.6)? query) {} + + resource function get case3(Value query) {} + + resource function get case4(Value? query = "value2") {} + + resource function get case5(ValueNilable query) {} + + resource function get case6(EnumValue query) {} + + resource function get case7(EnumValue? query = VALUE2) {} + + resource function get case8(EnumCombined query) {} + + resource function get case9((EnumValue|"VALUE4"|"VALUE5")? query) {} + + resource function get case10(EnumValue|Value? query) {} + + resource function get case11((1|2|3)[] query) {} + + resource function get case12(Value[]? query) {} + + resource function get case13(EnumValue[] query) {} + + resource function get case14(UnionType[] query) {} + + resource function get case15((EnumValue|"VALUE4")[]? query) {} + + resource function get case16((EnumValue|Value)[]? query) {} + + resource function get case17(QueryRecord[]? query) {} + + resource function get case18(QueryRecord|map query) {} + + resource function get case19(QueryRecordCombined? query) {} + + resource function get case20((QueryRecord|map)[] query) {} + +} + +type QueryRecordCombinedInvalid QueryRecord|map; + +service /query/negative on listenerEP { + + resource function get case1("value1"|"value2"|4 query) {} + + resource function get case2(1.2|2.4|3? query) {} + + resource function get case3(MixedValue query) {} + + resource function get case4(MixedValue? query = "value2") {} + + resource function get case5(MixedValueNilable query) {} + + resource function get case6(EnumValue|4 query) {} + + resource function get case7(EnumValue|true? query = VALUE2) {} + + resource function get case11((1|2|3|3.2)[] query) {} + + resource function get case12(MixedValue[]? query) {} + + resource function get case14((EnumValue|true)[]? query) {} + + resource function get case15(QueryRecordCombinedInvalid? query) {} + + resource function get case16((QueryRecord|map)[]? query) {} +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_39/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_39/Ballerina.toml new file mode 100644 index 0000000000..c8bd94ad8e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_39/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_39" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_39/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_39/service.bal new file mode 100644 index 0000000000..1adaae6d81 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_39/service.bal @@ -0,0 +1,41 @@ +import ballerina/http; + +service class MyRequestInterceptor { + *http:RequestInterceptor; + + resource function 'default [string... path](http:RequestContext ctx) + returns http:NextService|error? { + return ctx.next(); + } +} + +service class MyResponseInterceptor { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx) + returns http:NextService|error? { + return ctx.next(); + } +} + +service http:InterceptableService / on new http:Listener(9099) { + + public function createInterceptors() returns [MyRequestInterceptor, MyResponseInterceptor] { + return [new MyRequestInterceptor(), new MyResponseInterceptor()]; + } + + resource function get hello(http:Caller caller) returns error? { + check caller->respond("Hello, World!"); + } +} + +service http:InterceptableService / on new http:Listener(9100) { + + public function createInterceptors() returns MyRequestInterceptor { + return new MyRequestInterceptor(); + } + + resource function get hello(http:Caller caller) returns error? { + check caller->respond("Hello, World!"); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_4/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_4/Ballerina.toml new file mode 100644 index 0000000000..faaa934dcc --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_4/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_4" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_4/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_4/service.bal new file mode 100644 index 0000000000..bc63a5326e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_4/service.bal @@ -0,0 +1,391 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/mime; + +type Person record {| + readonly int id; +|}; + +type RequestBody record {| + string xyz; + mime:Entity file1; + http:Request req; +|}; + +public annotation Person Pp on parameter; + +service http:Service on new http:Listener(9090) { + + resource function post dbXmlNegative(@http:Payload @http:Header xml abc) returns string { + return "done"; // error + } + + resource function get dbStringNegative(@http:Payload string abc) returns string { + return "done"; // error + } + + resource function head dbStringNegative(@http:Payload string abc) returns string { + return "done"; // error + } + + resource function options dbStringNegative(@http:Payload string abc) returns string { + return "done"; // error + } + + // int + resource function post dbInt(@http:Payload int abc) returns string { + return "done"; + } + + resource function post dbIntArr(@http:Payload int[] abc) returns string { + return "done"; + } + + resource function post dbIntMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbIntTable(@http:Payload table> abc) returns string { + return "done"; + } + + // boolean + resource function post dbBool(@http:Payload boolean abc) returns string { + return "done"; + } + + resource function post dbBoolArr(@http:Payload boolean[] abc) returns string { + return "done"; + } + + resource function post dbBoolMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbBoolTable(@http:Payload table> abc) returns string { + return "done"; + } + + // float + resource function post dbFloat(@http:Payload float abc) returns string { + return "done"; + } + + resource function post dbFloatArr(@http:Payload float[] abc) returns string { + return "done"; + } + + resource function post dbFloatMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbFloatTable(@http:Payload table> abc) returns string { + return "done"; + } + + // decimal + resource function post dbDecimal(@http:Payload decimal abc) returns string { + return "done"; + } + + resource function post dbDecimalArr(@http:Payload decimal[] abc) returns string { + return "done"; + } + + resource function post dbDecimalMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbDecimalTable(@http:Payload table> abc) returns string { + return "done"; + } + + // byte[] + resource function post dbByteArr(@http:Payload byte[] abc) returns string { + return "done"; + } + + resource function post dbByteArrArr(@http:Payload byte[][] abc) returns string { + return "done"; + } + + resource function post dbByteArrMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbByteArrTable(@http:Payload table> abc) returns string { + return "done"; + } + + // string + resource function post dbString(@http:Payload string abc) returns string { + return "done"; + } + + resource function post dbStringArr(@http:Payload string[] abc) returns string { + return "done"; + } + + resource function post dbStringMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbStringTable(@http:Payload table> abc) returns string { + return "done"; + } + + // xml + resource function post dbXml(@http:Payload xml abc) returns string { + return "done"; + } + + resource function post dbXmlArr(@http:Payload xml[] abc) returns string { + return "done"; + } + + resource function post dbXmlMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbXmlTable(@http:Payload table> abc) returns string { + return "done"; + } + + // json + resource function post dbJson(@http:Payload json abc) returns string { + return "done"; + } + + resource function post dbJsonArr(@http:Payload json[] abc) returns string { + return "done"; + } + + resource function post dbJsonMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbJsonTable(@http:Payload table> abc) returns string { + return "done"; + } + + // record + resource function post dbRecord(@http:Payload Person abc) returns string { + return "done"; + } + + resource function post dbRecordArr(@http:Payload Person[] abc) returns string { + return "done"; + } + + resource function post dbRecordMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbRecordTable(@http:Payload table key(id) abc) returns string { + return "done"; + } + + // map + resource function post dbMapArr(@http:Payload map[] abc) returns string { + return "done"; + } + + resource function post dbMapMap(@http:Payload map> abc) returns string { + return "done"; + } + + // array + resource function post dbArrArr(@http:Payload Person[][] abc) returns string { + return "done"; + } + + resource function post dbArrayMap(@http:Payload map abc) returns string { + return "done"; + } + + resource function post dbRecorArrayMapMap(@http:Payload map> abc) returns string { + return "done"; + } + + // table + resource function post dbTableArr(@http:Payload table key(id)[] abc) returns string { + return "done"; + } + + resource function post dbTableMap(@http:Payload map key(id)> abc) returns string { + return "done"; + } + + // anydata + resource function post dbAnydata(@http:Payload anydata abc) returns string { + return "done"; + } + + //readonly + resource function post dbIntTableRO(@http:Payload table> abc) returns string { + return "done"; + } + + resource function post dbArrayMapRO(@http:Payload readonly & map abc) returns string { + return "done"; + } + + resource function post greeting1(int num, @http:Payload json abc, @Pp {id:0} string a) returns string { + return "done"; // error + } + + // unions + resource function post dbUnion(@http:Payload json|xml abc) returns string { + return "done"; + } + + resource function post dbReadonlyJsonUnion(@http:Payload readonly & byte[]|xml abc) returns string { + return "done"; + } + + resource function post dbReadonlyUnion(@http:Payload readonly & (json|xml) abc) returns string { + return "done"; + } + + resource function post dbStringNil(@http:Payload string? abc) returns string { + return "done"; + } + + resource function post dbUnionNegative(@http:Payload string|http:Caller abc) returns string { + return "done"; + } + + // builtin subtypes + resource function post dbXmlElement(@http:Payload xml:Element abc) returns string { + return "done"; + } + + resource function post dbXmlText(@http:Payload xml:Text abc) returns string { + return "done"; + } + + resource function post dbXmlComment(@http:Payload xml:Comment abc) returns string { + return "done"; + } + + resource function post dbXmlProcessingInstruction(@http:Payload xml:ProcessingInstruction abc) returns string { + return "done"; + } + + resource function post dbStrChar(@http:Payload string:Char abc) returns string { + return "done"; + } + + resource function post dbIntSigned32(@http:Payload int:Signed32 abc) returns string { + return "done"; + } + + resource function post dbIntSigned16(@http:Payload int:Signed16 abc) returns string { + return "done"; + } + + resource function post dbIntSigned8(@http:Payload int:Signed8 abc) returns string { + return "done"; + } + + resource function post dbIntUnsigned32(@http:Payload int:Unsigned32 abc) returns string { + return "done"; + } + + resource function post dbIntUnsigned16(@http:Payload int:Unsigned16 abc) returns string { + return "done"; + } + + resource function post dbIntUnsigned8(@http:Payload int:Unsigned8 abc) returns string { + return "done"; + } + + resource function post dbRecordWithObjectNegative(@http:Payload RequestBody abc) returns string { + return "done"; //error + } +} + +enum MenuType { + BREAK_FAST, + LUNCH, + DINNER +} + +type Item record {| + int _id; + string name; + string description; + decimal price; +|}; + +type Menu record {| + int _id; + MenuType 'type; + Item[] items; +|}; + +type Restaurant record {| + string name; + string city; + string description; + Menu[] menus; +|}; + +public type User readonly & record {| + int id; + int age; +|}; + +type RestaurantNew record {| + *Restaurant; + [int, string, decimal, float, User] address; +|}; + +class Object {} + +service on new http:Listener(9091) { + + resource function post menuType(@http:Payload MenuType menuType) + returns http:Accepted { + return http:ACCEPTED; + } + + resource function post menu(@http:Payload Menu menu) + returns http:Created { + return http:CREATED; + } + + resource function post restaurants(@http:Payload Restaurant restaurant) + returns http:Created { + return http:CREATED; + } + + resource function post restaurantsNew(@http:Payload RestaurantNew restaurant) returns RestaurantNew { + return restaurant; + } + + resource function post address(@http:Payload [int, string, User] address) returns http:Created { + return http:CREATED; + } + + // error + resource function post obj(@http:Payload [int, string, Object] address) returns http:Created { + return http:CREATED; + } +} + diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_40/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_40/Ballerina.toml new file mode 100644 index 0000000000..b7b8157477 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_40/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_40" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_40/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_40/service.bal new file mode 100644 index 0000000000..6cfcbdb41c --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_40/service.bal @@ -0,0 +1,74 @@ +import ballerina/http; + +type ContractServiceWithoutServiceConfig service object { + *http:ServiceContract; +}; + +@http:ServiceConfig { + basePath: "/api" +} +type ContractService service object { + *http:ServiceContract; +}; + +@http:ServiceConfig { +} +service ContractService /api on new http:Listener(9090) { +}; + +@http:ServiceConfig { + serviceType: ContractService +} +service ContractService on new http:Listener(9090) { +}; + +@http:ServiceConfig { + basePath: "/api" +} +type NonContractService service object { + *http:Service; +}; + +@http:ServiceConfig { + serviceType: ContractServiceWithoutServiceConfig +} +service ContractService on new http:Listener(9090) { +}; + +@http:ServiceConfig { + serviceType: ContractServiceWithoutServiceConfig +} +service NonContractService on new http:Listener(9090) { +}; + + +@http:ServiceConfig { + basePath: "/api" +} +type ContractServiceWithResource service object { + *http:ServiceContract; + + resource function get greeting(@http:Header string? header) returns string; +}; + +service ContractServiceWithResource on new http:Listener(9090) { + resource function get greeting(string? header) returns string { + return "Hello, World!"; + } +}; + +service ContractServiceWithResource on new http:Listener(9090) { + resource function get greeting(string? header) returns string { + return "Hello, World!"; + } + + resource function get newGreeting() {} +}; + +service ContractServiceWithResource on new http:Listener(9090) { + + @http:ResourceConfig {} + resource function get greeting(@http:Header string? header) returns string { + return "Hello, World!"; + } +}; diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_41/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_41/Ballerina.toml new file mode 100644 index 0000000000..78b28feb26 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_41/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_41" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_41/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_41/service.bal new file mode 100644 index 0000000000..ce73b5ac41 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_41/service.bal @@ -0,0 +1,104 @@ +import ballerina/http; +import ballerina/log; + +@http:ServiceConfig { + mediaTypeSubtypePrefix: "vnd.socialMedia", + basePath: "/socialMedia" +} +public type Service service object { + *http:ServiceContract; + *http:InterceptableService; + + public function createInterceptors() returns ErrorInterceptor; + + resource function get users() returns @http:Cache {maxAge: 10} User[]|error; + + resource function get users/[int id]() returns User|UserNotFound|error; + + resource function post users(NewUser newUser) returns http:Created|error; +}; + +public isolated service class ErrorInterceptor { + *http:ResponseErrorInterceptor; + + isolated remote function interceptResponseError(error err, http:Response res, http:RequestContext ctx) returns DefaultResponse { + log:printError("error occurred", err); + return { + body: err.message(), + status: new (res.statusCode) + }; + } +} + +public type User record { + int id; + string name; + string email; +}; + +public type NewUser record { + string name; + string email; +}; + + +public type UserNotFound record {| + *http:NotFound; + ErrorMessage body; +|}; + +public type DefaultResponse record {| + *http:DefaultStatusCodeResponse; + ErrorMessage body; +|}; + +public type ErrorMessage string; + +service Service on new http:Listener(9090) { + + resource function get users() returns User[]|error { + return [{id: 1, name: "Alice", email: "alice@gmail.com"}, {id: 2, name: "Bob", email: "bob@gmail.com"}]; + } + + resource function get users/[int id]() returns User|UserNotFound|error { + return {id: 1, name: "Alice", email: "alice@gmail.com"}; + } + + resource function post users(NewUser newUser) returns http:Created|error { + return { + body: { + message: "User created successfully" + } + }; + } + + public function createInterceptors() returns ErrorInterceptor { + return new (); + } +} + +@http:ServiceConfig { + serviceType: Service +} +service Service on new http:Listener(9091) { + + resource function get users() returns User[]|error { + return [{id: 1, name: "Alice", email: "alice@gmail.com"}, {id: 2, name: "Bob", email: "bob@gmail.com"}]; + } + + resource function get users/[int id]() returns User|UserNotFound|error { + return {id: 1, name: "Alice", email: "alice@gmail.com"}; + } + + resource function post users(NewUser newUser) returns http:Created|error { + return { + body: { + message: "User created successfully" + } + }; + } + + public function createInterceptors() returns ErrorInterceptor { + return new (); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_5/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_5/Ballerina.toml new file mode 100644 index 0000000000..84412e1aa7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_5/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_5" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_5/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_5/service.bal new file mode 100644 index 0000000000..fc8e3f6fc7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_5/service.bal @@ -0,0 +1,153 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +type RateLimitHeaders record {| + string x\-rate\-limit\-id; + int? x\-rate\-limit\-remaining; + string[]? x\-rate\-limit\-types; +|}; + +type TestRecord record {| + string[]|string xRate; +|}; + +type NestedRecord record {| + RateLimitHeaders xRate; +|}; + +enum HeaderValue { + VALUE1 = "value1", + VALUE2 = "value2", + VALUE3 = "value3" +}; + +service http:Service on new http:Listener(9090) { + + resource function get headerString(@http:Header {name: "x-type"} string abc) returns string { + return "done"; + } + + resource function get headerStringArr(@http:Header {name: "x-type"} string[] abc) returns string { + return "done"; + } + + resource function get headerStringNil(@http:Header {name: "x-type"} string? abc) returns string { + return "done"; + } + + resource function get headerStringArrNil(@http:Header {name: "x-type"} string[]? abc) returns string { + return "done"; + } + + resource function get headerRecord(@http:Header {name: "x-type"} RateLimitHeaders abc) returns string { + return "done"; + } + + resource function get headerRecordReadonly(@http:Header readonly & RateLimitHeaders abc) returns string { + return "done"; + } + + resource function get headerRecordWithInvalidFieldUnion(@http:Header TestRecord abc) returns string { + return "done"; //error + } + + resource function get headerRecordNil(@http:Header {name: "x-type"} RateLimitHeaders? abc) returns string { + return "done"; + } + + resource function get headerRecordArr(@http:Header {name: "x-type"} RateLimitHeaders[] abc) returns string { + return "done"; //error + } + + resource function get headerRecordArrNil(@http:Header RateLimitHeaders[]? abc) returns string { + return "done"; //error + } + + resource function get headerRecordUnionStr(@http:Header RateLimitHeaders|string abc) returns string { + return "done"; //error + } + + resource function get headerInlineRecord(@http:Header record {|string hello;|} abc) returns string { + return "done"; + } + + resource function get headerInlineRestAndStringRecord(@http:Header record {|string hello; string...;|} abc) returns + string { + return "done"; //error + } + + resource function get headerInlineRestRecord(@http:Header record {|string...;|} abc) returns string { + return "done"; //error + } + + resource function get headerInt(@http:Header int foo, @http:Header int[] bar, @http:Header int? baz, + @http:Header int[]? daz, @http:Header readonly & int dawz) returns string { + return "done"; + } + + resource function get headerDecimal(@http:Header decimal foo, @http:Header decimal[] bar, @http:Header decimal? baz, + @http:Header decimal[]? daz, @http:Header readonly & decimal? dawz) returns string { + return "done"; + } + + resource function get headerFloat(@http:Header float foo, @http:Header float[] bar, @http:Header float? baz, + @http:Header float[]? daz, @http:Header readonly & float dawz) returns string { + return "done"; + } + + resource function get headerBool(@http:Header boolean foo, @http:Header boolean[] bar, @http:Header boolean? baz, + @http:Header boolean[]? daz, @http:Header readonly & boolean dawz) returns string { + return "done"; + } + + resource function get headerErr1(@http:Header {name: "x-type"} json abc) returns string { + return "done"; //error + } + + resource function post headerErr2(@http:Header @http:Payload string abc) returns string { + return "done"; //error + } + + resource function get headerErr3(@http:Header {name: "x-type"} http:Request abc) returns string { + return "done"; //error + } + + resource function get headerErr4(@http:Header {name: "x-type"} string|json abc) returns string { + return "done"; //error + } + + resource function get headerErr5(@http:Header {name: "x-type"} json? abc) returns string { + return "done"; //error + } + + resource function get headerErr6(@http:Header {name: "x-type"} string|json|xml abc) returns string { + return "done"; //error + } + + resource function get headerErr7(@http:Header {name: "x-type"} int[] abc) returns string { + return "done"; //error + } + + resource function get headerRecordWithRecordField(@http:Header NestedRecord abc) returns string { + return "done"; //error + } + + resource function 'default [string... path](@http:Header HeaderValue? test) returns string { + return test.toString(); + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_6/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_6/Ballerina.toml new file mode 100644 index 0000000000..2bae5bb4b1 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_6/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_6" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_6/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_6/service.bal new file mode 100644 index 0000000000..c99d0bba7e --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_6/service.bal @@ -0,0 +1,40 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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 as a; + +type Caller record {| + int id; +|}; + +service a:Service on new a:Listener(9090) { + + resource function get callerInf(@a:CallerInfo a:Caller abc) returns string { + return "done"; + } + + resource function get callerErr1(@a:CallerInfo string abc) returns string { + return "done"; //error + } + + resource function post callerErr2(@a:CallerInfo @a:Payload a:Caller abc) returns string { + return "done"; //error + } + + resource function get callerErr3(@a:CallerInfo Caller abc) returns string { + return "done"; //error + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_7/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_7/Ballerina.toml new file mode 100644 index 0000000000..48dc1cac29 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_7/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_7" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_7/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_7/service.bal new file mode 100644 index 0000000000..fcdbff1e02 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_7/service.bal @@ -0,0 +1,46 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/mime; + +type Caller record {| + int id; + any val; +|}; + +service http:Service on new http:Listener(9090) { + + resource function get callerInfo(http:Caller abc, http:Request req, http:Headers head) returns string { + return "done"; + } + + resource function get callerErr1(http:Response abc) returns string { + return "done"; + } + + resource function get callerErr2(mime:Entity abc) returns string { + return "done"; + } + + resource function get callerErr3(int a, mime:Entity abc) returns string { + return "done"; + } + + resource function get callerErr4(int a, Caller abc) returns string { + return "done"; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_8/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_8/Ballerina.toml new file mode 100644 index 0000000000..eb56906dab --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_8/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_8" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_8/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_8/service.bal new file mode 100644 index 0000000000..fdd85588ee --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_8/service.bal @@ -0,0 +1,137 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/mime; + +type Caller record {| + int id; +|}; + +// This is user-defined type +public type Count int; +public type TypeJson json; +public type Name string; +public type FirstName Name; +public type FullName FirstName; + +service http:Service on new http:Listener(9090) { + + resource function get callerInfo1(string a, int[] b, float? c, decimal[]? d) returns string { + return "done"; + } + + resource function get callerInfo2(string a, int[] b) returns string { + return "done"; + } + + resource function get callerInfo3(string a, int b, float c, decimal d, boolean e) returns string { + return "done"; + } + + resource function get callerInfo4(string? a, int? b, float? c, decimal? d, boolean? e) returns string { + return "done"; + } + + resource function get callerInfo5(string[] a, int[] b, float[] c, decimal[] d, boolean[] e) returns string { + return "done"; + } + + resource function get callerInfo6(string[]? a, int[]? b, float[]? c, decimal[]? d, boolean[]? e) returns string { + return "done"; + } + + resource function get callerInfo7(map aa, string? ab, boolean[] ac) returns string { + return "done"; + } + + resource function get callerInfo8(map[] ba, int bb, decimal[]? bc) returns string { + return "done"; + } + + resource function get callerInfo9(float[] cb, int[]? cc, map? ca) returns string { + return "done"; + } + + resource function get callerInfo10(string[] db, boolean dc, map[]? da) returns string { + return "done"; + } + + resource function get callerErr1(mime:Entity abc) returns string { + return "done"; + } + + resource function get callerErr2(int|string a) returns string { + return "done"; + } + + resource function get callerErr3(int|string[]|float b) returns string { + return "done"; + } + + resource function get callerErr4(int[]|json c) returns string { + return "done"; + } + + resource function get callerErr5(xml? d, string e) returns string { + return "done"; + } + + resource function get callerErr6(int[]? b, json a, json[] aa) returns string { + return "done"; + } + + resource function get callerErr7(string? b, map a) returns string { + return "done"; + } + + resource function get callerErr8(map[] b, int[] c) returns string { + return "done"; + } + + resource function get callerErr9(map? c, map d) returns string { + return "done"; + } + + resource function get callerErr10(json[] d, xml e) returns string { + return "done"; + } + + resource function get pets(Count count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get petsUnion(Count? count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get petsArr(Count[] count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get petsMap(map count) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } + + resource function get nestedTypeRef(FullName names) returns http:Ok { + http:Ok ok = {body: ()}; + return ok; + } +} diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_9/Ballerina.toml b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_9/Ballerina.toml new file mode 100644 index 0000000000..9172401313 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_9/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "http_test" +name = "sample_9" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_9/service.bal b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_9/service.bal new file mode 100644 index 0000000000..0b85a00665 --- /dev/null +++ b/compiler-plugin-tests/bin/test/ballerina_sources/sample_package_9/service.bal @@ -0,0 +1,56 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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/file; + +listener http:Listener ep1 = new(9091); +listener http:Listener ep2 = new(9092, { httpVersion: "2.0" }); +listener http:Listener ep3 = new(9095); +listener file:Listener inFolder = new ({ + path: "/home/ballerina/fs-server-connector/observed-dir", + recursive: false +}); + +service http:Service on ep1 { + resource function get greeting(http:Caller caller) { + } +} + +service http:Service on ep2, ep3 { + resource function get greeting(http:Caller caller) { + } +} + +service http:Service on new http:Listener(9093) { + resource function get greeting() { + } +} + +service on new http:Listener(9094, { host: "0.0.0.0"}), new http:Listener(9096) { + resource function get greeting() { + } +} + +service http:Service on ep2 { // error + resource function get greeting(http:Response res) { + } +} + +service http:Service on ep3 { // skip http validation + remote function greeting(http:Cookie abc) { + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result1.bal b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result1.bal new file mode 100644 index 0000000000..99ba9e4aa3 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result1.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /greeting on new http:Listener(0) { + resource function get hi(@http:Header string header) returns string { + return "hi"; + } + + resource function post hi(@http:Payload string payload) returns string { + return "hi"; + } + + resource function post hello() returns string { + return "hello"; + } + + resource function post hey(@http:Header string header) returns string { + return "hey"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result2.bal b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result2.bal new file mode 100644 index 0000000000..847284abc9 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result2.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /greeting on new http:Listener(0) { + resource function get hi() returns string { + return "hi"; + } + + resource function post hi(@http:Payload string payload, @http:Header string header) returns string { + return "hi"; + } + + resource function post hello() returns string { + return "hello"; + } + + resource function post hey(@http:Header string header) returns string { + return "hey"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result3.bal b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result3.bal new file mode 100644 index 0000000000..f726c33042 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result3.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /greeting on new http:Listener(0) { + resource function get hi() returns string { + return "hi"; + } + + resource function post hi(@http:Payload string payload) returns string { + return "hi"; + } + + resource function post hello(@http:Payload json payload) returns string { + return "hello"; + } + + resource function post hey(@http:Header string header) returns string { + return "hey"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result4.bal b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result4.bal new file mode 100644 index 0000000000..c7faf29b31 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_annotated_param/result4.bal @@ -0,0 +1,35 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service /greeting on new http:Listener(0) { + resource function get hi() returns string { + return "hi"; + } + + resource function post hi(@http:Payload string payload) returns string { + return "hi"; + } + + resource function post hello() returns string { + return "hello"; + } + + resource function post hey(@http:Header string header, @http:Payload json payload) returns string { + return "hey"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_annotations_to_return_type/result1.bal b/compiler-plugin-tests/bin/test/codeaction/add_annotations_to_return_type/result1.bal new file mode 100644 index 0000000000..1af7784cfa --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_annotations_to_return_type/result1.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + + resource function get . (@http:Header json length) { + + } + + resource function get path1(http:Caller caller) returns @http:Cache string { + return ""; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_annotations_to_return_type/result2.bal b/compiler-plugin-tests/bin/test/codeaction/add_annotations_to_return_type/result2.bal new file mode 100644 index 0000000000..cb7f4746ae --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_annotations_to_return_type/result2.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + + resource function get . (@http:Header json length) { + + } + + resource function get path1(http:Caller caller) returns @http:Payload{mediaType: ""} string { + return ""; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result1.bal b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result1.bal new file mode 100644 index 0000000000..401ae675e7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result1.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service class RequestInterceptor { + *http:RequestInterceptor; + + resource function 'default [string... path](http:RequestContext ctx) returns http:NextService|error? { + // add your logic here + return ctx.next(); + } +} + +service class RequestErrorInterceptor { + *http:RequestErrorInterceptor; +} + +service class ResponseInterceptor { + *http:ResponseInterceptor; +} + +service class ResponseErrorInterceptor { + *http:ResponseErrorInterceptor; +} + +service /greeting on new http:Listener(9090) { + resource function get hi() returns string { + return "hi"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result2.bal b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result2.bal new file mode 100644 index 0000000000..dae6d83124 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result2.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service class RequestInterceptor { + *http:RequestInterceptor; +} + +service class RequestErrorInterceptor { + *http:RequestErrorInterceptor; + + resource function 'default [string... path](error err, http:RequestContext ctx) returns http:NextService|error? { + // add your logic here + return ctx.next(); + } +} + +service class ResponseInterceptor { + *http:ResponseInterceptor; +} + +service class ResponseErrorInterceptor { + *http:ResponseErrorInterceptor; +} + +service /greeting on new http:Listener(9090) { + resource function get hi() returns string { + return "hi"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result3.bal b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result3.bal new file mode 100644 index 0000000000..7b98e8d0c5 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result3.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service class RequestInterceptor { + *http:RequestInterceptor; +} + +service class RequestErrorInterceptor { + *http:RequestErrorInterceptor; +} + +service class ResponseInterceptor { + *http:ResponseInterceptor; + + remote function interceptResponse(http:RequestContext ctx) returns http:NextService|error? { + // add your logic here + return ctx.next(); + } +} + +service class ResponseErrorInterceptor { + *http:ResponseErrorInterceptor; +} + +service /greeting on new http:Listener(9090) { + resource function get hi() returns string { + return "hi"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result4.bal b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result4.bal new file mode 100644 index 0000000000..34ce2087f7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/add_interceptor_method/result4.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +service class RequestInterceptor { + *http:RequestInterceptor; +} + +service class RequestErrorInterceptor { + *http:RequestErrorInterceptor; +} + +service class ResponseInterceptor { + *http:ResponseInterceptor; +} + +service class ResponseErrorInterceptor { + *http:ResponseErrorInterceptor; + + remote function interceptResponseError(error err, http:RequestContext ctx) returns http:NextService|error? { + // add your logic here + return ctx.next(); + } +} + +service /greeting on new http:Listener(9090) { + resource function get hi() returns string { + return "hi"; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/change_header_param_type/result1.bal b/compiler-plugin-tests/bin/test/codeaction/change_header_param_type/result1.bal new file mode 100644 index 0000000000..28fd1775b6 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/change_header_param_type/result1.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + + resource function get . (@http:Header string length) { + + } + + resource function get path1(http:Caller caller) returns string { + return ""; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/change_header_param_type/result2.bal b/compiler-plugin-tests/bin/test/codeaction/change_header_param_type/result2.bal new file mode 100644 index 0000000000..cd049163a7 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/change_header_param_type/result2.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + + resource function get . (@http:Header string[] length) { + + } + + resource function get path1(http:Caller caller) returns string { + return ""; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/change_return_type_with_caller/result1.bal b/compiler-plugin-tests/bin/test/codeaction/change_return_type_with_caller/result1.bal new file mode 100644 index 0000000000..67897cacb6 --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/change_return_type_with_caller/result1.bal @@ -0,0 +1,28 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. 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; + +service / on new http:Listener(9999) { + + resource function get . (@http:Header json length) { + + } + + resource function get path1(http:Caller caller) returns error? { + return ""; + } +} diff --git a/compiler-plugin-tests/bin/test/codeaction/implement_service_contract_resources/result1.bal b/compiler-plugin-tests/bin/test/codeaction/implement_service_contract_resources/result1.bal new file mode 100644 index 0000000000..e132b5262f --- /dev/null +++ b/compiler-plugin-tests/bin/test/codeaction/implement_service_contract_resources/result1.bal @@ -0,0 +1,210 @@ +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org). +// +// 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. + +// This is added to test some auto generated code segments. +// Please ignore the indentation. + +import ballerina/http; + +import ballerina/http; +import ballerina/log; + +# The service type that handles the social media API +@http:ServiceConfig { + mediaTypeSubtypePrefix: "vnd.socialMedia", + basePath: "/socialMedia" +} +public type Service service object { + *http:ServiceContract; + *http:InterceptableService; + + public function createInterceptors() returns ErrorInterceptor; + + # Get all users + # + # + return - List of users(`User[]`) or an error + @http:ResourceConfig { + name: "users" + } + resource function get users() returns @http:Cache {maxAge: 10} User[]|error; + + # Get a user by ID + # + # + id - User ID + # + return - `User` or NotFound response(`UserNotFound`) when the user is not found or an error + @http:ResourceConfig { + name: "user", + linkedTo: [ + {name: "user", method: http:DELETE, relation: "delete-user"}, + {name: "posts", method: http:POST, relation: "create-posts"}, + {name: "posts", method: http:GET, relation: "get-posts"} + ] + } + resource function get users/[int id]() returns User|UserNotFound|error; + + # Create a new user + # + # + newUser - New user details(`NewUser`) as payload + # + return - Created(`http:Created`) response or an error + @http:ResourceConfig { + name: "users", + linkedTo: [ + {name: "user", method: http:GET, relation: "get-user"}, + {name: "user", method: http:DELETE, relation: "delete-user"}, + {name: "posts", method: http:POST, relation: "create-posts"}, + {name: "posts", method: http:GET, relation: "get-posts"} + ], + consumes: ["application/vnd.socialMedia+json"] + } + resource function post users(NewUser newUser) returns http:Created|error; + + # Delete a user by ID + # + # + id - User ID + # + return - NoContent response(`http:NoContent`) or an error + @http:ResourceConfig { + name: "user" + } + resource function delete users/[int id]() returns http:NoContent|error; + + # Get all posts of a user + # + # + id - User ID + # + return - List of posts with metadata(`PostWithMeta[]`) or NotFound response(`UserNotFound`) when the user is not found or an error + @http:ResourceConfig { + name: "posts" + } + resource function get users/[int id]/posts() returns @http:Cache {maxAge: 25} PostWithMeta[]|UserNotFound|error; + + # Create a new post for a user + # + # + id - User ID + # + newPost - New post details(`NewPost`) as payload + # + return - Created(`http:Created`) response or an error + @http:ResourceConfig { + name: "posts", + linkedTo: [ + {name: "posts", method: http:POST, relation: "create-posts"} + ], + consumes: ["application/vnd.socialMedia+json"] + } + resource function post users/[int id]/posts(@http:Payload NewPost newPost) returns http:Created|UserNotFound|PostForbidden|error; +}; + +public isolated service class ErrorInterceptor { + *http:ResponseErrorInterceptor; + + isolated remote function interceptResponseError(error err, http:Response res, http:RequestContext ctx) returns DefaultResponse { + log:printError("error occurred", err); + return { + body: err.message(), + status: new (res.statusCode) + }; + } +} + +# Represents a user in the system +# +# + id - user ID +# + name - user name +# + email - user email +public type User record { + int id; + string name; + string email; +}; + +# Represents a new user +# +# + name - user name +# + email - user email +public type NewUser record { + string name; + string email; +}; + +# Represents a user not found error +# +# + body - error message +public type UserNotFound record {| + *http:NotFound; + ErrorMessage body; +|}; + +# Represents a new post +# +# + content - post content +public type NewPost record { + string content; +}; + +# Represents a post with metadata +# +# + id - post ID +# + content - post content +# + createdAt - post creation time +public type PostWithMeta record { + int id; + string content; + string createdAt; +}; + +# Represents a post forbidden error +# +# + body - error message +public type PostForbidden record {| + *http:Forbidden; + ErrorMessage body; +|}; + +# Represents a default response +# +# + body - response body +public type DefaultResponse record {| + *http:DefaultStatusCodeResponse; + ErrorMessage body; +|}; + +# Represents a error message +public type ErrorMessage string; + +service Service on new http:Listener(9090) { + + + resource function get users () returns User[]|error { + + } + + resource function get users/[int id] () returns User|UserNotFound|error { + + } + + resource function post users (NewUser newUser) returns http:Created|error { + + } + + resource function delete users/[int id] () returns http:NoContent|error { + + } + + resource function get users/[int id]/posts () returns PostWithMeta[]|UserNotFound|error { + + } + + resource function post users/[int id]/posts (NewPost newPost) returns http:Created|UserNotFound|PostForbidden|error { + + } +} diff --git a/compiler-plugin-tests/bin/test/completion/service_declaration/expected_completions1.json b/compiler-plugin-tests/bin/test/completion/service_declaration/expected_completions1.json new file mode 100644 index 0000000000..0242b10c11 --- /dev/null +++ b/compiler-plugin-tests/bin/test/completion/service_declaration/expected_completions1.json @@ -0,0 +1,34 @@ +{ + "items": [ + { + "label": "resource function get path()", + "insertText": "resource function get ${1:path}(${2}) ${3}{\n\t${4}\n}", + "priority": "HIGH" + }, + { + "label": "resource function post path()", + "insertText": "resource function post ${1:path}(${2}) ${3}{\n\t${4}\n}", + "priority": "HIGH" + }, + { + "label": "resource function put path()", + "insertText": "resource function put ${1:path}(${2}) ${3}{\n\t${4}\n}", + "priority": "HIGH" + }, + { + "label": "resource function delete path()", + "insertText": "resource function delete ${1:path}(${2}) ${3}{\n\t${4}\n}", + "priority": "HIGH" + }, + { + "label": "resource function head path()", + "insertText": "resource function head ${1:path}(${2}) ${3}{\n\t${4}\n}", + "priority": "HIGH" + }, + { + "label": "resource function options path()", + "insertText": "resource function options ${1:path}(${2}) ${3}{\n\t${4}\n}", + "priority": "HIGH" + } + ] +} diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/Ballerina.toml b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/Ballerina.toml new file mode 100644 index 0000000000..a2262d50af --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "ballerina" +name = "rule1" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service.bal b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service.bal new file mode 100644 index 0000000000..2490eefb23 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). +// +// 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; + +service on new http:Listener(8080) { + resource function default .() returns string? { + return; + } + + resource function default greet() returns string? { + return; + } +}; diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service_class.bal b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service_class.bal new file mode 100644 index 0000000000..9020df9eef --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service_class.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). +// +// 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; + +service class GreetingService { + *http:Service; + + resource function default .() returns string { + return ""; + } + + resource function default greet() returns string { + return ""; + } +}; diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service_object.bal b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service_object.bal new file mode 100644 index 0000000000..9ede2843d3 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule1/service_object.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). +// +// 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; + +type ServiceContract service object { + *http:Service; + resource function default .() returns string; + resource function default greet() returns string; +}; + +type MyContract service object { + *http:ServiceContract; + resource function default .() returns string; + resource function default greet() returns string; +}; diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/Ballerina.toml b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/Ballerina.toml new file mode 100644 index 0000000000..adf0cc8b06 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "ballerina" +name = "rule2" +version = "0.1.0" diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service.bal b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service.bal new file mode 100644 index 0000000000..8e095f9d41 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service.bal @@ -0,0 +1,34 @@ +// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). +// +// 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; + +@http:ServiceConfig { + cors: { + allowOrigins: ["*"] + } +} +service on new http:Listener(8080) { + + @http:ResourceConfig { + cors: { + allowOrigins: ["*"] + } + } + resource function get greet() returns string? { + return; + } +}; diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service_class.bal b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service_class.bal new file mode 100644 index 0000000000..c8779ff6a1 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service_class.bal @@ -0,0 +1,30 @@ +// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). +// +// 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; + +service class GreetingService { + *http:Service; + + @http:ResourceConfig { + cors: { + allowOrigins: ["*"] + } + } + resource function get .() returns string? { + return; + } +}; diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service_object.bal b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service_object.bal new file mode 100644 index 0000000000..a7c1f6ccd8 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/ballerina_packages/rule2/service_object.bal @@ -0,0 +1,49 @@ +// Copyright (c) 2024 WSO2 LLC. (https://www.wso2.com). +// +// 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; + +@http:ServiceConfig { + cors: { + allowOrigins: ["*"] + } +} +type ServiceContract service object { + *http:Service; + + @http:ResourceConfig { + cors: { + allowOrigins: ["*"] + } + } + resource function get greet() returns string; +}; + +@http:ServiceConfig { + cors: { + allowOrigins: ["*"] + } +} +type MyContract service object { + *http:ServiceContract; + + @http:ResourceConfig { + cors: { + allowOrigins: ["*"] + } + } + resource function get greet() returns string; +}; diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/expected_output/rule1.json b/compiler-plugin-tests/bin/test/static_code_analyzer/expected_output/rule1.json new file mode 100644 index 0000000000..0e9afd7895 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/expected_output/rule1.json @@ -0,0 +1,162 @@ +[ + { + "location": { + "filePath": "service.bal", + "startLine": 19, + "endLine": 19, + "startColumn": 22, + "endColumn": 29, + "startOffset": 728, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service.bal" + }, + { + "location": { + "filePath": "service.bal", + "startLine": 23, + "endLine": 23, + "startColumn": 22, + "endColumn": 29, + "startOffset": 803, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service.bal" + }, + { + "location": { + "filePath": "service_class.bal", + "startLine": 21, + "endLine": 21, + "startColumn": 22, + "endColumn": 29, + "startOffset": 743, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service_class.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service_class.bal" + }, + { + "location": { + "filePath": "service_class.bal", + "startLine": 25, + "endLine": 25, + "startColumn": 22, + "endColumn": 29, + "startOffset": 820, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service_class.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service_class.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 20, + "endLine": 20, + "startColumn": 22, + "endColumn": 29, + "startOffset": 748, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service_object.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 21, + "endLine": 21, + "startColumn": 22, + "endColumn": 29, + "startOffset": 798, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service_object.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 26, + "endLine": 26, + "startColumn": 22, + "endColumn": 29, + "startOffset": 916, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service_object.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 27, + "endLine": 27, + "startColumn": 22, + "endColumn": 29, + "startOffset": 966, + "length": 7 + }, + "rule": { + "id": "ballerina/http:1", + "numericId": 1, + "description": "Avoid allowing default resource accessor", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule1/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule1/service_object.bal" + } +] diff --git a/compiler-plugin-tests/bin/test/static_code_analyzer/expected_output/rule2.json b/compiler-plugin-tests/bin/test/static_code_analyzer/expected_output/rule2.json new file mode 100644 index 0000000000..00608dc943 --- /dev/null +++ b/compiler-plugin-tests/bin/test/static_code_analyzer/expected_output/rule2.json @@ -0,0 +1,142 @@ +[ + { + "location": { + "filePath": "service.bal", + "startLine": 20, + "endLine": 20, + "startColumn": 23, + "endColumn": 26, + "startOffset": 726, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service.bal" + }, + { + "location": { + "filePath": "service.bal", + "startLine": 27, + "endLine": 27, + "startColumn": 27, + "endColumn": 30, + "startOffset": 847, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service.bal" + }, + { + "location": { + "filePath": "service_class.bal", + "startLine": 23, + "endLine": 23, + "startColumn": 27, + "endColumn": 30, + "startOffset": 791, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service_class.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service_class.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 20, + "endLine": 20, + "startColumn": 23, + "endColumn": 26, + "startOffset": 726, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service_object.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 28, + "endLine": 28, + "startColumn": 27, + "endColumn": 30, + "startOffset": 867, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service_object.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 36, + "endLine": 36, + "startColumn": 23, + "endColumn": 26, + "startOffset": 999, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service_object.bal" + }, + { + "location": { + "filePath": "service_object.bal", + "startLine": 44, + "endLine": 44, + "startColumn": 27, + "endColumn": 30, + "startOffset": 1143, + "length": 3 + }, + "rule": { + "id": "ballerina/http:2", + "numericId": 2, + "description": "Avoid permissive Cross-Origin Resource Sharing", + "ruleKind": "VULNERABILITY" + }, + "source": "BUILT_IN", + "fileName": "rule2/service_object.bal", + "filePath": "/Users/admin/Desktop/WORKSPACE/module-ballerina-http/compiler-plugin-tests/src/test/resources/static_code_analyzer/ballerina_packages/rule2/service_object.bal" + } +] diff --git a/compiler-plugin-tests/bin/test/testng.xml b/compiler-plugin-tests/bin/test/testng.xml new file mode 100644 index 0000000000..7d43c52ab2 --- /dev/null +++ b/compiler-plugin-tests/bin/test/testng.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + diff --git a/compiler-plugin/bin/main/rules.json b/compiler-plugin/bin/main/rules.json new file mode 100644 index 0000000000..2774fb7821 --- /dev/null +++ b/compiler-plugin/bin/main/rules.json @@ -0,0 +1,12 @@ +[ + { + "id": 1, + "kind": "VULNERABILITY", + "description": "Avoid allowing default resource accessor" + }, + { + "id": 2, + "kind": "VULNERABILITY", + "description": "Avoid permissive Cross-Origin Resource Sharing" + } +] diff --git a/gradle.properties b/gradle.properties index b2ecb15a6d..05b9776cd7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.stdlib version=2.13.0-SNAPSHOT -ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 +ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77 ballerinaTomlParserVersion=1.2.2 commonsLang3Version=3.12.0 nettyVersion=4.1.115.Final diff --git a/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/jni-config.json b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/jni-config.json new file mode 100644 index 0000000000..6aacbde53e --- /dev/null +++ b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/jni-config.json @@ -0,0 +1,173 @@ +[ + { + "name": "io.netty.handler.ssl.OpenSslSessionCache", + "methods": [ + { + "name": "getSession", + "parameterTypes": [ + "long", + "byte[]" + ] + }, + { + "name": "sessionCreated", + "parameterTypes": [ + "long", + "long" + ] + } + ] + }, + { + "name": "io.netty.handler.ssl.ReferenceCountedOpenSslContext$AbstractCertificateVerifier", + "methods": [ + { + "name": "verify", + "parameterTypes": [ + "long", + "byte[][]", + "java.lang.String" + ] + } + ] + }, + { + "name": "io.netty.handler.ssl.ReferenceCountedOpenSslServerContext$ExtendedTrustManagerVerifyCallback" + }, + { + "name": "io.netty.handler.ssl.ReferenceCountedOpenSslServerContext$OpenSslServerCertificateCallback", + "methods": [ + { + "name": "handle", + "parameterTypes": [ + "long", + "byte[]", + "byte[][]" + ] + } + ] + }, + { + "name": "io.netty.handler.ssl.ReferenceCountedOpenSslServerContext$OpenSslSniHostnameMatcher", + "methods": [ + { + "name": "match", + "parameterTypes": [ + "long", + "java.lang.String" + ] + } + ] + }, + { + "name": "io.netty.handler.ssl.OpenSslClientSessionCache" + }, + { + "name": "io.netty.handler.ssl.ReferenceCountedOpenSslClientContext$ExtendedTrustManagerVerifyCallback" + }, + { + "name": "io.netty.handler.ssl.ReferenceCountedOpenSslClientContext$OpenSslClientCertificateCallback", + "methods": [ + { + "name": "handle", + "parameterTypes": [ + "long", + "byte[]", + "byte[][]" + ] + } + ] + }, + { + "name": "io.netty.internal.tcnative.Buffer" + }, + { + "name": "io.netty.internal.tcnative.CertificateCallbackTask", + "methods": [ + { + "name": "", + "parameterTypes": [ + "long", + "byte[]", + "byte[][]", + "io.netty.internal.tcnative.CertificateCallback" + ] + } + ] + }, + { + "name": "io.netty.internal.tcnative.CertificateVerifierTask", + "methods": [ + { + "name": "", + "parameterTypes": [ + "long", + "byte[][]", + "java.lang.String", + "io.netty.internal.tcnative.CertificateVerifier" + ] + } + ] + }, + { + "name": "io.netty.internal.tcnative.Library" + }, + { + "name": "io.netty.internal.tcnative.NativeStaticallyReferencedJniMethods" + }, + { + "name": "io.netty.internal.tcnative.SSL" + }, + { + "name": "io.netty.internal.tcnative.SSLContext" + }, + { + "name": "io.netty.internal.tcnative.SSLPrivateKeyMethodDecryptTask", + "methods": [ + { + "name": "", + "parameterTypes": [ + "long", + "byte[]", + "io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod" + ] + } + ] + }, + { + "name": "io.netty.internal.tcnative.SSLPrivateKeyMethodSignTask", + "methods": [ + { + "name": "", + "parameterTypes": [ + "long", + "int", + "byte[]", + "io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod" + ] + } + ] + }, + { + "name": "io.netty.internal.tcnative.SSLPrivateKeyMethodTask", + "fields": [ + { + "name": "resultBytes" + } + ] + }, + { + "name": "io.netty.internal.tcnative.SSLSession" + }, + { + "name": "io.netty.internal.tcnative.SSLTask", + "fields": [ + { + "name": "complete" + }, + { + "name": "returnValue" + } + ] + } +] diff --git a/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/native-image.properties b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/native-image.properties new file mode 100644 index 0000000000..bffdde3712 --- /dev/null +++ b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/native-image.properties @@ -0,0 +1,32 @@ +# Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com) 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. + +Args = --enable-url-protocols=http,https \ + --initialize-at-build-time=org.slf4j \ + --initialize-at-run-time=io.netty.handler.codec.compression.ZstdOptions \ + --initialize-at-run-time=io.netty.handler.codec.http2.Http2ServerUpgradeCodec \ + --initialize-at-run-time=io.netty.handler.ssl.BouncyCastleAlpnSslUtils \ + --initialize-at-run-time=io.netty.handler.ssl.JdkSslServerContext \ + --initialize-at-run-time=io.netty.handler.ssl.OpenSsl \ + --initialize-at-run-time=io.netty.handler.ssl.OpenSslPrivateKeyMethod \ + --initialize-at-run-time=io.netty.handler.ssl.OpenSslAsyncPrivateKeyMethod \ + --initialize-at-run-time=io.netty.handler.ssl.ReferenceCountedOpenSslEngine \ + --initialize-at-run-time=io.netty.internal.tcnative.AsyncSSLPrivateKeyMethod \ + --initialize-at-run-time=io.netty.internal.tcnative.CertificateCompressionAlgo \ + --initialize-at-run-time=io.netty.internal.tcnative.CertificateVerifier \ + --initialize-at-run-time=io.netty.internal.tcnative.SSL \ + --initialize-at-run-time=io.netty.internal.tcnative.SSLPrivateKeyMethod \ + -J--add-opens=java.base/java.nio=ALL-UNNAMED diff --git a/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/reflect-config.json b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/reflect-config.json new file mode 100644 index 0000000000..ca04e5a0d5 --- /dev/null +++ b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/reflect-config.json @@ -0,0 +1,20 @@ +[ + { + "name": "io.netty.channel.socket.nio.NioDatagramChannel", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "io.netty.channel.socket.nio.NioSocketChannel", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + } +] diff --git a/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/resource-config.json b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/resource-config.json new file mode 100644 index 0000000000..4d2de3167f --- /dev/null +++ b/native/bin/main/META-INF/native-image/io.ballerina.stdlib/http-native/resource-config.json @@ -0,0 +1,24 @@ +{ + "resources": { + "includes": [ + { + "pattern": "\\QMETA-INF/native/libnetty_tcnative_linux_x86_64.so\\E" + }, + { + "pattern": "\\QMETA-INF/native/libnetty_tcnative_linux_aarch_64.so\\E" + }, + { + "pattern": "\\QMETA-INF/native/libnetty_tcnative_osx_x86_64.jnilib\\E" + }, + { + "pattern": "\\QMETA-INF/native/libnetty_tcnative_osx_aarch_64.jnilib\\E" + }, + { + "pattern": "\\QMETA-INF/native/netty_tcnative_windows_x86_64.dll\\E" + }, + { + "pattern": "\\Qlogging.properties\\E" + } + ] + } +} diff --git a/native/bin/main/logging.properties b/native/bin/main/logging.properties new file mode 100644 index 0000000000..dd6d2d5b9a --- /dev/null +++ b/native/bin/main/logging.properties @@ -0,0 +1,19 @@ +####################### HANDLERS ####################### +# Log formatter for HTTP trace logs +io.ballerina.stdlib.http.api.logging.formatters.HttpTraceLogFormatter.format=[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS,%1$tL] %2$-5s {%3$s} - %4$s %5$s %n + +# Log formatter for HTTP access logs +io.ballerina.stdlib.http.api.logging.formatters.HttpAccessLogFormatter.format=%1$s %n + +####################### LOGGERS ####################### +# Root logger +handlers=java.util.logging.ConsoleHandler +.level=OFF + +# HTTP tracing logger - This is turned off by default, to turn on, set level to 'FINE' or lower +http.tracelog.level=OFF +http.tracelog.useParentHandlers=false + +# HTTP access logger +http.accesslog.level=OFF +http.accesslog.useParentHandlers=false diff --git a/native/bin/test/logging.properties b/native/bin/test/logging.properties new file mode 100644 index 0000000000..6ce6dfee5f --- /dev/null +++ b/native/bin/test/logging.properties @@ -0,0 +1,40 @@ +# +# Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. 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. +# + +####################### HANDLERS ####################### +# Configurations for console logging +java.util.logging.ConsoleHandler.level=ALL +java.util.logging.ConsoleHandler.formatter=org.ballerinalang.logging.formatters.BallerinaLogFormatter +org.ballerinalang.logging.formatters.BallerinaLogFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS,%1$tL %2$s [%3$s] - %4$s %n + +org.ballerinalang.stdlib.common.TestLogHandler.level=INFO +org.ballerinalang.stdlib.common.TestLogHandler.formatter=org.ballerinalang.logging.formatters.DefaultLogFormatter +org.ballerinalang.logging.formatters.DefaultLogFormatter.format=[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS,%1$tL] %2$s [%3$s] - %4$s %5$s %n + +####################### LOGGERS ####################### +# Ballerina user level root logger +ballerina.handlers=java.util.logging.ConsoleHandler +ballerina.level=SEVERE +ballerina.useParentHandlers=false + +# JUL root logger +.handlers=org.ballerinalang.stdlib.common.TestLogHandler +.level=SEVERE + +com.zaxxer.hikari.level=SEVERE +org.quartz.level=SEVERE diff --git a/native/bin/test/simple-test-config/cacerts.p12 b/native/bin/test/simple-test-config/cacerts.p12 new file mode 100644 index 0000000000..689734fb0e Binary files /dev/null and b/native/bin/test/simple-test-config/cacerts.p12 differ diff --git a/native/bin/test/simple-test-config/certificatevalidation/DigiCertHighAssuranceEVCA-1 b/native/bin/test/simple-test-config/certificatevalidation/DigiCertHighAssuranceEVCA-1 new file mode 100644 index 0000000000..35e0a3a3fc --- /dev/null +++ b/native/bin/test/simple-test-config/certificatevalidation/DigiCertHighAssuranceEVCA-1 @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIEtjCCA56gAwIBAgIQDHmpRLCMEZUgkmFf4msdgzANBgkqhkiG9w0BAQsFADBs +MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j +ZSBFViBSb290IENBMB4XDTEzMTAyMjEyMDAwMFoXDTI4MTAyMjEyMDAwMFowdTEL +MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 +LmRpZ2ljZXJ0LmNvbTE0MDIGA1UEAxMrRGlnaUNlcnQgU0hBMiBFeHRlbmRlZCBW +YWxpZGF0aW9uIFNlcnZlciBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBANdTpARR+JmmFkhLZyeqk0nQOe0MsLAAh/FnKIaFjI5j2ryxQDji0/XspQUY +uD0+xZkXMuwYjPrxDKZkIYXLBxA0sFKIKx9om9KxjxKws9LniB8f7zh3VFNfgHk/ +LhqqqB5LKw2rt2O5Nbd9FLxZS99RStKh4gzikIKHaq7q12TWmFXo/a8aUGxUvBHy +/Urynbt/DvTVvo4WiRJV2MBxNO723C3sxIclho3YIeSwTQyJ3DkmF93215SF2AQh +cJ1vb/9cuhnhRctWVyh+HA1BV6q3uCe7seT6Ku8hI3UarS2bhjWMnHe1c63YlC3k +8wyd7sFOYn4XwHGeLN7x+RAoGTMCAwEAAaOCAUkwggFFMBIGA1UdEwEB/wQIMAYB +Af8CAQAwDgYDVR0PAQH/BAQDAgGGMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEF +BQcDAjA0BggrBgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRp +Z2ljZXJ0LmNvbTBLBgNVHR8ERDBCMECgPqA8hjpodHRwOi8vY3JsNC5kaWdpY2Vy +dC5jb20vRGlnaUNlcnRIaWdoQXNzdXJhbmNlRVZSb290Q0EuY3JsMD0GA1UdIAQ2 +MDQwMgYEVR0gADAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5j +b20vQ1BTMB0GA1UdDgQWBBQ901Cl1qCt7vNKYApl0yHU+PjWDzAfBgNVHSMEGDAW +gBSxPsNpA/i/RwHUmCYaCALvY2QrwzANBgkqhkiG9w0BAQsFAAOCAQEAnbbQkIbh +hgLtxaDwNBx0wY12zIYKqPBKikLWP8ipTa18CK3mtlC4ohpNiAexKSHc59rGPCHg +4xFJcKx6HQGkyhE6V6t9VypAdP3THYUYUN9XR3WhfVUgLkc3UHKMf4Ib0mKPLQNa +2sPIoc4sUqIAY+tzunHISScjl2SFnjgOrWNoPLpSgVh5oywM395t6zHyuqB8bPEs +1OG9d4Q3A84ytciagRpKkk47RpqF/oOi+Z6Mo8wNXrM9zwR4jxQUezKcxwCmXMS1 +oVWNWlZopCJwqjyBcdmdqEU79OX2olHdx3ti6G8MdOu42vi/hw15UJGQmxg7kVkn +8TUoE6smftX3eg== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/native/bin/test/simple-test-config/certificatevalidation/DigiCertHighAssuranceEVRootCA b/native/bin/test/simple-test-config/certificatevalidation/DigiCertHighAssuranceEVRootCA new file mode 100644 index 0000000000..85bc580a44 --- /dev/null +++ b/native/bin/test/simple-test-config/certificatevalidation/DigiCertHighAssuranceEVRootCA @@ -0,0 +1,23 @@ +-----BEGIN CERTIFICATE----- +MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs +MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 +d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j +ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL +MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 +LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug +RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm ++9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW +PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM +xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB +Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3 +hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg +EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF +MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA +FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec +nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z +eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF +hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2 +Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe +vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep ++OkuE6N36B9K +-----END CERTIFICATE----- \ No newline at end of file diff --git a/native/bin/test/simple-test-config/certsAndKeys/ocspCertChain.crt b/native/bin/test/simple-test-config/certsAndKeys/ocspCertChain.crt new file mode 100644 index 0000000000..e66226c5a9 --- /dev/null +++ b/native/bin/test/simple-test-config/certsAndKeys/ocspCertChain.crt @@ -0,0 +1,33 @@ +-----BEGIN CERTIFICATE----- +MIIC6DCCAlGgAwIBAgIBATANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJMSzEQ +MA4GA1UECAwHcm9vdC1jYTENMAsGA1UEBwwEcm9vdDELMAkGA1UECgwCY2EwHhcN +MTUwODEzMDgwMDAwWhcNMjUwODEzMDkwMDAwWjBQMQswCQYDVQQGEwJMSzEQMA4G +A1UECBMHd2VzdGVybjERMA8GA1UEChMIa2V5c3RvcmUxDjAMBgNVBAsTBXN0b3Jl +MQwwCgYDVQQDEwNrZXkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC9 +i9LLylnen+Go7IuPYpfKVUADWEGVXsSP11iEuJIgToIGWOB/OVMXjbMRexWmkBYu +78UeVh7Mx/MgkqJ/o4kpMG4OSfOXTBazadUJn+JOywVwfBJW+q8yRfP9PMku605C +Rat5RqkecvVxIWmdUIZ18PVVVFjzoSWFlesdOU/PNo7oflJ2wu1v9Ysr514MPA0I +QhUEJ65xr0uoWpSOx/wnKUexk+EUd7/dVzj9s+o7qzOSQnseP25HcUux6p72q88F +oxYEtrgwnWg+rACk/Klajc/I9iA1naWW8UJEMx5Y2GF5kLNTk2oYVMgs8pbl0rJ5 +8TrXY/z4JMCz4JXYI/gtAgMBAAGjYzBhMCwGA1UdHwQlMCMwIaAfoB2GG2h0dHA6 +Ly9sb2NhbGhvc3Qvcm9vdENBLmNybDAxBggrBgEFBQcBAQQlMCMwIQYIKwYBBQUH +MAGGFWh0dHA6Ly8xMjcuMC4wLjE6ODA4MDANBgkqhkiG9w0BAQQFAAOBgQCOs/QF +bmCEbQfhLXdEGWkJ4rA63xduH5YphDlfZ7paPl9/OjnwC1JBRZTUAilvPOndv5IQ +IijYSBDJxyhKWIG+7vI/iqUbmqG8bjGBAIyoZz5cb0KVriB2A0+QkSwEkaNxYwqy +cmMNxJJuAjBuJoTe1yvrq73MmTnkt2G6sUCeMQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIICazCCAdSgAwIBAgIJANWDrPG8zSJqMA0GCSqGSIb3DQEBCwUAMDsxCzAJBgNV +BAYTAkxLMRAwDgYDVQQIDAdyb290LWNhMQ0wCwYDVQQHDARyb290MQswCQYDVQQK +DAJjYTAeFw0xODAyMDgxMjM5MDhaFw0yODAyMDYxMjM5MDhaMDsxCzAJBgNVBAYT +AkxLMRAwDgYDVQQIDAdyb290LWNhMQ0wCwYDVQQHDARyb290MQswCQYDVQQKDAJj +YTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2QfdsqpOMpQ6au+E2jEayZ2k +JPRrfhlzoL92zS7UTzmOc11CSQ/L43lat1mnOcjKsHm4y87TAh/+QhQppQ2br9Dl +LGWLNu4X71HkrPERLHXOp9139iD8q7w4XOPj5N3zALIE9DRqMp4xmdaRxMA6wge+ +I9k6rjn6mscI4MZ73lcCAwEAAaN3MHUwDwYDVR0TAQH/BAUwAwEB/zAvBgNVHR8E +KDAmMCSgIqAghh7igItodHRwOi8vbG9jYWxob3N0L3Jvb3RDQS5jcmwwMQYIKwYB +BQUHAQEEJTAjMCEGCCsGAQUFBzABhhVodHRwOi8vMTI3LjAuMC4xOjgwODAwDQYJ +KoZIhvcNAQELBQADgYEAhGqack6LVXNlTcXtH3TVlt0/GkVEO6iR1p8eo72zHjEg ++VowFC41eZRtpWxr0F41E0K7a2OypXVE9D6pIQSv/BA/e1Ph/J6hyjPQTGltcGge +WWIKVLkFLpegJ1yvRdQaQRKnpMom0N3XCyY26w7xnp9EdV1EiVZP2et28AhTjSs= +-----END CERTIFICATE----- diff --git a/native/bin/test/simple-test-config/certsAndKeys/private.key b/native/bin/test/simple-test-config/certsAndKeys/private.key new file mode 100644 index 0000000000..0c7915581e --- /dev/null +++ b/native/bin/test/simple-test-config/certsAndKeys/private.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpIL03xTlH6C3V +e8ES8wjNBjXAnKt4GgSEiVYLPDYK1wngbEWT6wN7o2a5DS13QlWZMWS/8bwKez7f +TBTspkuE1xGNM5OkdUCSPrNdiV+vPjPgn3La+dsUql+1iBqY5lcTcvN7+sCkDANV +1ApyMBpJz29Bx/bzXSi7bU2s7hGLI4d48n0XpNAxesHAWYLZO8KaPpbXe3FvB59r +87VBIRtWAtCMztdT9BcXbYGVKuvOvKeyV/yjd67b5GTexTpHGKPKiBGn2Yx7S5Mp +T4sHbnZGpR+kOx06dU2Jxw9CL/qyMI8+EXHzWtgauQf0IS8Fy/Mt4ziYHA5+dwfU +Hcem4ERjAgMBAAECggEATf9bRC0gjZj2Ck5YbHTIykTi5UFbkrfs/XKYy/WotrcV +Rvqn29+2a36gEReSsD1XXJ7658qD/hF4nWJpA/ptOYY2AfiXTnEEpm1kKu7/wcHe +Cul9/p7b+lvYZ8+s9HbGEaIhyDuMPBuOLjbr2l10wjV4Cc4+hV2hO07dU7M3RAMO +aF7MDlPrk3ZSxz3uT1FyEbjn8rh2lbm3N35G2/6BaEAqOD4XPacbEzcR8map4ZE4 +4CInDi4/uQGXMUPBRmKGtr45HzjJTBhqft2coAOsR0n0qxDc9LaCrK0iFnOOVz3l +Grbdw3/+chet1zV76HZgUGqK4UVQUXU90tP6loQiAQKBgQDceAxtbHEpzAnoCsb+ +CG+Bk1Sg6xEmT7dfwW5PqgWlHzUzjMJuqcrh2UUWg144gAYnlRdA1HYKFNL1Qk27 +DT5VA+3H15m07RISMxQy4Zysbd9EGr7IUr9lQ7fzlfuVtZJspqgDuYqX/Bb+UWiO +ZWPFstiOGhCIeY1ucKflSaKpkQKBgQDEYn9vGablFIS4Ht3SW3A5I9KRrLd2O8U6 +xu8eFV4pC477QHx9TMz6vuKUutuA9ZTNfEumZLZycA1eYDPZqx3SbJMbWexJ5PGf +Hxcyw5Bc7iHpLqOzUPs7UkHwaTWS1kwKQpwLNRbXNVlDYI7+94cjQk0/MeFc5hof +NyE0iW50swKBgQC/yKZ24ainRVkww39LKKdnPnSV7yZh/2JzJ97/6dUzSKyNBVt1 +zLoyMUDKTsi9uZChCi7KNIfiSS8iLuVTXDfm2J4WA9Uv8DKSJmDhyiTyUjmwEtv3 +gxP/0SLKAKR0HRkc7vSlGNgZUi/mV4buqABc0DFVnBLZxXNkqRdEfAPGIQKBgHpl +oWMPK9Ou/CD9K+eFkeYrC3w7l4SbMAu4HSQ00SDn0U+LG4vEqCTHf9SOuWwgo4OG +qmekcYnViJ9/ehF58vZJMU5ktz4+8NDpwb2j4X/p8zywEtsZ59tLI0nBaOCBq5bh +ePwLNJcg6udxcO48O/+fvSFb50fNKg62f32NAki9AoGAJ71xzoCVzTspX+jFwXaX +3GYJVERAvTreZhGMMS5vlKvWGfpEfWXacCuPceH1SsHwZK68y1gfFYaQVSScF49I +u1u1ZzkVQZQYkemRHGuM12/JY+jEfCvAWDKrSMfSVrly9qtUTU44Ti5MYmWsp9rD +/OAKIOElPvQzS8DL/TtD1TQ= +-----END PRIVATE KEY----- diff --git a/native/bin/test/simple-test-config/certsAndKeys/public.crt b/native/bin/test/simple-test-config/certsAndKeys/public.crt new file mode 100644 index 0000000000..94d24f046b --- /dev/null +++ b/native/bin/test/simple-test-config/certsAndKeys/public.crt @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDsTCCApmgAwIBAgIUAcBP5M4LISxVgyGsnJohqmsCN/kwDQYJKoZIhvcNAQEL +BQAwaDELMAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3Rlcm4xEDAOBgNVBAcMB0Nv +bG9tYm8xDTALBgNVBAoMBHdzbzIxEjAQBgNVBAsMCWJhbGxlcmluYTESMBAGA1UE +AwwJbG9jYWxob3N0MB4XDTE5MDgwNTA1MTMwNVoXDTI5MDgwMjA1MTMwNVowaDEL +MAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3Rlcm4xEDAOBgNVBAcMB0NvbG9tYm8x +DTALBgNVBAoMBHdzbzIxEjAQBgNVBAsMCWJhbGxlcmluYTESMBAGA1UEAwwJbG9j +YWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqSC9N8U5R+gt +1XvBEvMIzQY1wJyreBoEhIlWCzw2CtcJ4GxFk+sDe6NmuQ0td0JVmTFkv/G8Cns+ +30wU7KZLhNcRjTOTpHVAkj6zXYlfrz4z4J9y2vnbFKpftYgamOZXE3Lze/rApAwD +VdQKcjAaSc9vQcf2810ou21NrO4RiyOHePJ9F6TQMXrBwFmC2TvCmj6W13txbwef +a/O1QSEbVgLQjM7XU/QXF22BlSrrzrynslf8o3eu2+Rk3sU6RxijyogRp9mMe0uT +KU+LB252RqUfpDsdOnVNiccPQi/6sjCPPhFx81rYGrkH9CEvBcvzLeM4mBwOfncH +1B3HpuBEYwIDAQABo1MwUTAdBgNVHQ4EFgQU8NRYN+9Cj1nCT/8/z69SdoosStQw +HwYDVR0jBBgwFoAU8NRYN+9Cj1nCT/8/z69SdoosStQwDwYDVR0TAQH/BAUwAwEB +/zANBgkqhkiG9w0BAQsFAAOCAQEAHuS1UwR8yrh7QdmZRPuX6BQWETXXEsto0bnp +DD+c5u5WptUg/bYkAGsnkuHYv7TQcN163SXpnExg1QnMcdF+XuwCVtGpqZrmcosv +ZPCf/CWoobBxsuiim5mY8zD3WwdzAO8kZheemiZM5FZYhaXkBymNNe7qvL/aC6Cu +wyC3n+4GOtV+xabmH4T/p7HEcvq2SY0YGTpJ0OcUlvJ3UqzhTieK67dSFKmDN3hO +BrxacFV9ybzub67erPkQpV4GpJUW9HShp0qXr6WuX1hg7WA6RgneWkq3y2h6sts/ +c5S/dAP8KlqghvEdv8lnAcSqjN3kSTim/JMMe4kChtjUE7C1Ag== +-----END CERTIFICATE----- diff --git a/native/bin/test/simple-test-config/client-truststore.jks b/native/bin/test/simple-test-config/client-truststore.jks new file mode 100644 index 0000000000..cd16dd7e8c Binary files /dev/null and b/native/bin/test/simple-test-config/client-truststore.jks differ diff --git a/native/bin/test/simple-test-config/client-truststore.p12 b/native/bin/test/simple-test-config/client-truststore.p12 new file mode 100644 index 0000000000..5f5ec6a792 Binary files /dev/null and b/native/bin/test/simple-test-config/client-truststore.p12 differ diff --git a/native/bin/test/simple-test-config/http2/netty-transports.yml b/native/bin/test/simple-test-config/http2/netty-transports.yml new file mode 100644 index 0000000000..9c5206c227 --- /dev/null +++ b/native/bin/test/simple-test-config/http2/netty-transports.yml @@ -0,0 +1,151 @@ +################################################################################ +# Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# Licensed 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. +################################################################################ +transportProperties: + - + name: "latency.metrics.enabled" + value: true + - + name: "request.size.validation" + value: false + - + name: "request.size.validation.maximum.value" #in bytes + value: 2048 + - + name: "request.size.validation.reject.status.code" + value: 401 + - + name: "request.size.validation.reject.message" + value: "Message is too big, hence cannot proceed" + - + name: "request.size.validation.reject.message.content.type" + value: "plain/text" + - + name: "header.size.validation" + value: false + - + name: "header.validation.maximum.request.line" #in bytes + value: 2048 + - + name: "header.validation.maximum.size" #in bytes + value: 2048 + - + name: "header.validation.maximum.chunk.size" #in bytes, refere http://netty.io/4.0/api/io/netty/handler/codec/http/HttpRequestDecoder.html + value: 2048 + - + name: "header.validation.reject.status.code" + value: 401 + - + name: "header.validation.reject.message" + value: "Message's header size is too big, hence cannot proceed" + - + name: "header.validation.reject.message.content.type" + value: "plain/text" + - + name: "server.bootstrap.boss.group.size" + value: 4 + - + name: "server.bootstrap.worker.group.size" + value: 8 + - + name: "server.bootstrap.nodelay" + value: true + - + name: "server.bootstrap.keepalive" + value: true + - + name: "server.bootstrap.sendbuffersize" + value: 1048576 + - + name: "server.bootstrap.recievebuffersize" + value: 1048576 + - + name: "server.bootstrap.connect.timeout" + value: 15000 + - + name: "server.bootstrap.socket.reuse" + value: false + - + name: "server.bootstrap.socket.timeout" + value: 15 + - + name: "server.bootstrap.socket.backlog" + value: 100 + +listenerConfigurations: + - + id: "default" + host: "0.0.0.0" + port: 8490 + http2: true + +senderConfigurations: + - + id: "http-sender" + parameters: + - + name: "connection.pool.count" + value: 0 + - + name: "client.bootstrap.nodelay" + value: true + - + name: "client.bootstrap.keepalive" + value: true + - + name: "client.bootstrap.sendbuffersize" + value: 1048576 + - + name: "client.bootstrap.recievebuffersize" + value: 1048576 + - + name: "client.bootstrap.connect.timeout" + value: 15000 + - + name: "client.bootstrap.socket.reuse" + value: false + - + name: "client.bootstrap.socket.timeout" + value: 15 + - + id: "https-sender" + scheme: "https" + trustStoreFile: "simple-test-config/client-truststore.jks" + trustStorePass: "wso2carbon" + parameters: + - + name: "connection.pool.count" + value: 0 + - + name: "client.bootstrap.nodelay" + value: true + - + name: "client.bootstrap.keepalive" + value: true + - + name: "client.bootstrap.sendbuffersize" + value: 1048576 + - + name: "client.bootstrap.recievebuffersize" + value: 1048576 + - + name: "client.bootstrap.connect.timeout" + value: 15000 + - + name: "client.bootstrap.socket.reuse" + value: false + - + name: "client.bootstrap.socket.timeout" + value: 15 diff --git a/native/bin/test/simple-test-config/localcrt.p12 b/native/bin/test/simple-test-config/localcrt.p12 new file mode 100644 index 0000000000..5fbac4534c Binary files /dev/null and b/native/bin/test/simple-test-config/localcrt.p12 differ diff --git a/native/bin/test/simple-test-config/netty-transports.yml b/native/bin/test/simple-test-config/netty-transports.yml new file mode 100644 index 0000000000..11329a83fb --- /dev/null +++ b/native/bin/test/simple-test-config/netty-transports.yml @@ -0,0 +1,152 @@ +################################################################################ +# Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# Licensed 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. +################################################################################ +transportProperties: + - + name: "latency.metrics.enabled" + value: true + - + name: "request.size.validation" + value: false + - + name: "request.size.validation.maximum.value" #in bytes + value: 2048 + - + name: "request.size.validation.reject.status.code" + value: 401 + - + name: "request.size.validation.reject.message" + value: "Message is too big, hence cannot proceed" + - + name: "request.size.validation.reject.message.content.type" + value: "plain/text" + - + name: "header.size.validation" + value: false + - + name: "header.validation.maximum.request.line" #in bytes + value: 2048 + - + name: "header.validation.maximum.size" #in bytes + value: 2048 + - + name: "header.validation.maximum.chunk.size" #in bytes, refere http://netty.io/4.0/api/io/netty/handler/codec/http/HttpRequestDecoder.html + value: 2048 + - + name: "header.validation.reject.status.code" + value: 401 + - + name: "header.validation.reject.message" + value: "Message's header size is too big, hence cannot proceed" + - + name: "header.validation.reject.message.content.type" + value: "plain/text" + - + name: "server.bootstrap.boss.group.size" + value: 4 + - + name: "server.bootstrap.worker.group.size" + value: 8 + - + name: "server.bootstrap.nodelay" + value: true + - + name: "server.bootstrap.keepalive" + value: true + - + name: "server.bootstrap.sendbuffersize" + value: 1048576 + - + name: "server.bootstrap.recievebuffersize" + value: 1048576 + - + name: "server.bootstrap.connect.timeout" + value: 15000 + - + name: "server.bootstrap.socket.reuse" + value: false + - + name: "server.bootstrap.socket.timeout" + value: 15 + - + name: "server.bootstrap.socket.backlog" + value: 100 + +listenerConfigurations: + - + id: "default" + host: "0.0.0.0" + port: 8490 + +senderConfigurations: + - + id: "http-sender" + socketIdleTimeout: 120000 + parameters: + - + name: "connection.pool.count" + value: 0 + - + name: "client.bootstrap.nodelay" + value: true + - + name: "client.bootstrap.keepalive" + value: true + - + name: "client.bootstrap.sendbuffersize" + value: 1048576 + - + name: "client.bootstrap.recievebuffersize" + value: 1048576 + - + name: "client.bootstrap.connect.timeout" + value: 15000 + - + name: "client.bootstrap.socket.reuse" + value: false + - + name: "client.bootstrap.socket.timeout" + value: 15 + - + id: "https-sender" + scheme: "https" + trustStoreFile: "/simple-test-config/wso2carbon.jks" + trustStorePass: "wso2carbon" + socketIdleTimeout: 120000 + parameters: + - + name: "connection.pool.count" + value: 0 + - + name: "client.bootstrap.nodelay" + value: true + - + name: "client.bootstrap.keepalive" + value: true + - + name: "client.bootstrap.sendbuffersize" + value: 1048576 + - + name: "client.bootstrap.recievebuffersize" + value: 1048576 + - + name: "client.bootstrap.connect.timeout" + value: 15000 + - + name: "client.bootstrap.socket.reuse" + value: false + - + name: "client.bootstrap.socket.timeout" + value: 15 diff --git a/native/bin/test/simple-test-config/wso2carbon.jks b/native/bin/test/simple-test-config/wso2carbon.jks new file mode 100644 index 0000000000..560787073f Binary files /dev/null and b/native/bin/test/simple-test-config/wso2carbon.jks differ diff --git a/native/bin/test/simple-test-config/wso2carbon.p12 b/native/bin/test/simple-test-config/wso2carbon.p12 new file mode 100644 index 0000000000..cd38805e8d Binary files /dev/null and b/native/bin/test/simple-test-config/wso2carbon.p12 differ diff --git a/native/bin/test/testng.xml b/native/bin/test/testng.xml new file mode 100644 index 0000000000..baec87d43b --- /dev/null +++ b/native/bin/test/testng.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +