├── .gitattributes
├── .github
├── CODEOWNERS
├── issue_template.md
├── pull_request_template.md
└── workflows
│ ├── build-timestamped-master.yml
│ ├── build-with-bal-test-graalvm.yml
│ ├── central-publish.yml
│ ├── fossa_scan.yml
│ ├── process-load-test-result.yml
│ ├── publish-release.yml
│ ├── pull-request.yml
│ ├── trigger-load-tests.yml
│ ├── trivy-scan.yml
│ └── update_spec.yml
├── .gitignore
├── .trivyignore
├── LICENSE
├── README.md
├── ballerina
├── Ballerina.toml
├── CompilerPlugin.toml
├── Dependencies.toml
├── README.md
├── annotation.bal
├── auth_desugar.bal
├── auth_types.bal
├── auth_utils.bal
├── build.gradle
├── close_frame_return_types.bal
├── icon.png
├── init.bal
├── service_endpoint.bal
├── tests
│ ├── Config.toml
│ ├── auth_declarative_basic_auth_test.bal
│ ├── auth_declarative_bearer_token_auth_test.bal
│ ├── auth_declarative_jwt_auth_test.bal
│ ├── auth_declarative_oauth2_test.bal
│ ├── auth_test_commons.bal
│ ├── caller_close_test.bal
│ ├── cancel_websocket_upgrade_test.bal
│ ├── certsAndKeys
│ │ ├── ballerinaKeystore.p12
│ │ ├── ballerinaTruststore.p12
│ │ ├── private.key
│ │ └── public.crt
│ ├── client_handshake_timeout_test.bal
│ ├── client_init_test.bal
│ ├── close_frame_test.bal
│ ├── connection_close_test.bal
│ ├── connection_closure_timeout.bal
│ ├── constraint_test.bal
│ ├── cookie_sync_client_test.bal
│ ├── corrupted_frame_server_test.bal
│ ├── custom_remote_functions.bal
│ ├── data_binding_with_enum.bal
│ ├── http_header_param_binding_test.bal
│ ├── http_query_param_binding_test.bal
│ ├── invalid_base_path_test.bal
│ ├── malformed_url_test.bal
│ ├── on_binary_with_on_error.bal
│ ├── read_message_function_test.bal
│ ├── read_message_on_message_test.bal
│ ├── retry_client_test_read.bal
│ ├── retry_client_test_write.bal
│ ├── server_idle_timeout_test.bal
│ ├── service_error_returned_binary_message.bal
│ ├── service_test_error_when_returning_message.bal
│ ├── simple_server_without_ping_resource.bal
│ ├── start_attach_detach_stop_test.bal
│ ├── stream_test.bal
│ ├── sync_client_idle_timeout.bal
│ ├── sync_client_onError.bal
│ ├── sync_client_ping_pong.bal
│ ├── sync_client_read_binary_chunks_test.bal
│ ├── sync_client_read_text_chunks_test.bal
│ ├── sync_client_send_binary_data_chunks_test.bal
│ ├── sync_client_send_text_data_chunk_test.bal
│ ├── sync_client_ssl_error.bal
│ ├── sync_client_ssl_test.bal
│ ├── sync_client_test_bytes.bal
│ ├── sync_client_test_text.bal
│ ├── sync_connection_close.bal
│ ├── test_caller_util_functions.bal
│ ├── test_close_while_reading.bal
│ ├── test_data_binding_json.bal
│ ├── test_data_binding_union.bal
│ ├── test_data_binding_xml.bal
│ ├── test_dispatcher_mapping_annotation.bal
│ ├── test_dispatching_error.bal
│ ├── test_dispatching_special_charachters.bal
│ ├── test_readMessage_after_connection_closure.bal
│ ├── test_readonly_values.bal
│ ├── test_returning_error.bal
│ ├── test_upgrade_service_panic.bal
│ ├── websocket_client_close.bal
│ ├── websocket_client_exceptions.bal
│ ├── websocket_client_service.bal
│ ├── websocket_custom_headers_test.bal
│ ├── websocket_disable_ssl_client_test.bal
│ ├── websocket_listener_init_errors.bal
│ ├── websocket_missing_resources.bal
│ ├── websocket_mutual_ssl_test.bal
│ ├── websocket_mutual_ssl_with_certs.bal
│ ├── websocket_ping_pong.bal
│ ├── websocket_pushText_failure.bal
│ ├── websocket_simple_proxy_server.bal
│ ├── websocket_ssl_protocol_error.bal
│ ├── websocket_ssl_proxy.bal
│ └── write_text_and_onText.bal
├── websocket_caller.bal
├── websocket_errors.bal
├── websocket_sync_client.bal
└── websocket_types.bal
├── build-config
├── checkstyle
│ └── build.gradle
└── resources
│ ├── Ballerina.toml
│ └── CompilerPlugin.toml
├── build.gradle
├── changelog.md
├── codecov.yml
├── compiler-plugin-tests
├── build.gradle
├── spotbugs-exclude.xml
└── src
│ └── test
│ ├── java
│ └── io
│ │ └── ballerina
│ │ └── stdlib
│ │ └── websocket
│ │ └── compiler
│ │ ├── AbstractCodeActionTest.java
│ │ ├── CodeSnippetGenerationCodeActionTest.java
│ │ └── WebSocketServiceValidationTest.java
│ └── resources
│ ├── ballerina_sources
│ ├── sample_package_1
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_10
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_11
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_12
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_13
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_14
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_15
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_16
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_17
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_18
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_19
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_2
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_20
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_21
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_22
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_23
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_24
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_25
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_26
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_27
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_28
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_29
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_3
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_30
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_31
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_32
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_33
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_34
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_35
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_36
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_37
│ │ ├── Ballerina.toml
│ │ ├── on_open.bal
│ │ ├── service.bal
│ │ └── service2.bal
│ ├── sample_package_38
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_39
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_4
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_40
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_41
│ │ ├── Ballerina.toml
│ │ ├── service2.bal
│ │ └── service3.bal
│ ├── sample_package_42
│ │ ├── Ballerina.toml
│ │ └── service2.bal
│ ├── sample_package_43
│ │ ├── Ballerina.toml
│ │ ├── service.bal
│ │ └── service2.bal
│ ├── sample_package_44
│ │ ├── Ballerina.toml
│ │ ├── service.bal
│ │ ├── service10.bal
│ │ ├── service2.bal
│ │ ├── service3.bal
│ │ ├── service4.bal
│ │ ├── service5.bal
│ │ ├── service6.bal
│ │ ├── service7.bal
│ │ ├── service8.bal
│ │ └── service9.bal
│ ├── sample_package_45
│ │ ├── Ballerina.toml
│ │ ├── service.bal
│ │ └── service2.bal
│ ├── sample_package_46
│ │ ├── Ballerina.toml
│ │ └── on_close.bal
│ ├── sample_package_47
│ │ ├── Ballerina.toml
│ │ └── on_binary.bal
│ ├── sample_package_48
│ │ ├── Ballerina.toml
│ │ └── on_text.bal
│ ├── sample_package_49
│ │ ├── Ballerina.toml
│ │ └── on_message.bal
│ ├── sample_package_5
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_50
│ │ ├── Ballerina.toml
│ │ └── on_ping.bal
│ ├── sample_package_51
│ │ ├── Ballerina.toml
│ │ └── on_pong.bal
│ ├── sample_package_52
│ │ ├── Ballerina.toml
│ │ └── on_error.bal
│ ├── sample_package_53
│ │ ├── Ballerina.toml
│ │ └── on_idletimeout.bal
│ ├── sample_package_54
│ │ ├── Ballerina.toml
│ │ ├── server.bal
│ │ └── server2.bal
│ ├── sample_package_55
│ │ ├── Ballerina.toml
│ │ ├── data_types.bal
│ │ └── server.bal
│ ├── sample_package_56
│ │ ├── Ballerina.toml
│ │ └── server.bal
│ ├── sample_package_57
│ │ ├── Ballerina.toml
│ │ └── server.bal
│ ├── sample_package_58
│ │ ├── Ballerina.toml
│ │ ├── server.bal
│ │ ├── server2.bal
│ │ ├── server3.bal
│ │ └── server4.bal
│ ├── sample_package_59
│ │ ├── Ballerina.toml
│ │ └── server.bal
│ ├── sample_package_6
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_60
│ │ ├── Ballerina.toml
│ │ └── server.bal
│ ├── sample_package_61
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_62
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_63
│ │ ├── Ballerina.toml
│ │ └── server.bal
│ ├── sample_package_64
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_7
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── sample_package_8
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ └── sample_package_9
│ │ ├── Ballerina.toml
│ │ └── service.bal
│ ├── codeaction
│ └── code_snippet_generation
│ │ ├── on_binary.bal
│ │ ├── on_close.bal
│ │ ├── on_error.bal
│ │ ├── on_idletimeout.bal
│ │ ├── on_message.bal
│ │ ├── on_open.bal
│ │ ├── on_ping.bal
│ │ ├── on_pong.bal
│ │ ├── on_text.bal
│ │ ├── result.bal
│ │ └── result2.bal
│ └── testng.xml
├── compiler-plugin
├── build.gradle
├── spotbugs-exclude.xml
└── src
│ └── main
│ └── java
│ ├── io
│ └── ballerina
│ │ └── stdlib
│ │ └── websocket
│ │ └── plugin
│ │ ├── AddWebSocketCodeTemplate.java
│ │ ├── ListenerInitExpressionNodeVisitor.java
│ │ ├── OnBinaryMessageCodeTemplate.java
│ │ ├── OnCloseCodeTemplate.java
│ │ ├── OnErrorCodeTemplate.java
│ │ ├── OnIdleTimeoutCodeTemplate.java
│ │ ├── OnMessageCodeTemplate.java
│ │ ├── OnOpenCodeTemplate.java
│ │ ├── OnPingCodeTemplate.java
│ │ ├── OnPongCodeTemplate.java
│ │ ├── OnTextMessageCodeTemplate.java
│ │ ├── PluginConstants.java
│ │ ├── ReturnStatementNodeVisitor.java
│ │ ├── Utils.java
│ │ ├── WebSocketCompilerPlugin.java
│ │ ├── WebSocketServiceAnalyzer.java
│ │ ├── WebSocketServiceValidator.java
│ │ ├── WebSocketServiceValidatorTask.java
│ │ ├── WebSocketUpgradeServiceValidator.java
│ │ └── WebSocketUpgradeServiceValidatorTask.java
│ └── module-info.java
├── docs
├── proposals
│ ├── data-binding-api.md
│ ├── dispatching-to-custom-remote-functions.md
│ └── readMessage-api.md
└── spec
│ └── spec.md
├── examples
├── _resources
│ └── Dependencies.toml
├── build.gradle
├── chat-application
│ ├── A Basic Chat Application using the Ballerina WebSocket Module.md
│ ├── client
│ │ ├── .gitignore
│ │ ├── Ballerina.toml
│ │ ├── Dependencies.toml
│ │ └── client.bal
│ └── server
│ │ ├── .gitignore
│ │ ├── Ballerina.toml
│ │ ├── Dependencies.toml
│ │ ├── server.bal
│ │ └── tests
│ │ └── test_chat_server.bal
├── taxi-service-management
│ ├── Building a Real-Time Taxi Management Service with Ballerina.md
│ ├── driver
│ │ ├── .gitignore
│ │ ├── Ballerina.toml
│ │ ├── Dependencies.toml
│ │ └── driver.bal
│ ├── rider
│ │ ├── .gitignore
│ │ ├── Ballerina.toml
│ │ ├── Dependencies.toml
│ │ └── rider.bal
│ ├── server
│ │ ├── .gitignore
│ │ ├── Ballerina.toml
│ │ ├── Dependencies.toml
│ │ ├── server.bal
│ │ └── tests
│ │ │ └── test_server.bal
│ └── taxi.jpeg
└── tic-tac-toe
│ ├── Building a Real-Time Multiplayer Tic Tac Toe Game using Ballerina.md
│ ├── server
│ ├── .gitignore
│ ├── Ballerina.toml
│ ├── Dependencies.toml
│ ├── server.bal
│ └── tests
│ │ └── test_game_server.bal
│ ├── tic-tac-toe.gif
│ └── web-app
│ ├── .gitignore
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
│ └── src
│ ├── index.css
│ └── index.js
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── load-tests
└── chat_application
│ ├── deployment
│ ├── deployment-patch.yaml
│ ├── ingress.yaml
│ └── kustomization.yaml
│ ├── results
│ └── summary.csv
│ ├── scripts
│ ├── chat-app.jmx
│ ├── pre_run.sh
│ └── run.sh
│ └── src
│ ├── Ballerina.toml
│ ├── Cloud.toml
│ └── chat_server.bal
├── native
├── build.gradle
├── spotbugs-exclude.xml
└── src
│ ├── main
│ └── java
│ │ ├── io
│ │ └── ballerina
│ │ │ └── stdlib
│ │ │ └── websocket
│ │ │ ├── Handler.java
│ │ │ ├── HeaderParam.java
│ │ │ ├── ModuleUtils.java
│ │ │ ├── QueryParam.java
│ │ │ ├── ReturnStreamUnitCallBack.java
│ │ │ ├── WebSocketConnectorPortBindingListener.java
│ │ │ ├── WebSocketConstants.java
│ │ │ ├── WebSocketException.java
│ │ │ ├── WebSocketResourceCallback.java
│ │ │ ├── WebSocketResourceDispatcher.java
│ │ │ ├── WebSocketService.java
│ │ │ ├── WebSocketUtil.java
│ │ │ ├── actions
│ │ │ └── websocketconnector
│ │ │ │ ├── Close.java
│ │ │ │ ├── WebSocketConnector.java
│ │ │ │ ├── WebSocketSyncConnector.java
│ │ │ │ └── WriteTimeOutListener.java
│ │ │ ├── client
│ │ │ ├── RetryContext.java
│ │ │ ├── SyncInitEndpoint.java
│ │ │ └── listener
│ │ │ │ ├── RetryWebSocketClientHandshakeListener.java
│ │ │ │ ├── RetryWriteBinaryHandshakeListener.java
│ │ │ │ ├── RetryWriteTextHandshakeListener.java
│ │ │ │ ├── SyncClientConnectorListener.java
│ │ │ │ └── WebSocketHandshakeListener.java
│ │ │ ├── observability
│ │ │ ├── WebSocketMetricsUtil.java
│ │ │ ├── WebSocketObservabilityConstants.java
│ │ │ ├── WebSocketObservabilityUtil.java
│ │ │ ├── WebSocketObserverContext.java
│ │ │ └── WebSocketTracingUtil.java
│ │ │ ├── server
│ │ │ ├── OnUpgradeResourceCallback.java
│ │ │ ├── UpgradeListener.java
│ │ │ ├── WebSocketConnectionInfo.java
│ │ │ ├── WebSocketConnectionManager.java
│ │ │ ├── WebSocketDataElement.java
│ │ │ ├── WebSocketDataElementFactory.java
│ │ │ ├── WebSocketServerListener.java
│ │ │ ├── WebSocketServerService.java
│ │ │ └── WebSocketServicesRegistry.java
│ │ │ └── serviceendpoint
│ │ │ ├── AbstractWebsocketNativeFunction.java
│ │ │ ├── Detach.java
│ │ │ ├── GracefulStop.java
│ │ │ ├── InitEndpoint.java
│ │ │ ├── Register.java
│ │ │ └── Start.java
│ │ └── module-info.java
│ └── resources
│ └── META-INF
│ └── native-image
│ └── io.ballerina.stdlib
│ └── websocket-native
│ └── reflect-config.json
├── settings.gradle
└── test-utils
├── build.gradle
└── src
└── main
└── java
├── io
└── ballerina
│ └── stdlib
│ └── websocket
│ └── testutils
│ ├── WebSocketHttpRequestHandler.java
│ ├── WebSocketRemoteServer.java
│ ├── WebSocketRemoteServerFrameHandler.java
│ └── WebSocketRemoteServerInitializer.java
└── module-info.java
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Ensure all Java files use LF.
2 | *.java eol=lf
3 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # See: https://help.github.com/articles/about-codeowners/
5 |
6 | # These owners will be the default owners for everything in the repo.
7 | * @ThisaruGuruge @MohamedSabthar @shafreenAnfar
8 |
--------------------------------------------------------------------------------
/.github/issue_template.md:
--------------------------------------------------------------------------------
1 | **Description:**
2 |
3 |
4 | **Suggested Labels:**
5 |
6 |
7 | **Suggested Assignees:**
8 |
9 |
10 | **Affected Product Version:**
11 |
12 | **OS, DB, other environment details and versions:**
13 |
14 | **Steps to reproduce:**
15 |
16 |
17 | **Related Issues:**
18 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | ## Examples
4 |
5 | ## Checklist
6 | - [ ] Linked to an issue
7 | - [ ] Updated the specification
8 | - [ ] Updated the changelog
9 | - [ ] Added tests
10 | - [ ] Checked native-image compatibility
11 |
--------------------------------------------------------------------------------
/.github/workflows/build-timestamped-master.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | paths-ignore:
8 | - "*.md"
9 | - "docs/**"
10 | - "load-tests/**"
11 |
12 | workflow_dispatch:
13 |
14 | jobs:
15 | call_workflow:
16 | name: Run Build Workflow
17 | if: ${{ github.repository_owner == 'ballerina-platform' }}
18 | uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main
19 | secrets: inherit
20 |
--------------------------------------------------------------------------------
/.github/workflows/build-with-bal-test-graalvm.yml:
--------------------------------------------------------------------------------
1 | name: GraalVM Check
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | lang_tag:
7 | description: Branch/Release Tag of the Ballerina Lang
8 | required: true
9 | default: master
10 | lang_version:
11 | description: Ballerina Lang Version (If given ballerina lang buid will be skipped)
12 | required: false
13 | default: ''
14 | native_image_options:
15 | description: Default native-image options
16 | required: false
17 | default: ''
18 | schedule:
19 | - cron: '30 18 * * *'
20 | pull_request:
21 | branches:
22 | - main
23 | types: [ opened, synchronize, reopened, labeled, unlabeled ]
24 |
25 | concurrency:
26 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
27 | cancel-in-progress: true
28 |
29 | jobs:
30 | call_stdlib_workflow:
31 | name: Run StdLib Workflow
32 | if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
33 | uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
34 | with:
35 | lang_tag: ${{ inputs.lang_tag }}
36 | lang_version: ${{ inputs.lang_version }}
37 | native_image_options: ${{ inputs.native_image_options }}
38 | additional_ubuntu_build_flags: '-x :websocket-compiler-plugin-test:test'
39 | additional_windows_build_flags: '-x :websocket-compiler-plugin-test:test'
40 | java_tool_options: '-Dfile.encoding=UTF8'
41 |
--------------------------------------------------------------------------------
/.github/workflows/central-publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish to the Ballerina central
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | environment:
7 | type: choice
8 | description: Select Environment
9 | required: true
10 | options:
11 | - DEV CENTRAL
12 | - STAGE CENTRAL
13 |
14 | jobs:
15 | call_workflow:
16 | name: Run Central Publish Workflow
17 | if: ${{ github.repository_owner == 'ballerina-platform' }}
18 | uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main
19 | secrets: inherit
20 | with:
21 | environment: ${{ github.event.inputs.environment }}
22 |
--------------------------------------------------------------------------------
/.github/workflows/fossa_scan.yml:
--------------------------------------------------------------------------------
1 | name: Fossa Scan
2 | on:
3 | workflow_dispatch:
4 | schedule:
5 | - cron: '30 18 * * *' # 00:00 in LK time (GMT+5:30)
6 | jobs:
7 | fossa-scan:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v3
11 | - uses: fossas/fossa-action@main
12 | env:
13 | packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
14 | packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
15 | with:
16 | api-key: ${{secrets.FOSSA_APIKEY}}
17 |
--------------------------------------------------------------------------------
/.github/workflows/process-load-test-result.yml:
--------------------------------------------------------------------------------
1 | name: Process load test results
2 | on:
3 | repository_dispatch:
4 | types: [websocket-load-test]
5 |
6 | jobs:
7 | call_stdlib_process_load_test_results_workflow:
8 | name: Run StdLib Process Load Test Results Workflow
9 | uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@main
10 | with:
11 | results: ${{ toJson(github.event.client_payload.results) }}
12 | secrets:
13 | ballerina_bot_token: ${{ secrets.BALLERINA_BOT_TOKEN }}
14 | ballerina_reviewer_bot_token: ${{ secrets.BALLERINA_REVIEWER_BOT_TOKEN }}
15 |
--------------------------------------------------------------------------------
/.github/workflows/publish-release.yml:
--------------------------------------------------------------------------------
1 | name: Publish Release
2 |
3 | on:
4 | workflow_dispatch:
5 | repository_dispatch:
6 | types: [stdlib-release-pipeline]
7 |
8 | jobs:
9 | call_workflow:
10 | name: Run Release Workflow
11 | if: ${{ github.repository_owner == 'ballerina-platform' }}
12 | uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main
13 | secrets: inherit
14 | with:
15 | package-name: websocket
16 | package-org: ballerina
17 | additional-build-flags: "-x :websocket-examples:build"
18 |
--------------------------------------------------------------------------------
/.github/workflows/pull-request.yml:
--------------------------------------------------------------------------------
1 | name: PR Build
2 |
3 | concurrency:
4 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
5 | cancel-in-progress: true
6 |
7 | on: pull_request
8 |
9 | jobs:
10 | call_workflow:
11 | name: Run PR Build Workflow
12 | if: ${{ github.repository_owner == 'ballerina-platform' }}
13 | uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
14 | secrets: inherit
15 |
--------------------------------------------------------------------------------
/.github/workflows/trigger-load-tests.yml:
--------------------------------------------------------------------------------
1 | name: Trigger Load Tests
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | tests:
7 | description: >
8 | List of test names. This needs to be filled only if you want to run a specific set of tests. Example: foo,bar
9 | required: false
10 | clusterName:
11 | description: 'Cluster name'
12 | default: 'websocket-perf-cluster-test'
13 | required: false
14 | branch:
15 | description: 'Branch of the given repository'
16 | default: ''
17 | required: false
18 | schedule:
19 | - cron: '0 18 * * *'
20 |
21 | jobs:
22 | call_stdlib_trigger_load_test_workflow:
23 | name: Run StdLib Load Test Workflow
24 | if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
25 | uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main
26 | with:
27 | repo_name: 'module-ballerina-websocket'
28 | runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-websocket/actions/artifacts'
29 | dispatch_type: 'websocket-load-test'
30 | cluster_name: ${{ inputs.clusterName }}
31 | tests: ${{ inputs.tests }}
32 | branch: ${{ inputs.branch }}
33 | secrets:
34 | ballerina_bot_token: ${{ secrets.BALLERINA_BOT_TOKEN }}
35 |
--------------------------------------------------------------------------------
/.github/workflows/trivy-scan.yml:
--------------------------------------------------------------------------------
1 | name: Trivy
2 |
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: "30 20 * * *"
7 |
8 | jobs:
9 | call_workflow:
10 | name: Run Trivy Scan Workflow
11 | if: ${{ github.repository_owner == 'ballerina-platform' }}
12 | uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
13 | secrets: inherit
14 |
--------------------------------------------------------------------------------
/.github/workflows/update_spec.yml:
--------------------------------------------------------------------------------
1 | name: Update Specifications
2 |
3 | env:
4 | SPEC_FOLDER_PATH: 'docs/spec'
5 |
6 | on:
7 | workflow_dispatch:
8 | push:
9 | branches:
10 | - main
11 | paths:
12 | - 'docs/spec/**'
13 |
14 | jobs:
15 | update_specs:
16 | name: Update Specifications
17 | if: github.repository_owner == 'ballerina-platform'
18 | runs-on: ubuntu-latest
19 |
20 | steps:
21 | - name: Checkout Repository
22 | uses: actions/checkout@v3
23 |
24 | - name: Get current date
25 | id: date
26 | run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
27 |
28 | - name: Get Repo Name
29 | id: repo_name
30 | run: |
31 | MODULE=${{ github.event.repository.name }}
32 | echo "::set-output name=short_name::${MODULE##*-}"
33 |
34 | - name: Trigger Workflow
35 | run: |
36 | curl --request POST \
37 | 'https://api.github.com/repos/ballerina-platform/ballerina-dev-website/dispatches' \
38 | -H 'Accept: application/vnd.github.v3+json' \
39 | -H 'Authorization: Bearer ${{ secrets.BALLERINA_BOT_TOKEN }}' \
40 | --data "{
41 | \"event_type\": \"update-stdlib-specs\",
42 | \"client_payload\": {
43 | \"module_name\": \"${{ github.event.repository.name }}\",
44 | \"short_name\": \"${{ steps.repo_name.outputs.short_name }}\",
45 | \"file_dir\": \"${{ github.event.repository.name }}/${{ env.SPEC_FOLDER_PATH }}\",
46 | \"release_date\": \"${{ steps.date.outputs.date }}\"
47 | }
48 | }"
49 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | !gradle/wrapper/gradle-wrapper.jar
16 | *.war
17 | *.nar
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 |
26 | # Ignore Gradle project-specific cache directory
27 | .gradle
28 |
29 | # Ignore Gradle build output directory
30 | build
31 |
32 | target
33 | # IDEA Files
34 | .idea/
35 | *.iml
36 | *.ipr
37 | *.iws
38 |
39 | # MacOS
40 | *.DS_Store
41 |
42 | # Ballerina
43 | velocity.log*
44 | *Ballerina.lock
45 |
--------------------------------------------------------------------------------
/.trivyignore:
--------------------------------------------------------------------------------
1 | CVE-2025-25193
2 |
--------------------------------------------------------------------------------
/ballerina/CompilerPlugin.toml:
--------------------------------------------------------------------------------
1 | [plugin]
2 | id = "websocket-compiler-plugin"
3 | class = "io.ballerina.stdlib.websocket.plugin.WebSocketCompilerPlugin"
4 |
5 | [[dependency]]
6 | path = "../compiler-plugin/build/libs/websocket-compiler-plugin-2.15.0-SNAPSHOT.jar"
7 |
8 | [[dependency]]
9 | path = "../native/build/libs/websocket-native-2.15.0-SNAPSHOT.jar"
10 |
11 | [[dependency]]
12 | path = "./lib/http-native-2.14.0.jar"
13 |
--------------------------------------------------------------------------------
/ballerina/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/ballerina/icon.png
--------------------------------------------------------------------------------
/ballerina/init.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/jballerina.java;
18 |
19 | function init() {
20 | setModule();
21 | }
22 |
23 | function setModule() = @java:Method {
24 | 'class: "io.ballerina.stdlib.websocket.ModuleUtils"
25 | } external;
26 |
--------------------------------------------------------------------------------
/ballerina/tests/Config.toml:
--------------------------------------------------------------------------------
1 | [[ballerina.auth.users]]
2 | username="alice"
3 | password="xxx"
4 | scopes=["write", "update"]
5 |
6 | [[ballerina.auth.users]]
7 | username="bob"
8 | password="yyy"
9 | scopes=["read"]
10 |
11 | [[ballerina.auth.users]]
12 | username="eve"
13 | password="123"
14 |
--------------------------------------------------------------------------------
/ballerina/tests/certsAndKeys/ballerinaKeystore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/ballerina/tests/certsAndKeys/ballerinaKeystore.p12
--------------------------------------------------------------------------------
/ballerina/tests/certsAndKeys/ballerinaTruststore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/ballerina/tests/certsAndKeys/ballerinaTruststore.p12
--------------------------------------------------------------------------------
/ballerina/tests/certsAndKeys/private.key:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCpIL03xTlH6C3V
3 | e8ES8wjNBjXAnKt4GgSEiVYLPDYK1wngbEWT6wN7o2a5DS13QlWZMWS/8bwKez7f
4 | TBTspkuE1xGNM5OkdUCSPrNdiV+vPjPgn3La+dsUql+1iBqY5lcTcvN7+sCkDANV
5 | 1ApyMBpJz29Bx/bzXSi7bU2s7hGLI4d48n0XpNAxesHAWYLZO8KaPpbXe3FvB59r
6 | 87VBIRtWAtCMztdT9BcXbYGVKuvOvKeyV/yjd67b5GTexTpHGKPKiBGn2Yx7S5Mp
7 | T4sHbnZGpR+kOx06dU2Jxw9CL/qyMI8+EXHzWtgauQf0IS8Fy/Mt4ziYHA5+dwfU
8 | Hcem4ERjAgMBAAECggEATf9bRC0gjZj2Ck5YbHTIykTi5UFbkrfs/XKYy/WotrcV
9 | Rvqn29+2a36gEReSsD1XXJ7658qD/hF4nWJpA/ptOYY2AfiXTnEEpm1kKu7/wcHe
10 | Cul9/p7b+lvYZ8+s9HbGEaIhyDuMPBuOLjbr2l10wjV4Cc4+hV2hO07dU7M3RAMO
11 | aF7MDlPrk3ZSxz3uT1FyEbjn8rh2lbm3N35G2/6BaEAqOD4XPacbEzcR8map4ZE4
12 | 4CInDi4/uQGXMUPBRmKGtr45HzjJTBhqft2coAOsR0n0qxDc9LaCrK0iFnOOVz3l
13 | Grbdw3/+chet1zV76HZgUGqK4UVQUXU90tP6loQiAQKBgQDceAxtbHEpzAnoCsb+
14 | CG+Bk1Sg6xEmT7dfwW5PqgWlHzUzjMJuqcrh2UUWg144gAYnlRdA1HYKFNL1Qk27
15 | DT5VA+3H15m07RISMxQy4Zysbd9EGr7IUr9lQ7fzlfuVtZJspqgDuYqX/Bb+UWiO
16 | ZWPFstiOGhCIeY1ucKflSaKpkQKBgQDEYn9vGablFIS4Ht3SW3A5I9KRrLd2O8U6
17 | xu8eFV4pC477QHx9TMz6vuKUutuA9ZTNfEumZLZycA1eYDPZqx3SbJMbWexJ5PGf
18 | Hxcyw5Bc7iHpLqOzUPs7UkHwaTWS1kwKQpwLNRbXNVlDYI7+94cjQk0/MeFc5hof
19 | NyE0iW50swKBgQC/yKZ24ainRVkww39LKKdnPnSV7yZh/2JzJ97/6dUzSKyNBVt1
20 | zLoyMUDKTsi9uZChCi7KNIfiSS8iLuVTXDfm2J4WA9Uv8DKSJmDhyiTyUjmwEtv3
21 | gxP/0SLKAKR0HRkc7vSlGNgZUi/mV4buqABc0DFVnBLZxXNkqRdEfAPGIQKBgHpl
22 | oWMPK9Ou/CD9K+eFkeYrC3w7l4SbMAu4HSQ00SDn0U+LG4vEqCTHf9SOuWwgo4OG
23 | qmekcYnViJ9/ehF58vZJMU5ktz4+8NDpwb2j4X/p8zywEtsZ59tLI0nBaOCBq5bh
24 | ePwLNJcg6udxcO48O/+fvSFb50fNKg62f32NAki9AoGAJ71xzoCVzTspX+jFwXaX
25 | 3GYJVERAvTreZhGMMS5vlKvWGfpEfWXacCuPceH1SsHwZK68y1gfFYaQVSScF49I
26 | u1u1ZzkVQZQYkemRHGuM12/JY+jEfCvAWDKrSMfSVrly9qtUTU44Ti5MYmWsp9rD
27 | /OAKIOElPvQzS8DL/TtD1TQ=
28 | -----END PRIVATE KEY-----
29 |
--------------------------------------------------------------------------------
/ballerina/tests/certsAndKeys/public.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDsTCCApmgAwIBAgIUAcBP5M4LISxVgyGsnJohqmsCN/kwDQYJKoZIhvcNAQEL
3 | BQAwaDELMAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3Rlcm4xEDAOBgNVBAcMB0Nv
4 | bG9tYm8xDTALBgNVBAoMBHdzbzIxEjAQBgNVBAsMCWJhbGxlcmluYTESMBAGA1UE
5 | AwwJbG9jYWxob3N0MB4XDTE5MDgwNTA1MTMwNVoXDTI5MDgwMjA1MTMwNVowaDEL
6 | MAkGA1UEBhMCTEsxEDAOBgNVBAgMB1dlc3Rlcm4xEDAOBgNVBAcMB0NvbG9tYm8x
7 | DTALBgNVBAoMBHdzbzIxEjAQBgNVBAsMCWJhbGxlcmluYTESMBAGA1UEAwwJbG9j
8 | YWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqSC9N8U5R+gt
9 | 1XvBEvMIzQY1wJyreBoEhIlWCzw2CtcJ4GxFk+sDe6NmuQ0td0JVmTFkv/G8Cns+
10 | 30wU7KZLhNcRjTOTpHVAkj6zXYlfrz4z4J9y2vnbFKpftYgamOZXE3Lze/rApAwD
11 | VdQKcjAaSc9vQcf2810ou21NrO4RiyOHePJ9F6TQMXrBwFmC2TvCmj6W13txbwef
12 | a/O1QSEbVgLQjM7XU/QXF22BlSrrzrynslf8o3eu2+Rk3sU6RxijyogRp9mMe0uT
13 | KU+LB252RqUfpDsdOnVNiccPQi/6sjCPPhFx81rYGrkH9CEvBcvzLeM4mBwOfncH
14 | 1B3HpuBEYwIDAQABo1MwUTAdBgNVHQ4EFgQU8NRYN+9Cj1nCT/8/z69SdoosStQw
15 | HwYDVR0jBBgwFoAU8NRYN+9Cj1nCT/8/z69SdoosStQwDwYDVR0TAQH/BAUwAwEB
16 | /zANBgkqhkiG9w0BAQsFAAOCAQEAHuS1UwR8yrh7QdmZRPuX6BQWETXXEsto0bnp
17 | DD+c5u5WptUg/bYkAGsnkuHYv7TQcN163SXpnExg1QnMcdF+XuwCVtGpqZrmcosv
18 | ZPCf/CWoobBxsuiim5mY8zD3WwdzAO8kZheemiZM5FZYhaXkBymNNe7qvL/aC6Cu
19 | wyC3n+4GOtV+xabmH4T/p7HEcvq2SY0YGTpJ0OcUlvJ3UqzhTieK67dSFKmDN3hO
20 | BrxacFV9ybzub67erPkQpV4GpJUW9HShp0qXr6WuX1hg7WA6RgneWkq3y2h6sts/
21 | c5S/dAP8KlqghvEdv8lnAcSqjN3kSTim/JMMe4kChtjUE7C1Ag==
22 | -----END CERTIFICATE-----
23 |
--------------------------------------------------------------------------------
/ballerina/tests/client_init_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | service isolated class ClientPingPongCallBackService {
20 | *PingPongService;
21 | remote isolated function onPing(Client caller, byte[] localData) {
22 | }
23 |
24 | remote isolated function onPong(Client caller, byte[] localData) {
25 | }
26 | }
27 |
28 | @test:Config {}
29 | public function testErrorCallbackService() returns Error? {
30 | Error|Client wsClient = new("ws://localhost:21057/pingpong", config = {pingPongHandler : new ClientPingPongCallBackService()});
31 | if wsClient is Error {
32 | test:assertEquals("Error: The callback service should be a PingPongService", wsClient.message());
33 | } else {
34 | test:assertFail("Expected an error in call back service");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ballerina/tests/data_binding_with_enum.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | enum Point {
20 | A,
21 | B,
22 | C
23 | }
24 |
25 | service on new Listener(21400) {
26 | resource function get .() returns Service|Error {
27 | return new EnumService();
28 | }
29 | }
30 |
31 | service class EnumService {
32 | *Service;
33 |
34 | remote function onMessage(Caller caller, Point data) returns Error? {
35 | check caller->writeMessage(B);
36 | }
37 | }
38 |
39 | @test:Config {}
40 | public function testEnum() returns Error? {
41 | Client cl = check new("ws://localhost:21400");
42 | check cl->writeMessage(A);
43 | Point p = check cl->readMessage();
44 | test:assertEquals(p, B);
45 | }
46 |
--------------------------------------------------------------------------------
/ballerina/tests/invalid_base_path_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | service /echo on new Listener(9092) {
20 | resource function get .() returns Service|Error {
21 | return new WsService9092();
22 | }
23 | }
24 |
25 | service class WsService9092 {
26 | *Service;
27 | remote function onOpen() {
28 | }
29 | }
30 |
31 | @test:Config {}
32 | public function testServiceNotFound() returns Error? {
33 | Client|Error wsClient = new("ws://localhost:9092");
34 | if wsClient is Error {
35 | test:assertEquals(wsClient.message(), "InvalidHandshakeError: Invalid handshake response getStatus: 404 Not Found");
36 | } else {
37 | test:assertFail("Expected a service not found error");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ballerina/tests/malformed_url_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | // Tests the malformed url error in synchronous client
20 | @test:Config {}
21 | public function testMalformedUrl() returns Error? {
22 | Client|Error wsClient = new("xxx");
23 | if wsClient is Error {
24 | test:assertEquals(wsClient.message(), "Error: Malformed URL: xxx");
25 | } else {
26 | test:assertFail("Expected a malformed URL error");
27 | }
28 | }
29 |
30 | @test:Config {}
31 | public function testUrlWithIpAddress() returns Error? {
32 | Client|Error wsClient = new("127.0.0.1:9090/echo");
33 | if wsClient is Error {
34 | test:assertEquals(wsClient.message(), "Error: Illegal character in scheme name at index 0: 127.0.0.1:9090/echo");
35 | } else {
36 | test:assertFail("Expected an URL error");
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/ballerina/tests/on_binary_with_on_error.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 | import ballerina/io;
19 |
20 | listener Listener onErrorListener = new(21403);
21 |
22 | service on onErrorListener {
23 | resource function get .() returns Service|Error {
24 | return new ServiceWithOnError();
25 | }
26 | }
27 |
28 | service class ServiceWithOnError {
29 | *Service;
30 | remote function onError(Caller caller, error data) returns Error? {
31 | io:println(data);
32 | check caller->writeMessage({"event": "onError"});
33 | }
34 |
35 | remote function onMessage(Caller caller, int data) returns Error? {
36 | check caller->writeMessage({"event": "onMessage"});
37 | }
38 | }
39 |
40 | @test:Config {}
41 | public function testBindingFailureWithOnError() returns Error? {
42 | Client cl = check new("ws://localhost:21403");
43 | check cl->writeMessage("event".toBytes());
44 | json resp = check cl->readMessage();
45 | test:assertEquals(resp, {"event": "onError"});
46 | }
47 |
--------------------------------------------------------------------------------
/ballerina/tests/start_attach_detach_stop_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/io;
18 | import ballerina/test;
19 |
20 | listener Listener lis = new(21077);
21 |
22 | UpgradeService dummyService = service object {
23 | resource function get .() returns Service|UpgradeError {
24 | return new WsService70();
25 | }
26 | };
27 |
28 | service class WsService70 {
29 | *Service;
30 | remote function onTextMessage(Caller caller, string text) {
31 | io:println(text);
32 | }
33 | }
34 |
35 | @test:Config {}
36 | public function testAttachDetachGracefulStop() returns error? {
37 | check lis.attach(dummyService);
38 | check lis.'start();
39 | Client client1 = check new("ws://localhost:21077");
40 | check client1->writeTextMessage("Testing 123");
41 | check lis.detach(dummyService);
42 | check lis.gracefulStop();
43 |
44 | Client|Error client2 = new("ws://localhost:21077");
45 | if client2 is Error {
46 | test:assertEquals(client2.message(), "ConnectionError: IO Error");
47 | } else {
48 | test:assertFail("Expecting a connection error");
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ballerina/tests/sync_client_read_text_chunks_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/lang.runtime as runtime;
18 | import ballerina/test;
19 |
20 | string chunkTxtData = "";
21 |
22 | listener Listener l43 = new(21313);
23 |
24 | @ServiceConfig {
25 | maxFrameSize: 4
26 | }
27 | service /onTxtDataSync on l43 {
28 | resource function get .() returns Service|UpgradeError {
29 | return new WsService43();
30 | }
31 | }
32 |
33 | service class WsService43 {
34 | *Service;
35 | remote function onTextMessage(string data) returns string {
36 | return "chunked message";
37 | }
38 | }
39 |
40 | // Tests reading text data coming as continuation frames and aggragating them to a single text message.
41 | @test:Config {}
42 | public function testReadTextDataChunkSync() returns Error? {
43 | Client wsClient = check new("ws://localhost:21313/onTxtDataSync/");
44 | check wsClient->writeTextMessage("Hi");
45 | runtime:sleep(3);
46 | string resp = check wsClient->readTextMessage();
47 | test:assertEquals("chunked message", resp, msg = "Failed testReadTextDataChunkSync");
48 | error? result = wsClient->close(statusCode = 1000, reason = "Close the connection", timeout = 0);
49 | }
50 |
--------------------------------------------------------------------------------
/ballerina/tests/sync_client_send_binary_data_chunks_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/lang.runtime as runtime;
18 | import ballerina/test;
19 |
20 | byte[] BinSyncData = [];
21 |
22 | listener Listener l41 = new(21311);
23 |
24 | service /onBinaryDataSync on l41 {
25 | resource function get .() returns Service|UpgradeError {
26 | return new WsService41();
27 | }
28 | }
29 |
30 | service class WsService41 {
31 | *Service;
32 | remote function onBinaryMessage(Caller caller, byte[] data) returns Error? {
33 | BinSyncData = data;
34 | }
35 | }
36 |
37 | // Tests writing binary data as continuation frames chunked by the given maxFrameSize using the sync client.
38 | @test:Config {}
39 | public function testChunkBinaryDataSync() returns Error? {
40 | Client wsClient = check new("ws://localhost:21311/onBinaryDataSync/", config = {maxFrameSize: 1});
41 | byte[] binaryData = [5, 24, 56];
42 | check wsClient->writeBinaryMessage(binaryData);
43 | runtime:sleep(5);
44 | test:assertEquals(BinSyncData, binaryData, msg = "Failed testChunkBinaryDataSync");
45 | error? result = wsClient->close(statusCode = 1000, reason = "Close the connection", timeout = 0);
46 | }
47 |
--------------------------------------------------------------------------------
/ballerina/tests/test_data_binding_xml.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org).
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | final readonly & xml xmlMessage = xml `The Lost World`;
20 |
21 | service / on new Listener(22102) {
22 |
23 | resource function get .() returns Service|UpgradeError {
24 | return new WsService22102();
25 | }
26 | }
27 |
28 | service class WsService22102 {
29 | *Service;
30 |
31 | remote function onMessage(string message) returns xml {
32 | return xmlMessage;
33 | }
34 | }
35 |
36 | @test:Config {
37 | groups: ["xml"]
38 | }
39 | public function testReturningXml() returns error? {
40 | Client wsClient = check new ("ws://localhost:22102");
41 | check wsClient->writeMessage("Hello");
42 | xml response = check wsClient->readMessage();
43 | test:assertEquals(response, xmlMessage);
44 | }
45 |
--------------------------------------------------------------------------------
/ballerina/tests/test_dispatching_special_charachters.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | listener Listener l21104 = new(21104);
20 |
21 | service /on\-Text\-String on l21104 {
22 | resource function get abc\-d/pqr\-s() returns Service|UpgradeError {
23 | return new WsService21104();
24 | }
25 | }
26 |
27 | service class WsService21104 {
28 | *Service;
29 | remote isolated function onMessage(string data) returns string {
30 | return data;
31 | }
32 | }
33 |
34 | @test:Config {}
35 | public function testSpecialCharachter() returns Error? {
36 | Client wsClient = check new("ws://localhost:21104/on-Text-String/abc-d/pqr-s");
37 | check wsClient->writeMessage("Hi");
38 | string data = check wsClient->readMessage();
39 | test:assertEquals(data, "Hi");
40 | }
41 |
--------------------------------------------------------------------------------
/ballerina/tests/test_readMessage_after_connection_closure.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/io;
18 | import ballerina/test;
19 |
20 | service on new Listener(6090) {
21 | resource function get .() returns StreamingService {
22 | return new StreamingService();
23 | }
24 | }
25 |
26 | service class StreamingService {
27 | *Service;
28 |
29 | remote function onMessage(json message) returns error? {
30 | // ignore the data.
31 | }
32 |
33 | remote function onClose(Caller caller) returns error? {
34 | io:println(string `Connection ${caller.getConnectionId()} closed`);
35 | }
36 | }
37 |
38 | @test:Config {}
39 | public function testReadMessageAfterConnectionClosure() returns Error? {
40 | Client wsClient = check new ("ws://localhost:6090");
41 | json request = {'type: "start"};
42 | check wsClient->writeMessage(request);
43 | check wsClient->close();
44 | json|Error resp = wsClient->readMessage();
45 | if resp is Error {
46 | test:assertEquals(resp.message(), "Connection already closed");
47 | } else {
48 | test:assertFail("Expected a connection closure error");
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ballerina/tests/test_readonly_values.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/lang.runtime as runtime;
18 | import ballerina/test;
19 |
20 | listener Listener l77 = new(21012);
21 |
22 | service /onReadonlyBinary on l77 {
23 | resource function get .() returns Service|UpgradeError {
24 | return new WsService77();
25 | }
26 | }
27 |
28 | service class WsService77 {
29 | *Service;
30 | remote isolated function onBinaryMessage(Caller caller, readonly & byte[] data) returns byte[]? {
31 | return data;
32 | }
33 |
34 | remote isolated function onPing(Caller caller, readonly & byte[] data) returns byte[]? {
35 | return data;
36 | }
37 | }
38 |
39 | // Tests readonly support for onBinaryMessage
40 | @test:Config {}
41 | public function testReadonlyBinary() returns Error? {
42 | Client wsClient = check new("ws://localhost:21012/onReadonlyBinary/");
43 | byte[] bindata = [5, 24, 56];
44 | check wsClient->writeBinaryMessage(bindata);
45 | byte[] data = check wsClient->readBinaryMessage();
46 | check wsClient->ping(data);
47 | runtime:sleep(0.5);
48 | test:assertEquals(data, bindata);
49 | }
50 |
--------------------------------------------------------------------------------
/ballerina/tests/test_returning_error.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | listener Listener l74 = new(21074);
20 |
21 | service /onDispatchError on l74 {
22 | resource function get .() returns Service|UpgradeError {
23 | return new WsService74();
24 | }
25 | }
26 |
27 | service class WsService74 {
28 | *Service;
29 | remote function onTextMessage(Caller caller, string data) returns error? {
30 | return error("error returned");
31 | }
32 | }
33 |
34 | // Tests error returned from remote function.
35 | @test:Config {}
36 | public function testReturningError() returns Error? {
37 | Client wsClient = check new ("ws://localhost:21074/onDispatchError/");
38 | check wsClient->writeTextMessage("Hi");
39 | error? result = wsClient->close(statusCode = 1000, reason = "Close the connection", timeout = 0);
40 | }
41 |
--------------------------------------------------------------------------------
/ballerina/tests/test_upgrade_service_panic.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 |
19 | listener Listener l75 = new(21075);
20 |
21 | service /onPanic on l75 {
22 | resource function get .() returns Service|UpgradeError {
23 | if true {
24 | panic error("panic from the service");
25 | }
26 | }
27 | }
28 |
29 | service class WsService75 {
30 | *Service;
31 | remote function onTextMessage(Caller caller, string data) returns error? {
32 | return error("error returned");
33 | }
34 | }
35 |
36 | // Tests error panicked from get resource.
37 | @test:Config {}
38 | public function testPanicErrorFromUpgradeService() returns Error? {
39 | Client|Error wsClient = new ("ws://localhost:21075/onPanic/");
40 | test:assertTrue(wsClient is Error);
41 | if wsClient is Error {
42 | test:assertEquals(wsClient.message(), "InvalidHandshakeError: Invalid handshake response getStatus: "
43 | + "500 Internal Server Error");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ballerina/tests/websocket_pushText_failure.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | ////www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/lang.runtime as runtime;
18 | import ballerina/test;
19 |
20 | string errorMsg2 = "";
21 | listener Listener l20 = new(21008);
22 | service /pushTextFailureService on l20 {
23 | resource isolated function get .() returns Service|UpgradeError {
24 | return new PushTextFailureService();
25 | }
26 | }
27 |
28 | service class PushTextFailureService {
29 | *Service;
30 | remote function onOpen(Caller caller) {
31 | Error? err1 = caller->close(timeout = 0);
32 | Error? err = caller->writeTextMessage("hey");
33 | if err is Error {
34 | errorMsg2 = err.message();
35 | }
36 | }
37 | }
38 |
39 | // Checks for the log that is printed when writeTextMessage fails.
40 | @test:Config {}
41 | public function pushTextFailure() returns Error? {
42 | Client wsClient = check new("ws://localhost:21008/pushTextFailureService");
43 | runtime:sleep(0.5);
44 | test:assertEquals(errorMsg2, "ConnectionClosureError: Close frame already sent. Cannot push text data!",
45 | msg = "Data mismatched");
46 | }
47 |
--------------------------------------------------------------------------------
/ballerina/websocket_types.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | # The WebSocket service type.
18 | public type Service distinct service object {
19 | };
20 |
21 | # The WebSocket upgrade service type.
22 | public type UpgradeService distinct service object {
23 | };
24 |
25 | # The WebSocket service type to handle ping/pong frames.
26 | public type PingPongService distinct isolated service object {
27 | };
28 |
--------------------------------------------------------------------------------
/build-config/checkstyle/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | plugins {
19 | id "de.undercouch.download"
20 | id "java"
21 | }
22 |
23 | task downloadCheckstyleRuleFiles(type: Download) {
24 | src([
25 | 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.xml',
26 | 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.xml'
27 | ])
28 | overwrite false
29 | onlyIfNewer true
30 | dest buildDir
31 | }
32 |
33 | jar {
34 | enabled = false
35 | }
36 |
37 | clean {
38 | enabled = false
39 | }
40 |
41 | artifacts.add('default', file("$project.buildDir/checkstyle.xml")) {
42 | builtBy('downloadCheckstyleRuleFiles')
43 | }
44 |
45 | artifacts.add('default', file("$project.buildDir/suppressions.xml")) {
46 | builtBy('downloadCheckstyleRuleFiles')
47 | }
48 |
--------------------------------------------------------------------------------
/build-config/resources/CompilerPlugin.toml:
--------------------------------------------------------------------------------
1 | [plugin]
2 | id = "websocket-compiler-plugin"
3 | class = "io.ballerina.stdlib.websocket.plugin.WebSocketCompilerPlugin"
4 |
5 | [[dependency]]
6 | path = "../compiler-plugin/build/libs/websocket-compiler-plugin-@project.version@.jar"
7 |
8 | [[dependency]]
9 | path = "../native/build/libs/websocket-native-@project.version@.jar"
10 |
11 | [[dependency]]
12 | path = "./lib/http-native-@stdlib.httpnative.version@.jar"
13 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | ignore:
2 | - "test-utils"
3 | coverage:
4 | precision: 2
5 | round: down
6 | range: "60...80"
7 | status:
8 | project:
9 | default:
10 | target: 80
11 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_1"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_1/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | service /basic/ws on new websocket:Listener(9090) {
4 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
5 | return new WsService();
6 | }
7 |
8 | resource isolated function get y() returns websocket:Service|websocket:UpgradeError {
9 | return new WsService();
10 | }
11 | }
12 |
13 | service isolated class WsService {
14 | *websocket:Service;
15 | remote function onOpen(websocket:Caller caller) {
16 | }
17 |
18 | remote function onTextMessage(websocket:Caller caller, string text) {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_10/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_10"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_10/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|int {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onOpen(websocket:Caller caller) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_11/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_11"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_11/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|string {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen(ws:Caller caller) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_12/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_12"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_12/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|ws:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen(ws:Caller caller) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_13/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_13"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_13/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|ws:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen(ws:Caller caller) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_14/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_14"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_14/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|ws:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen() {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_15/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_15"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_15/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|ws:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen(ws:Client caller) {
14 | }
15 |
16 | remote function onClose(ws:Client caller, string message, int status) returns string {
17 | return "hello";
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_16/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_16"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_16/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|ws:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen(ws:Caller caller, string xyz) {
14 | }
15 |
16 | remote function onClose(ws:Caller caller, string message, int status) {
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_17/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_16"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_17/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket as ws;
2 |
3 | listener ws:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns ws:Service|ws:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *ws:Service;
13 | remote function onOpen(ws:Caller caller) returns ws:Error? {
14 | return ();
15 | }
16 |
17 | remote function onClose(string message, int status) returns ws:Error? {
18 | return ();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_18/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_18"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_18/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onOpen(websocket:Caller caller) returns string {
14 | return "Hello";
15 | }
16 |
17 | remote function onClose(websocket:Caller caller, string message, int status, int status2) {
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_19/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_19"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_19/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onOpen(websocket:Caller caller) returns error? {
14 | return ();
15 | }
16 |
17 | remote function onIdleTimeout(websocket:Caller caller) returns int {
18 | return 5;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_2"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_2/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 | import ballerina/io;
4 |
5 | websocket:ListenerConfiguration conf = {
6 | secureSocket: {
7 | key: {
8 | path: "tests/certsAndKeys/ballerinaKeystore.p12",
9 | password: "ballerina"
10 | }
11 | }
12 | };
13 |
14 | @websocket:ServiceConfig {
15 | subProtocols: ["xml", "json"],
16 | idleTimeout: 120
17 | }
18 | service /basic/ws on new websocket:Listener(9090, conf) {
19 | resource function get [string name](http:Request req) returns
20 | websocket:Service|websocket:UpgradeError {
21 | lock {
22 | self.testFunc();
23 | return new WsService();
24 | }
25 | }
26 |
27 | isolated function testFunc() {
28 | io:println("Invoked the function");
29 | }
30 | }
31 | service isolated class WsService {
32 | *websocket:Service;
33 | remote function onOpen(websocket:Caller caller) {
34 | }
35 |
36 | remote function onTextMessage(string text) returns byte[]? {
37 | return ();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_20/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_20"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_20/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onError(websocket:Caller caller, websocket:Error err) returns string {
14 | return "error";
15 | }
16 |
17 | remote function onIdleTimeout(websocket:Caller caller) {
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_21/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_21"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_21/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onError(websocket:Caller caller) returns websocket:Error? {
14 | return ();
15 | }
16 |
17 | remote function onIdleTimeout(websocket:Client caller) {
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_22/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_22"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_22/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onError(websocket:Caller caller, string 'err) returns error? {
14 | return ();
15 | }
16 |
17 | remote function onIdleTimeout(websocket:Caller caller, string text) {
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_23/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_23"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_23/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onTextMessage(websocket:Caller caller) returns string|int? {
15 | return "hello";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_24/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_24"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_24/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener hl = check new(21001);
20 |
21 | service /basic/ws on hl {
22 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
23 | return new WsService();
24 | }
25 | }
26 |
27 | service isolated class WsService {
28 | *websocket:Service;
29 |
30 | remote function onTextMessage(websocket:Caller caller, int status) returns byte[]? {
31 | return "hello".toBytes();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_25/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_24"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_25/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws1 on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onBinaryMessage(websocket:Caller caller) returns byte[]? {
15 | return "hello".toBytes();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_26/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_26"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_26/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onBinaryMessage(websocket:Caller caller, int status) returns byte[]|string|int? {
15 | return "hello".toBytes();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_27/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_27"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_27/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onBinaryMessage(websocket:Caller caller, byte[] data) returns byte[]? {
15 | return "hello".toBytes();
16 | }
17 |
18 | resource isolated function get abc() returns string {
19 | return "Hello";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_28/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_28"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_28/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onOpen(websocket:Caller caller, string xyz) returns websocket:Error? {
15 | return ();
16 | }
17 |
18 | remote function onBinaryMessage(websocket:Caller caller, byte[] data) returns byte[]? {
19 | return "hello".toBytes();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_29/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_29"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_29/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onOpen(websocket:Caller caller) returns int {
15 | return 5;
16 | }
17 |
18 | remote function onClose(websocket:Caller caller, string message, int status) {
19 | }
20 |
21 | remote function onError(error err) returns error? {
22 | return ();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_3/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_3"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_3/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/io;
3 |
4 | service /basic/ws on new websocket:Listener(9090, {
5 | secureSocket: {
6 | key: {
7 | path: "tests/certsAndKeys/ballerinaKeystore.p12",
8 | password: "ballerina"
9 | }
10 | }
11 | }) {
12 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
13 | io:println("Invoked the function");
14 | return new WsService();
15 | }
16 | }
17 | service isolated class WsService {
18 | *websocket:Service;
19 | remote function onOpen(websocket:Caller caller) {
20 | }
21 |
22 | remote function onTextMessage(websocket:Caller caller, string text) returns byte[] {
23 | self.testFunc();
24 | return "hello".toBytes();
25 | }
26 |
27 | isolated function testFunc() {
28 | io:println("Invoked the function");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_30/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_30"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_30/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/io;
3 |
4 | listener websocket:Listener hl = check new(21001);
5 |
6 | service /basic/ws on hl {
7 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
8 | lock {
9 | self.testFunc();
10 | return new WsService();
11 | }
12 | }
13 |
14 | isolated function testFunc() {
15 | io:println("Invoked the function");
16 | }
17 | }
18 |
19 | service isolated class WsService {
20 | *websocket:Service;
21 |
22 | remote function onClose(websocket:Caller caller, string message, int status, int status2) {
23 | }
24 |
25 | remote function onIdleTimeout() {
26 | }
27 |
28 | remote function onError(websocket:Caller caller, websocket:Error err) returns string {
29 | return "error";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_31/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_31"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_31/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onError(websocket:Caller caller) returns websocket:Error? {
15 | return ();
16 | }
17 |
18 | remote function onIdleTimeout(websocket:Client caller) {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_32/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_32"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_32/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onError(websocket:Caller caller) returns websocket:Error? {
15 | return ();
16 | }
17 |
18 | remote function onIdleTimeout(websocket:Client caller) returns string {
19 | return "text";
20 | }
21 |
22 | remote function onTextMessage(websocket:Caller caller, int status) returns websocket:Error? {
23 | return ();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_33/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_32"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_33/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 |
14 | remote function onTextMessage(websocket:Caller caller)
15 | returns string|int? {
16 | return "hello";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_34/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_34"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_34/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 | import ballerina/io;
4 |
5 | http:ListenerConfiguration httpConf = {
6 | secureSocket: {
7 | key: {
8 | path: "tests/certsAndKeys/ballerinaKeystore.p12",
9 | password: "ballerina"
10 | }
11 | }
12 | };
13 |
14 | listener http:Listener hl = new(21001, httpConf);
15 |
16 | websocket:ListenerConfiguration conf = {
17 | secureSocket: {
18 | key: {
19 | path: "tests/certsAndKeys/ballerinaKeystore.p12",
20 | password: "ballerina"
21 | }
22 | }
23 | };
24 | listener websocket:Listener socketListener = new(hl, conf);
25 |
26 | service /basic/ws on socketListener {
27 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
28 | io:println("hello");
29 | return new WsService();
30 | }
31 | }
32 |
33 | service isolated class WsService {
34 | *websocket:Service;
35 | remote function onOpen(websocket:Caller caller) {
36 | }
37 |
38 | remote function onTextMessage(websocket:Caller caller, string text) returns error? {
39 | return ();
40 | }
41 | }
42 |
43 | service /helloWorld on hl {
44 | resource function get hello(http:Caller caller, http:Request req) returns error? {
45 | return caller->respond("Hello World!");
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_35/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_35"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_35/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 |
4 | websocket:ListenerConfiguration conf = {
5 | secureSocket: {
6 | key: {
7 | path: "tests/certsAndKeys/ballerinaKeystore.p12",
8 | password: "ballerina"
9 | }
10 | }
11 | };
12 | service /basic/ws on new websocket:Listener(9090, conf){
13 | resource function get [string name](http:Request req) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_36/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_36"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_36/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/http;
2 | import ballerina/websocket;
3 |
4 | listener websocket:Listener securedEP = new(9090,
5 | secureSocket = {
6 | key: {
7 | certFile: "../resources/public.crt",
8 | keyFile: "../resources/private.key"
9 | }
10 | }
11 | );
12 |
13 | service /foo on securedEP {
14 | resource function get bar(http:Request req) returns websocket:Service|websocket:AuthError {
15 | return new WsService();
16 | }
17 | }
18 |
19 | service isolated class WsService {
20 | *websocket:Service;
21 | remote function onTextMessage(websocket:Caller caller, string text) returns websocket:Error? {
22 | return caller->writeTextMessage(text);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_37/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_37"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_37/on_open.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_37/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | service /foo on new websocket:Listener(9090) {}
4 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_37/service2.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | service /foo on new websocket:Listener(9090) {
4 | int x = 5;
5 | string y = "xx";
6 | }
7 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_38/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_38"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_38/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/http;
2 | import ballerina/websocket;
3 |
4 | listener websocket:Listener securedEP = new(9090);
5 |
6 | service /foo on securedEP {
7 | resource function get bar(http:Request req) returns websocket:Service|websocket:AuthError {
8 | return new WsService();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_39/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_38"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_39/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/http;
2 | import ballerina/websocket;
3 | import ballerina/io;
4 |
5 | listener websocket:Listener securedEP = new(9090);
6 |
7 | service /foo on securedEP {
8 | resource function get bar(http:Request req) returns websocket:Service|websocket:AuthError {
9 | return new WsService();
10 | }
11 | }
12 |
13 | service class WsService {
14 | *websocket:Service;
15 | remote isolated function onBinaryMessage(websocket:Caller caller,
16 | byte[] text) returns websocket:Error? {
17 | io:println(text);
18 | return caller->writeBinaryMessage(text);
19 | }
20 |
21 | remote function onPing(websocket:Caller caller, byte[] data) returns error? {
22 | io:println(string `Ping received with data: ${data.toBase64()}`);
23 | check caller->pong(data);
24 | }
25 |
26 | remote function onPong(websocket:Caller caller, byte[] data) {
27 | io:println(string `Pong received with data: ${data.toBase64()}`);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_4/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_4"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_4/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 |
4 | service /basic/ws on new websocket:Listener(9090) {
5 | resource isolated function get .(http:Request req, http:Caller caller) returns websocket:Service|websocket:UpgradeError {
6 | return new WsService();
7 | }
8 | }
9 | service isolated class WsService {
10 | *websocket:Service;
11 | remote function onOpen(websocket:Caller caller) {
12 | }
13 |
14 | remote function onTextMessage(websocket:Caller caller, string text) {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_40/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_40"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_40/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | service /basic/ws on new websocket:Listener(9090) {
4 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
5 | return new WsService();
6 | }
7 | }
8 |
9 | service isolated class WsService {
10 | *websocket:Service;
11 |
12 | remote function onBinaryMessage(readonly & websocket:Caller caller, readonly & byte[] data) {
13 | }
14 |
15 | remote function onPing(websocket:Caller caller, readonly & byte[] data) {
16 | }
17 |
18 | remote function onPong(websocket:Caller caller, readonly & byte[] data) {
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_41/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_41"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_41/service2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /shuttle on new websocket:Listener(9094) {
20 | resource function get . () returns websocket:Service|websocket:Error {
21 | return new MyService();
22 | }
23 | }
24 |
25 | service class MyService {
26 | *websocket:Service;
27 |
28 | public function init() returns websocket:Error? {
29 | }
30 |
31 | remote function onOpen(websocket:Caller caller) {
32 | }
33 |
34 | remote function onTextMessage(websocket:Caller caller, string s) returns error? {
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_41/service3.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service class ShuttleService {
20 | *websocket:Service;
21 | int i;
22 |
23 | function init() { // no qualifier
24 | self.i = 0;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_42/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_42"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_42/service2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 | import ballerina/io;
19 |
20 | service /shuttle on new websocket:Listener(9094) {
21 | function init() {
22 | io:println("this should print first");
23 | }
24 | resource function get . () returns websocket:Service|websocket:Error {
25 | return new MyService();
26 | }
27 | }
28 |
29 | service class MyService {
30 | *websocket:Service;
31 |
32 | public function init() returns websocket:Error? {
33 | }
34 |
35 | remote function onOpen(websocket:Caller caller) {
36 | }
37 |
38 | remote function onTextMessage(websocket:Caller caller, string s) returns error? {
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_43/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_43"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_43/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | public type Coord record {
20 | int x;
21 | int y;
22 | };
23 |
24 | service /basic/ws on new websocket:Listener(9090) {
25 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
26 | return new WsService2();
27 | }
28 | }
29 |
30 | service isolated class WsService2 {
31 | *websocket:Service;
32 |
33 | remote function onTextMessage(websocket:Caller caller, readonly & Coord data) {
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_43/service2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService1();
22 | }
23 | }
24 |
25 | service isolated class WsService1 {
26 | *websocket:Service;
27 |
28 | remote function onTextMessage(websocket:Caller caller, readonly & json data) {
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_44"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service isolated class WsService {
26 | *websocket:Service;
27 |
28 | remote function onMessage(websocket:Caller caller, xml data) returns xml {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service10.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService10();
22 | }
23 | }
24 |
25 | service isolated class WsService10 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(readonly & int data) returns int? {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService1();
22 | }
23 | }
24 |
25 | service isolated class WsService1 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(json data) returns json {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service3.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | public type Coord record {
20 | int x;
21 | int y;
22 | };
23 |
24 | service /basic/ws on new websocket:Listener(9090) {
25 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
26 | return new WsService2();
27 | }
28 | }
29 |
30 | service isolated class WsService2 {
31 | *websocket:Service;
32 |
33 | remote function onMessage(Coord data) returns Coord {
34 | return data;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service4.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService3();
22 | }
23 | }
24 |
25 | service isolated class WsService3 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(Coord[] data) returns Coord[] {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service5.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService5();
22 | }
23 | }
24 |
25 | service isolated class WsService5 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(int data) returns int? {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service6.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService6();
22 | }
23 | }
24 |
25 | service isolated class WsService6 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(float data) returns float? {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service7.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService7();
22 | }
23 | }
24 |
25 | service isolated class WsService7 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(boolean data) returns boolean {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service8.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService8();
22 | }
23 | }
24 |
25 | service isolated class WsService8 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(readonly & json data) returns json {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_44/service9.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService9();
22 | }
23 | }
24 |
25 | service isolated class WsService9 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(readonly & Coord data) returns Coord {
29 | return data;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_45/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_45"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_45/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener hl = check new(21001);
20 |
21 | service /basic/ws on hl {
22 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
23 | return new WsService();
24 | }
25 | }
26 |
27 | service isolated class WsService {
28 | *websocket:Service;
29 |
30 | remote function onMessage(websocket:Caller caller, anydata data) returns websocket:Error? {
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_45/service2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on hl {
20 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService1();
22 | }
23 | }
24 |
25 | service isolated class WsService1 {
26 | *websocket:Service;
27 |
28 | remote function onMessage(anydata data) returns websocket:Error? {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_46/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_46"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_46/on_close.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_47/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_47"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_47/on_binary.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_48/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_48"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_48/on_text.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_49/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_49"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_49/on_message.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_5/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_5"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_5/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 |
4 | service /basic/ws on new websocket:Listener(9090) {
5 | resource isolated function get .(http:Caller caller) returns websocket:Service|websocket:UpgradeError {
6 | return new WsService();
7 | }
8 | }
9 | service isolated class WsService {
10 | remote function onOpen(websocket:Caller caller) {
11 | }
12 |
13 | remote function onTextMessage(websocket:Caller caller, string text) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_50/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_50"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_50/on_ping.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_51/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_51"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_51/on_pong.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_52/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_52"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_52/on_error.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_53/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_52"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_53/on_idletimeout.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_54/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_54"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_54/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onTextMessage(websocket:Caller caller, string data) {
29 | }
30 |
31 | remote function onMessage(readonly & websocket:Caller caller, string data) {
32 | }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_54/server2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service /basic/ws on new websocket:Listener(9090) {
20 | resource function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService1();
22 | }
23 | }
24 |
25 | service class WsService1 {
26 | *websocket:Service;
27 |
28 | remote function onBinaryMessage(websocket:Caller caller, byte[] data) {
29 | }
30 |
31 | remote function onMessage(readonly & websocket:Caller caller, byte[] data) {
32 | }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_55/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_55"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_55/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener = new(8080);
20 | service / on localListener {
21 | resource function get .() returns websocket:Service|websocket:Error {
22 | return new WsService();
23 | }
24 | }
25 |
26 | service class WsService {
27 | *websocket:Service;
28 |
29 | remote function onMessage(websocket:Caller caller, Ping|Subscribe|Unsubscribe message) returns websocket:Error? {
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_56/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_56"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_56/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener = new(8080);
20 | service / on localListener {
21 | resource function get .() returns websocket:Service|error {
22 | return new WsService();
23 | }
24 | }
25 |
26 | service class WsService {
27 | *websocket:Service;
28 |
29 | remote isolated function onOpen(websocket:Caller caller) returns stream|error {
30 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
31 | return greets.toStream();
32 | }
33 |
34 | remote isolated function onMessage(json data) returns stream|error {
35 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
36 | return greets.toStream();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_57/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_57"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_57/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener = new(8080);
20 |
21 | @websocket:ServiceConfig {dispatcherKey: "type"}
22 | service / on localListener {
23 | resource function get .() returns websocket:Service|error {
24 | return new WsService();
25 | }
26 | }
27 |
28 | service class WsService {
29 | *websocket:Service;
30 |
31 | remote isolated function onOpen123(websocket:Caller caller) returns stream|error {
32 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
33 | return greets.toStream();
34 | }
35 |
36 | remote isolated function onMessagexxx(json data) returns stream|error {
37 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
38 | return greets.toStream();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_58/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_58"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_58/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener = new(8080);
20 |
21 | @websocket:ServiceConfig {dispatcherKey: "type"}
22 | service / on localListener {
23 | resource function get .() returns websocket:Service|error {
24 | return new WsService();
25 | }
26 | }
27 |
28 | service class WsService {
29 | *websocket:Service;
30 |
31 | remote isolated function onOpen123(websocket:Caller caller) returns stream|int|error {
32 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
33 | return greets.toStream();
34 | }
35 |
36 | remote isolated function onMessagexxx(json data) returns stream|string|error {
37 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
38 | return greets.toStream();
39 | }
40 |
41 | remote isolated function onMessage(json data) returns stream|float|error {
42 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
43 | return greets.toStream();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_58/server2.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener2 = new(8081);
20 |
21 | @websocket:ServiceConfig {dispatcherKey: "type"}
22 | service / on localListener2 {
23 | resource function get .() returns websocket:Service|error {
24 | return new WsService2();
25 | }
26 | }
27 |
28 | service class WsService2 {
29 | *websocket:Service;
30 |
31 | remote isolated function onMessagexxx(json data) returns stream|string|error {
32 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
33 | return greets.toStream();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_58/server3.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener3 = new(8083);
20 |
21 | @websocket:ServiceConfig {dispatcherKey: "type"}
22 | service / on localListener3 {
23 | resource function get .() returns websocket:Service|error {
24 | return new WsService3();
25 | }
26 | }
27 |
28 | service class WsService3 {
29 | *websocket:Service;
30 |
31 | remote isolated function onMessagexxx(json data) returns stream|stream|error {
32 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
33 | return greets.toStream();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_58/server4.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener localListener4 = new(8083);
20 |
21 | @websocket:ServiceConfig {dispatcherKey: "type"}
22 | service / on localListener4 {
23 | resource function get .() returns websocket:Service|error {
24 | return new WsService4();
25 | }
26 | }
27 |
28 | service class WsService4 {
29 | *websocket:Service;
30 |
31 | remote isolated function onMessage(json data) returns stream|stream|error {
32 | string[] greets = ["Hi Sam", "Hey Sam", "GM Sam"];
33 | return greets.toStream();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_59/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_59"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_59/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023 WSO2 LLC. (www.wso2.com) All Rights Reserved.
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | type ErrorMessage record {
20 | string message;
21 | int code;
22 | };
23 |
24 | service /onStream on new websocket:Listener(9090) {
25 | resource function get .() returns websocket:Service|websocket:UpgradeError {
26 | return new StreamStringSvc();
27 | }
28 | }
29 |
30 | service class StreamStringSvc {
31 | *websocket:Service;
32 | isolated remote function onSubscribeMesssage(string data) returns stream {
33 | return [].toStream();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_6/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_6"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_6/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 |
4 | listener http:Listener hl = check new(21001);
5 | listener websocket:Listener socketListener = new(<@untainted> hl);
6 |
7 | service /basic/ws on socketListener {
8 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
9 | return new WsService();
10 | }
11 | }
12 |
13 | service isolated class WsService {
14 | *websocket:Service;
15 | remote function onOpen(websocket:Caller caller) {
16 | }
17 |
18 | remote function onTextMessage(websocket:Caller caller, string text) returns error? {
19 | return ();
20 | }
21 | }
22 |
23 | service /helloWorld on hl {
24 | resource function get hello(http:Caller caller, http:Request req) returns error? {
25 | return caller->respond("Hello World!");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_60/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_60"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_60/server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 WSO2 LLC. (www.wso2.com).
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | type ErrorMessage record {
20 | string message;
21 | int code;
22 | };
23 |
24 | @websocket:ServiceConfig {
25 | dispatcherStreamId: "streamId"
26 | }
27 | service /onStream on new websocket:Listener(9090) {
28 | resource function get .() returns websocket:Service|websocket:UpgradeError {
29 | return new StreamStringSvc();
30 | }
31 | }
32 |
33 | service class StreamStringSvc {
34 | *websocket:Service;
35 | remote function onSubscribeMesssage(string data) returns stream {
36 | return [].toStream();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_61/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_61"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_61/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org).
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | listener websocket:Listener l1 = check new (9090);
20 |
21 | service /ws1 on l1 {
22 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
23 | return new WsService1();
24 | }
25 | }
26 |
27 | service /ws2 on l1 {
28 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
29 | return new WsService2();
30 | }
31 | }
32 |
33 | service isolated class WsService1 {
34 | *websocket:Service;
35 |
36 | remote function onError(error err) returns websocket:CloseFrame {
37 | return websocket:NORMAL_CLOSURE;
38 | }
39 | }
40 |
41 | service isolated class WsService2 {
42 | *websocket:Service;
43 |
44 | remote function onError(error err) returns error|websocket:NormalClosure {
45 | return websocket:NORMAL_CLOSURE;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_62/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_62"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_62/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org).
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service / on new websocket:Listener(9090) {
20 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service isolated class WsService {
26 | *websocket:Service;
27 |
28 | remote function onMessage(string err) returns stream|websocket:CloseFrame {
29 | return websocket:NORMAL_CLOSURE;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_63/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_63"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_64/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_64"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_64/service.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
2 | //
3 | // WSO2 LLC. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | @websocket:ServiceConfig {
20 | connectionClosureTimeout: -5
21 | }
22 | service / on new websocket:Listener(9090) {
23 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
24 | return new WsService();
25 | }
26 | }
27 |
28 | service isolated class WsService {
29 | *websocket:Service;
30 | }
31 |
32 | // We ignore the compiler validation for below services since value is provided via a variable
33 | decimal connectionClosureTimeout = 5.0;
34 |
35 | @websocket:ServiceConfig {
36 | connectionClosureTimeout: connectionClosureTimeout
37 | }
38 | service / on new websocket:Listener(9090) {
39 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
40 | return new WsService();
41 | }
42 | }
43 |
44 | @websocket:ServiceConfig {
45 | connectionClosureTimeout
46 | }
47 | service / on new websocket:Listener(9090) {
48 | resource isolated function get .() returns websocket:Service|websocket:UpgradeError {
49 | return new WsService();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_7/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_7"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_7/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function post .() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onOpen(websocket:Caller caller) {
14 | }
15 |
16 | remote function onTextMessage(websocket:Caller caller, string text) returns websocket:Error? {
17 | return ();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_8/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_8"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_8/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 | import ballerina/http;
3 |
4 | listener http:Listener hl = check new(21001);
5 | listener websocket:Listener socketListener = new(<@untainted> hl, {
6 | secureSocket: {
7 | key: {
8 | path: "tests/certsAndKeys/ballerinaKeystore.p12",
9 | password: "ballerina"
10 | }
11 | }
12 | });
13 |
14 | service /basic/ws on socketListener {
15 | remote isolated function get() returns websocket:Service|websocket:UpgradeError {
16 | return new WsService();
17 | }
18 | }
19 |
20 | service isolated class WsService {
21 | *websocket:Service;
22 | remote function onOpen(websocket:Caller caller) {
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_9/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "websocket_test"
3 | name = "sample_9"
4 | version = "0.1.0"
5 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_9/service.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | listener websocket:Listener hl = check new(21001);
4 |
5 | service /basic/ws on hl {
6 | resource isolated function get abc() returns websocket:Service|websocket:UpgradeError {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service isolated class WsService {
12 | *websocket:Service;
13 | remote function onOpen(websocket:Caller caller) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_binary.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onBinaryMessage(websocket:Caller caller, byte[] data) returns websocket:Error? {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_close.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onClose(websocket:Caller caller, int statusCode, string reason) {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_error.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onError(websocket:Caller caller, websocket:Error err) returns websocket:Error? {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_idletimeout.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onIdleTimeout(websocket:Caller caller) {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_message.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onMessage(websocket:Caller caller, string data) returns websocket:Error? {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_open.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onOpen(websocket:Caller caller) returns websocket:Error? {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_ping.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onPing(websocket:Caller caller, byte[] data) {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_pong.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onPong(websocket:Caller caller, byte[] data) {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/on_text.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (//www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // //www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/websocket;
18 |
19 | service on new websocket:Listener(0) {
20 | resource function get .() returns websocket:Service|websocket:Error {
21 | return new WsService();
22 | }
23 | }
24 |
25 | service class WsService {
26 | *websocket:Service;
27 |
28 | remote function onTextMessage(websocket:Caller caller, string text) returns websocket:Error? {
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/result.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | service /foo on new websocket:Listener(9090) {
4 | resource function get .() returns websocket:Service|websocket:Error {
5 | return new WsService();
6 | }
7 | }
8 |
9 | service class WsService {
10 | *websocket:Service;
11 |
12 | remote function onMessage(websocket:Caller caller, anydata data) returns websocket:Error? {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/codeaction/code_snippet_generation/result2.bal:
--------------------------------------------------------------------------------
1 | import ballerina/websocket;
2 |
3 | service /foo on new websocket:Listener(9090) {
4 | int x = 5;
5 | string y = "xx";
6 | resource function get .() returns websocket:Service|websocket:Error {
7 | return new WsService();
8 | }
9 | }
10 |
11 | service class WsService {
12 | *websocket:Service;
13 |
14 | remote function onMessage(websocket:Caller caller, anydata data) returns websocket:Error? {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/compiler-plugin-tests/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/compiler-plugin/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/io/ballerina/stdlib/websocket/plugin/ReturnStatementNodeVisitor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.websocket.plugin;
19 |
20 | import io.ballerina.compiler.syntax.tree.NodeVisitor;
21 | import io.ballerina.compiler.syntax.tree.ReturnStatementNode;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | /**
27 | * A class for visiting return statements.
28 | */
29 | public class ReturnStatementNodeVisitor extends NodeVisitor {
30 | private List returnStatementNodes = new ArrayList<>();
31 |
32 | @Override
33 | public void visit(ReturnStatementNode returnStatementNode) {
34 | returnStatementNodes.add(returnStatementNode);
35 | }
36 |
37 | public List getReturnStatementNodes() {
38 | return returnStatementNodes;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/io/ballerina/stdlib/websocket/plugin/WebSocketServiceAnalyzer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.websocket.plugin;
19 |
20 | import io.ballerina.compiler.syntax.tree.SyntaxKind;
21 | import io.ballerina.projects.plugins.CodeAnalysisContext;
22 | import io.ballerina.projects.plugins.CodeAnalyzer;
23 |
24 | /**
25 | * The {@code CodeAnalyzer} for Ballerina WebSocket services.
26 | */
27 | public class WebSocketServiceAnalyzer extends CodeAnalyzer {
28 | @Override
29 | public void init(CodeAnalysisContext codeAnalysisContext) {
30 | codeAnalysisContext
31 | .addSyntaxNodeAnalysisTask(new WebSocketUpgradeServiceValidatorTask(), SyntaxKind.SERVICE_DECLARATION);
32 | codeAnalysisContext
33 | .addSyntaxNodeAnalysisTask(new WebSocketServiceValidatorTask(), SyntaxKind.CLASS_DEFINITION);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler-plugin/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | module io.ballerina.stdlib.websocket.plugin {
20 | requires io.ballerina.lang;
21 | requires io.ballerina.parser;
22 | requires io.ballerina.tools.api;
23 | requires io.ballerina.stdlib.websocket;
24 | exports io.ballerina.stdlib.websocket.plugin;
25 | }
26 |
--------------------------------------------------------------------------------
/examples/_resources/Dependencies.toml:
--------------------------------------------------------------------------------
1 | [[dependency]]
2 | org = "ballerina"
3 | name = "websocket"
4 | version = "@project.version@"
5 |
--------------------------------------------------------------------------------
/examples/chat-application/A Basic Chat Application using the Ballerina WebSocket Module.md:
--------------------------------------------------------------------------------
1 | # Chat Application
2 |
3 | [](https://github.com/ballerina-platform/module-ballerina-websocket)
4 |
5 | _Authors_: @shafreenAnfar @Bhashinee \
6 | _Reviewers_: @shafreenAnfar \
7 | _Created_: 2021/07/29 \
8 | _Updated_: 2021/08/16
9 |
10 | ## Overview
11 |
12 | This application shows how to use the Ballerina WebSocket package to implement a simple chat application.
13 |
14 | ## Implementation
15 |
16 | ### The WebSocket Server
17 | The WebSocket server is in charge of registering users to the chat application and broadcasting the messages received by the users.
18 |
19 | ### Users - WebSocket Clients
20 | Clients can register for the chat application by sending requests to the WebSocket server. When the application starts it will request a username. Once a non-empty username is entered, the user will get registered.
21 |
22 | After getting registered, the users can send messages to the chat group by typing messages on the console and pressing `Enter`. Then, the server will broadcast messages by looping over the registered clients.
23 | If a user wants to exit from the chat, he/she can type in `exit` and `Enter` so that the connection will get closed, and the client gets unregistered from the chat.
24 |
25 | The client will have one Ballerina strand writing the messages to the WebSocket connection and one for reading.
26 |
27 | ## Run the Example
28 |
29 | First, clone this repository, and then run the following commands to run this example in your local machine.
30 |
31 | ```sh
32 | // Run the WebSocket server
33 | $ cd examples/chat-application/server
34 | $ bal run
35 | ```
36 |
37 | In another terminal, run the client as follows.
38 | ```sh
39 | // Run the WebSocket client
40 | $ cd examples/chat-application/client
41 | $ bal run
42 | ```
--------------------------------------------------------------------------------
/examples/chat-application/client/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/examples/chat-application/client/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [build-options]
2 | observabilityIncluded = true
3 |
--------------------------------------------------------------------------------
/examples/chat-application/client/Dependencies.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/chat-application/client/Dependencies.toml
--------------------------------------------------------------------------------
/examples/chat-application/client/client.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/io;
18 | import ballerina/websocket;
19 |
20 | public function main() returns error? {
21 | string username = io:readln("Enter username: ");
22 | if (username == "") {
23 | io:println("Username cannot be empty");
24 | return;
25 | }
26 | string url = string `ws://localhost:9090/chat/${username}`;
27 | websocket:Client wsClient = check new(url);
28 | @strand {
29 | thread:"any"
30 | }
31 | worker writeWorker returns error? {
32 | while true {
33 | string msg = io:readln("");
34 | if (msg == "exit") {
35 | check wsClient->close();
36 | return;
37 | } else {
38 | check wsClient->writeMessage(msg);
39 | }
40 | }
41 | }
42 |
43 | @strand {
44 | thread:"any"
45 | }
46 | worker readWorker returns error? {
47 | while true {
48 | string textResp = check wsClient->readMessage();
49 | io:println(textResp);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/examples/chat-application/server/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/examples/chat-application/server/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [build-options]
2 | observabilityIncluded = true
3 |
--------------------------------------------------------------------------------
/examples/chat-application/server/Dependencies.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/chat-application/server/Dependencies.toml
--------------------------------------------------------------------------------
/examples/chat-application/server/tests/test_chat_server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 | import ballerina/websocket;
19 |
20 | @test:Config {}
21 | function testText() returns websocket:Error? {
22 | websocket:Client wsClient = check new("ws://localhost:9090/chat/Alice");
23 | check wsClient->writeTextMessage("Hey");
24 | string serviceReply = check wsClient->readTextMessage();
25 | test:assertEquals(serviceReply, "Hi Alice! You have successfully connected to the chat");
26 | websocket:Error? err = wsClient->close(statusCode = 1000, timeout = 10);
27 | }
28 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/driver/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/driver/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [build-options]
2 | observabilityIncluded = true
3 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/driver/Dependencies.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/taxi-service-management/driver/Dependencies.toml
--------------------------------------------------------------------------------
/examples/taxi-service-management/driver/driver.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/io;
18 | import ballerina/lang.runtime;
19 | import ballerina/random;
20 | import ballerina/websocket;
21 |
22 | public function main() returns error? {
23 | string username = io:readln("Enter username: ");
24 | websocket:Client driverClient = check new(string `ws://localhost:9091/taxi/${username}`);
25 | string connectedMsg = check driverClient->readMessage();
26 | io:println(connectedMsg);
27 | check updateLocation(driverClient);
28 | }
29 |
30 | // This function simulates a real time gps location updates.
31 | // This updated location will be sent to the server every 2 seconds.
32 | function updateLocation(websocket:Client driver) returns error? {
33 | while true {
34 | runtime:sleep(2);
35 | float lon = random:createDecimal() + 79.0;
36 | float lat = random:createDecimal() + 6.0;
37 | string location = "'Latitude'=" + lat.toString() + " 'Longititude'=" + lon.toString();
38 | check driver->writeMessage(location);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/rider/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/rider/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [build-options]
2 | observabilityIncluded = true
3 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/rider/Dependencies.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/taxi-service-management/rider/Dependencies.toml
--------------------------------------------------------------------------------
/examples/taxi-service-management/rider/rider.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/io;
18 | import ballerina/websocket;
19 |
20 | public function main() returns error? {
21 | string username = io:readln("Enter username: ");
22 | // Users can register simply by connecting to the server.
23 | websocket:Client riderClient = check new(string `ws://localhost:9091/subscribe/${username}`);
24 |
25 | // Continuously read the location updates coming from the server.
26 | while true {
27 | string textResp = check riderClient->readMessage();
28 | io:println(textResp);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/server/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/server/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [build-options]
2 | observabilityIncluded = true
3 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/server/Dependencies.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/taxi-service-management/server/Dependencies.toml
--------------------------------------------------------------------------------
/examples/taxi-service-management/server/tests/test_server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 | import ballerina/websocket;
19 |
20 | @test:Config {}
21 | function testServer() returns websocket:Error? {
22 | websocket:Client wsClient = check new("ws://localhost:9091/taxi/Alice");
23 | string serviceReply = check wsClient->readMessage();
24 | test:assertEquals(serviceReply, "Hi Alice! Your location will be shared with the riders");
25 | websocket:Error? err = wsClient->close(statusCode = 1000, timeout = 10);
26 | }
27 |
--------------------------------------------------------------------------------
/examples/taxi-service-management/taxi.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/taxi-service-management/taxi.jpeg
--------------------------------------------------------------------------------
/examples/tic-tac-toe/server/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/server/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [build-options]
2 | observabilityIncluded = true
3 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/server/Dependencies.toml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/tic-tac-toe/server/Dependencies.toml
--------------------------------------------------------------------------------
/examples/tic-tac-toe/server/tests/test_game_server.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/test;
18 | import ballerina/log;
19 | import ballerina/websocket;
20 |
21 | @test:Config {}
22 | function testText() returns websocket:Error? {
23 | websocket:Client wsClient = check new("ws://localhost:8000/ws/game");
24 | websocket:Error? result = wsClient->writeMessage(1);
25 | if (result is websocket:Error) {
26 | log:printError("Error occurred when writing text", 'error = result);
27 | }
28 | json serviceReply = check wsClient->readMessage();
29 | test:assertEquals(serviceReply, {"type":"start","success":true,"sign":"X","next":"X"});
30 | websocket:Error? err = wsClient->close(statusCode = 1000, timeout = 10);
31 | if err is websocket:Error {
32 | log:printError("Error occurred when closing the connection");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/tic-tac-toe.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/tic-tac-toe/tic-tac-toe.gif
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | node_modules
3 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "web-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.16.4",
7 | "@testing-library/react": "^13.3.0",
8 | "@testing-library/user-event": "^13.5.0",
9 | "react": "^18.1.0",
10 | "react-dom": "^18.1.0",
11 | "react-scripts": "5.0.1",
12 | "web-vitals": "^2.1.4",
13 | "websocket": "^1.0.34"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test",
19 | "eject": "react-scripts eject"
20 | },
21 | "eslintConfig": {
22 | "extends": [
23 | "react-app",
24 | "react-app/jest"
25 | ]
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/tic-tac-toe/web-app/public/favicon.ico
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/tic-tac-toe/web-app/public/logo192.png
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/examples/tic-tac-toe/web-app/public/logo512.png
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/examples/tic-tac-toe/web-app/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | font: 14px "Century Gothic", Futura, sans-serif;
3 | margin: 20px;
4 | }
5 |
6 | ol, ul {
7 | padding-left: 30px;
8 | }
9 |
10 | .board-row:after {
11 | clear: both;
12 | content: "";
13 | display: table;
14 | }
15 |
16 | .status {
17 | margin-bottom: 10px;
18 | }
19 |
20 | .sign {
21 | margin-bottom: 10px;
22 | }
23 |
24 | .square {
25 | background: #fff;
26 | border: 1px solid #999;
27 | float: left;
28 | font-size: 24px;
29 | font-weight: bold;
30 | line-height: 34px;
31 | height: 34px;
32 | margin-right: -1px;
33 | margin-top: -1px;
34 | padding: 0;
35 | text-align: center;
36 | width: 34px;
37 | }
38 |
39 | .square:focus {
40 | outline: none;
41 | }
42 |
43 | .kbd-navigation .square:focus {
44 | background: #ddd;
45 | }
46 |
47 | .game {
48 | display: flex;
49 | flex-direction: row;
50 | }
51 |
52 | .game-info {
53 | margin-left: 20px;
54 | }
55 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.caching=true
2 | group=io.ballerina.stdlib
3 | version=2.15.0-SNAPSHOT
4 | ballerinaLangVersion=2201.12.0
5 | ballerinaTomlParserVersion=1.2.2
6 | nettyVersion=4.1.118.Final
7 | slf4jVersion=1.7.30
8 | puppycrawlCheckstyleVersion=10.12.0
9 | unirestVersion=1.4.9
10 | testngVersion=7.6.1
11 | ballerinaGradlePluginVersion=2.3.0
12 | gsonVersion=2.8.8
13 |
14 | spotbugsPluginVersion=6.0.18
15 | shadowJarPluginVersion=8.1.1
16 | downloadPluginVersion=5.4.0
17 | releasePluginVersion=2.8.0
18 |
19 | # Standard Library Dependencies
20 | # Level 01
21 | stdlibIoVersion=1.8.0
22 | stdlibTimeVersion=2.7.0
23 | stdlibUrlVersion=2.6.0
24 |
25 | # Level 02
26 | stdlibConstraintVersion=1.7.0
27 | stdlibCryptoVersion=2.9.0
28 | stdlibLogVersion=2.12.0
29 | stdlibOsVersion=1.10.0
30 | stdlibTaskVersion=2.7.0
31 |
32 | # Level 03
33 | stdlibCacheVersion=3.10.0
34 | stdlibFileVersion=1.12.0
35 | stdlibMimeVersion=2.12.0
36 | stdlibUuidVersion=1.10.0
37 |
38 | # Level 04
39 | stdlibAuthVersion=2.14.0
40 | stdlibDataJsonDataVersion=1.1.0
41 | stdlibJwtVersion=2.15.0
42 | stdlibOAuth2Version=2.14.0
43 |
44 | # Level 05
45 | stdlibHttpVersion=2.14.0
46 |
47 | # Ballerinax Observer
48 | observeVersion=1.5.0
49 | observeInternalVersion=1.5.0
50 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerina-websocket/4799d69f0acc6b6cc532a1a6a7f657972720bf77/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/load-tests/chat_application/deployment/deployment-patch.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: "apps/v1"
2 | kind: Deployment
3 | metadata:
4 | name: no-name
5 | spec:
6 | template:
7 | spec:
8 | containers:
9 | - name: "chat-application"
10 | imagePullPolicy: Always
11 |
--------------------------------------------------------------------------------
/load-tests/chat_application/deployment/ingress.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: networking.k8s.io/v1
3 | kind: Ingress
4 | metadata:
5 | name: chat-application
6 | annotations:
7 | kubernetes.io/ingress.class: nginx
8 | namespace: default
9 | spec:
10 | rules:
11 | - host: bal.perf.test
12 | http:
13 | paths:
14 | - path: "/"
15 | pathType: Prefix
16 | backend:
17 | service:
18 | name: chat-applicatio
19 | port:
20 | number: 9090
21 |
--------------------------------------------------------------------------------
/load-tests/chat_application/deployment/kustomization.yaml:
--------------------------------------------------------------------------------
1 | resources:
2 | - chat_application.yaml
3 | - ingress.yaml
4 | patches:
5 | - path: deployment-patch.yaml
6 | target:
7 | group: apps
8 | version: v1
9 | kind: Deployment
10 | name: chat-application-deployment
11 |
--------------------------------------------------------------------------------
/load-tests/chat_application/scripts/pre_run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | # Copyright 2021 WSO2 Inc. (http://wso2.org)
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | # ----------------------------------------------------------------------------
17 | # Pre run script for ballerina performance tests
18 | # ----------------------------------------------------------------------------
19 | set -e
20 |
21 | echo "----------Downloading websocket plugin tool----------"
22 | wget -O JMeterWebSocketSamplers-1.2.8.jar https://repo1.maven.org/maven2/net/luminis/jmeter/jmeter-websocket-samplers/1.2.8/jmeter-websocket-samplers-1.2.8.jar
23 | sudo cp JMeterWebSocketSamplers-1.2.8.jar /opt/apache-jmeter-5.4/lib/ext
24 |
--------------------------------------------------------------------------------
/load-tests/chat_application/scripts/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 | # Copyright 2021 WSO2 Inc. (http://wso2.org)
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | # ----------------------------------------------------------------------------
17 | # Execution script for ballerina performance tests
18 | # ----------------------------------------------------------------------------
19 | set -e
20 | source base-scenario.sh
21 |
22 | jmeter -n -t "$scriptsDir/"chat-app.jmx -l "$resultsDir/"original.jtl -Jusers=10
23 |
--------------------------------------------------------------------------------
/load-tests/chat_application/src/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "wso2"
3 | name = "chat_application"
4 | version = "0.0.1"
5 |
6 | [build-options]
7 | observabilityIncluded = false
8 | cloud = "k8s"
9 |
--------------------------------------------------------------------------------
/load-tests/chat_application/src/Cloud.toml:
--------------------------------------------------------------------------------
1 | [container.image]
2 | repository= "ballerina"
3 | name="chat_application"
4 |
5 | [cloud.deployment]
6 | min_memory="256Mi"
7 | max_memory="512Mi"
8 | min_cpu="200m"
9 | max_cpu="1000m"
10 |
11 | [cloud.deployment.autoscaling]
12 | min_replicas=1
13 | max_replicas=1
14 |
--------------------------------------------------------------------------------
/native/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/websocket/Handler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2024 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.websocket;
19 |
20 | import io.ballerina.runtime.api.values.BError;
21 |
22 | /**
23 | * This utility interface will support Classes that depends on notifySuccess and notifyFailure methods.
24 | */
25 | public interface Handler {
26 | public void notifySuccess(Object result);
27 |
28 | public void notifyFailure(BError error);
29 | }
30 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/websocket/WebSocketConnectorPortBindingListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package io.ballerina.stdlib.websocket;
20 |
21 | import io.ballerina.stdlib.http.transport.contract.PortBindingEventListener;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | import java.io.PrintStream;
26 |
27 | /**
28 | * An implementation of the LifeCycleEventListener. This can be used to listen to the WebSocket connector
29 | * life cycle events.
30 | */
31 | public class WebSocketConnectorPortBindingListener implements PortBindingEventListener {
32 | private static final Logger log = LoggerFactory.getLogger(WebSocketConnectorPortBindingListener.class);
33 | private static final PrintStream console = System.out;
34 |
35 | @Override
36 | public void onOpen(String serverConnectorId, boolean wss) {
37 |
38 | }
39 |
40 | @Override
41 | public void onClose(String serverConnectorId, boolean wss) {
42 |
43 | }
44 |
45 | @Override
46 | public void onError(Throwable throwable) {
47 | log.debug("Error in WS endpoint", throwable);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/websocket/actions/websocketconnector/WriteTimeOutListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package io.ballerina.stdlib.websocket.actions.websocketconnector;
20 |
21 | import io.ballerina.stdlib.http.transport.contract.websocket.WebSocketWriteTimeOutListener;
22 | import io.ballerina.stdlib.websocket.WebSocketUtil;
23 |
24 | import java.util.concurrent.CompletableFuture;
25 | import java.util.concurrent.atomic.AtomicBoolean;
26 |
27 | /**
28 | * A class for notifying the write timeout to the client.
29 | */
30 | public class WriteTimeOutListener implements WebSocketWriteTimeOutListener {
31 |
32 | private CompletableFuture