-
Notifications
You must be signed in to change notification settings - Fork 37
Add support for custom remote function mapping via Annotation #1553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MohamedSabthar
merged 43 commits into
ballerina-platform:main
from
chathushkaayash:feat/custom-remote-method-annotation
Apr 11, 2025
Merged
Changes from 33 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
8ef867e
[Automated] Update the native jar versions
chathushkaayash 14a3533
[Automated] Update the native jar versions
chathushkaayash 1068e58
Add DispatcherConfig annotation for WebSocket remote functions
chathushkaayash 1c0b3a5
Add support for dispatching messages to remote functions based on pri…
chathushkaayash cb16593
Merge branch 'main' into feat/custom-remote-method-annotation
MohamedSabthar be883e0
Update license header and WsDispatcherConfig naming convention
chathushkaayash d587e8a
Change WsDispatcherConfig annotation to a constant
chathushkaayash 95bedbf
Rename WS service name in the test
chathushkaayash 855afda
Rename annotation file name
chathushkaayash 753c410
Update DispatcherConfig annotation doc comment
chathushkaayash c0d988f
Merge branch 'main' into feat/custom-remote-method-annotation
daneshk d979a5a
Refactor ANNOTATION_ATTR_DISPATCHER_VALUE to string
chathushkaayash f0a6982
Add compiler plugin validation for DispatcherConfig annotation
chathushkaayash 428a9cf
Add validation for duplicated DispatcherConfig annotation values
chathushkaayash f1d760a
Add validation for DispatcherConfig used with special functions
chathushkaayash cb2e95c
Handling dispatcher config annotation with customOnError methods
chathushkaayash 9c123a4
Move DispatcherConfig annotation to annotation file
chathushkaayash 8b45634
Rename DispatcherConfig annotation to DispatcherMapping
chathushkaayash cce160f
Merge branch 'main' into feat/custom-remote-method-annotation
chathushkaayash cafc522
Fix missing closing brace in WebSocketServiceValidationTest
chathushkaayash 3e7a192
[Automated] Update the native jar versions
chathushkaayash 4bd2f4b
Bump version to 2.15.0
chathushkaayash 80681d7
[Automated] Update the native jar versions
chathushkaayash d34b57f
Reuse createCustomRemoteFunction method and update dependencies requi…
chathushkaayash 5bde2e2
Fix typo in WebSocketServiceValidator
chathushkaayash 9ffecc6
Update the spec
chathushkaayash 13839d0
Remove unnecessary comment
chathushkaayash a7e6fe4
Use alias for websocket test
chathushkaayash 1c8a114
Refactor WebSocketServiceValidator to use semanticModel for getting a…
chathushkaayash 6ad3ef1
Rename dispatcherConfig to dispatcherMapping
chathushkaayash 0ef3e16
Update changelog
chathushkaayash f92a9cd
Remove if else ladders and use kind check instead of instanceof
chathushkaayash 56c0794
Update WsDispatcherMapping doc comment
chathushkaayash e8a82d2
Refactor WebSocketServiceValidator to use 'this' keyword for specialR…
chathushkaayash 6d4fc90
update getDispatchingFunctionMap method
chathushkaayash 57c4acc
Update INVALID_FUNCTION_ANNOTATION message to clarify usage with cust…
chathushkaayash df9da2d
update getDispatchingFunctionMap method to filter the remote methods
chathushkaayash c2db582
Merge branch 'main' of https://github.com/ballerina-platform/module-b…
chathushkaayash 3a3f729
Add logging to testConnectionClosureTimeoutCaller test
chathushkaayash ce9a8c7
Removed unnecessary prints
chathushkaayash 9dff3df
Validate remote qualifier in WebSocket service functions
chathushkaayash e2b63e6
Refactor WebSocketService to validate remote method types using Symbo…
chathushkaayash 7105638
Merge branch 'main' into feat/custom-remote-method-annotation
MohamedSabthar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import ballerina/test; | ||
|
|
||
| type Subscribe record {| | ||
| string event = "subscribe"; | ||
| string data; | ||
| |}; | ||
|
|
||
| @ServiceConfig { | ||
| dispatcherKey: "event" | ||
| } | ||
| service / on new Listener(22103) { | ||
| resource function get .() returns Service|UpgradeError { | ||
| return new WsService22103(); | ||
| } | ||
| } | ||
|
|
||
| service class WsService22103 { | ||
| *Service; | ||
|
|
||
| @DispatcherMapping { | ||
| value: "subscribe" | ||
| } | ||
| remote function onSubscribeMessage(Subscribe message) returns string { | ||
| return "onSubscribeMessage"; | ||
| } | ||
|
|
||
| remote function onSubscribeMessageError(Caller caller, error message) returns error? { | ||
| check caller->writeMessage("onSubscribeMessageError"); | ||
| } | ||
| } | ||
|
|
||
| @test:Config { | ||
| groups: ["dispatcherMappingAnnotation"] | ||
| } | ||
| public function testDispatcherMappingAnnotation() returns error? { | ||
| Client wsClient = check new ("ws://localhost:22103/"); | ||
| check wsClient->writeMessage({event: "subscribe", data: "test"}); | ||
| string res = check wsClient->readMessage(); | ||
| test:assertEquals(res, "onSubscribeMessage"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| groups: ["dispatcherMappingAnnotation"] | ||
| } | ||
| public function testDispatcherMappingAnnotationWithCustomOnError() returns error? { | ||
| Client wsClient = check new ("ws://localhost:22103/"); | ||
| check wsClient->writeMessage({event: "subscribe", invalidField: "test"}); | ||
| string res = check wsClient->readMessage(); | ||
| test:assertEquals(res, "onSubscribeMessageError"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_63/Ballerina.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [package] | ||
| org = "websocket_test" | ||
| name = "sample_63" | ||
| version = "0.1.0" |
60 changes: 60 additions & 0 deletions
60
compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_63/server.bal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import ballerina/websocket as ws; | ||
|
|
||
| type Subscribe record {| | ||
| string event = "subscribe"; | ||
| string data; | ||
| |}; | ||
|
|
||
| @ws:ServiceConfig { | ||
| dispatcherKey: "event" | ||
| } | ||
| service / on new ws:Listener(9090) { | ||
| resource function get .() returns ws:Service|ws:UpgradeError { | ||
| return new WsService(); | ||
| } | ||
| } | ||
|
|
||
| service class WsService { | ||
| *ws:Service; | ||
|
|
||
| remote function onSubscribe(Subscribe message) returns string { | ||
| return "onSubscribe"; | ||
| } | ||
|
|
||
| @ws:DispatcherMapping { | ||
| value: "subscribe" | ||
| } | ||
| remote function onSubscribeMessage(Subscribe message) returns string { | ||
| return "onSubscribeMessage"; | ||
| } | ||
|
|
||
| @ws:DispatcherMapping { | ||
| value: "subscribe" | ||
| } | ||
| remote function onSubscribeText(Subscribe message) returns string { | ||
| return "onSubscribeText"; | ||
| } | ||
|
|
||
| @ws:DispatcherMapping { | ||
| value: "ping" | ||
| } | ||
| remote function onPing(Subscribe message) returns string { | ||
| return "onPing"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.