Skip to content
Merged
Show file tree
Hide file tree
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 Mar 26, 2025
14a3533
[Automated] Update the native jar versions
chathushkaayash Mar 26, 2025
1068e58
Add DispatcherConfig annotation for WebSocket remote functions
chathushkaayash Mar 26, 2025
1c0b3a5
Add support for dispatching messages to remote functions based on pri…
chathushkaayash Mar 27, 2025
cb16593
Merge branch 'main' into feat/custom-remote-method-annotation
MohamedSabthar Mar 28, 2025
be883e0
Update license header and WsDispatcherConfig naming convention
chathushkaayash Mar 28, 2025
d587e8a
Change WsDispatcherConfig annotation to a constant
chathushkaayash Mar 28, 2025
95bedbf
Rename WS service name in the test
chathushkaayash Mar 28, 2025
855afda
Rename annotation file name
chathushkaayash Mar 28, 2025
753c410
Update DispatcherConfig annotation doc comment
chathushkaayash Mar 31, 2025
c0d988f
Merge branch 'main' into feat/custom-remote-method-annotation
daneshk Mar 31, 2025
d979a5a
Refactor ANNOTATION_ATTR_DISPATCHER_VALUE to string
chathushkaayash Apr 1, 2025
f0a6982
Add compiler plugin validation for DispatcherConfig annotation
chathushkaayash Apr 1, 2025
428a9cf
Add validation for duplicated DispatcherConfig annotation values
chathushkaayash Apr 1, 2025
f1d760a
Add validation for DispatcherConfig used with special functions
chathushkaayash Apr 2, 2025
cb2e95c
Handling dispatcher config annotation with customOnError methods
chathushkaayash Apr 3, 2025
9c123a4
Move DispatcherConfig annotation to annotation file
chathushkaayash Apr 3, 2025
8b45634
Rename DispatcherConfig annotation to DispatcherMapping
chathushkaayash Apr 3, 2025
cce160f
Merge branch 'main' into feat/custom-remote-method-annotation
chathushkaayash Apr 3, 2025
cafc522
Fix missing closing brace in WebSocketServiceValidationTest
chathushkaayash Apr 3, 2025
3e7a192
[Automated] Update the native jar versions
chathushkaayash Apr 3, 2025
4bd2f4b
Bump version to 2.15.0
chathushkaayash Apr 3, 2025
80681d7
[Automated] Update the native jar versions
chathushkaayash Apr 3, 2025
d34b57f
Reuse createCustomRemoteFunction method and update dependencies requi…
chathushkaayash Apr 3, 2025
5bde2e2
Fix typo in WebSocketServiceValidator
chathushkaayash Apr 3, 2025
9ffecc6
Update the spec
chathushkaayash Apr 4, 2025
13839d0
Remove unnecessary comment
chathushkaayash Apr 4, 2025
a7e6fe4
Use alias for websocket test
chathushkaayash Apr 4, 2025
1c8a114
Refactor WebSocketServiceValidator to use semanticModel for getting a…
chathushkaayash Apr 4, 2025
6ad3ef1
Rename dispatcherConfig to dispatcherMapping
chathushkaayash Apr 4, 2025
0ef3e16
Update changelog
chathushkaayash Apr 4, 2025
f92a9cd
Remove if else ladders and use kind check instead of instanceof
chathushkaayash Apr 4, 2025
56c0794
Update WsDispatcherMapping doc comment
chathushkaayash Apr 7, 2025
e8a82d2
Refactor WebSocketServiceValidator to use 'this' keyword for specialR…
chathushkaayash Apr 7, 2025
6d4fc90
update getDispatchingFunctionMap method
chathushkaayash Apr 7, 2025
57c4acc
Update INVALID_FUNCTION_ANNOTATION message to clarify usage with cust…
chathushkaayash Apr 7, 2025
df9da2d
update getDispatchingFunctionMap method to filter the remote methods
chathushkaayash Apr 8, 2025
c2db582
Merge branch 'main' of https://github.com/ballerina-platform/module-b…
chathushkaayash Apr 9, 2025
3a3f729
Add logging to testConnectionClosureTimeoutCaller test
chathushkaayash Apr 10, 2025
ce9a8c7
Removed unnecessary prints
chathushkaayash Apr 10, 2025
9dff3df
Validate remote qualifier in WebSocket service functions
chathushkaayash Apr 10, 2025
e2b63e6
Refactor WebSocketService to validate remote method types using Symbo…
chathushkaayash Apr 11, 2025
7105638
Merge branch 'main' into feat/custom-remote-method-annotation
MohamedSabthar Apr 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "websocket"
version = "2.14.1"
version = "2.15.0"
authors = ["Ballerina"]
keywords = ["ws", "network", "bi-directional", "streaming", "service", "client"]
repository = "https://github.com/ballerina-platform/module-ballerina-websocket"
Expand All @@ -15,8 +15,8 @@ graalvmCompatible = true
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "websocket-native"
version = "2.14.1"
path = "../native/build/libs/websocket-native-2.14.1-SNAPSHOT.jar"
version = "2.15.0"
path = "../native/build/libs/websocket-native-2.15.0-SNAPSHOT.jar"

[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
Expand Down Expand Up @@ -85,5 +85,5 @@ version = "4.1.118.Final"
path = "./lib/netty-handler-proxy-4.1.118.Final.jar"

[[platform.java21.dependency]]
path = "../test-utils/build/libs/websocket-test-utils-2.14.1-SNAPSHOT.jar"
path = "../test-utils/build/libs/websocket-test-utils-2.15.0-SNAPSHOT.jar"
scope = "testOnly"
8 changes: 7 additions & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ id = "websocket-compiler-plugin"
class = "io.ballerina.stdlib.websocket.plugin.WebSocketCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/websocket-compiler-plugin-2.14.1-SNAPSHOT.jar"
path = "../compiler-plugin/build/libs/websocket-compiler-plugin-2.15.0-SNAPSHOT.jar"

[[dependency]]
path = "../native/build/libs/websocket-native-2.15.0-SNAPSHOT.jar"

[[dependency]]
path = "./lib/http-native-2.14.0.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "websocket"
version = "2.14.1"
version = "2.15.0"
dependencies = [
{org = "ballerina", name = "auth"},
{org = "ballerina", name = "constraint"},
Expand Down
14 changes: 10 additions & 4 deletions ballerina/annotation.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
// specific language governing permissions and limitations
// under the License.

///////////////////////////
/// Service Annotations ///
///////////////////////////

# Configurations for a WebSocket service.
#
# + subProtocols - Negotiable sub protocol by the service
Expand All @@ -42,3 +38,13 @@ public type WSServiceConfig record {|

# The annotation which is used to configure a WebSocket service.
public annotation WSServiceConfig ServiceConfig on service;

# Configurations used to define dispatching rules for remote functions.
#
# + value - The value which is going to be used for dispatching to custom remote functions.
public type WsDispatcherMapping record {|
string value;
|};

# The annotation which is used to configure the dispatching rules for WebSocket remote functions.
public const annotation WsDispatcherMapping DispatcherMapping on function;
1 change: 1 addition & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ task updateTomlFiles {
ballerinaTomlFile.text = newConfig

def newPluginConfig = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version)
newPluginConfig = newPluginConfig.replace("@stdlib.httpnative.version@", stdlibDependentHttpNativeVersion)
compilerPluginTomlFile.text = newPluginConfig
}
}
Expand Down
66 changes: 66 additions & 0 deletions ballerina/tests/test_dispatcher_mapping_annotation.bal
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");
}
6 changes: 6 additions & 0 deletions build-config/resources/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ class = "io.ballerina.stdlib.websocket.plugin.WebSocketCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/websocket-compiler-plugin-@project.version@.jar"

[[dependency]]
path = "../native/build/libs/websocket-native-@project.version@.jar"

[[dependency]]
path = "./lib/http-native-@stdlib.httpnative.version@.jar"
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Added

- [Support Custom Remote Function Mapping via Annotation](https://github.com/ballerina-platform/ballerina-library/issues/7733)
- [Implement websocket close frame support](https://github.com/ballerina-platform/ballerina-library/issues/7578)

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,20 @@ public void testRemoteFunctionWithStreamAndCloseFrameReturnTypes() {
Assert.assertEquals(diagnosticResult.errorCount(), 0);
}

@Test
public void testDispatcherMappingAnnotation() {
Package currentPackage = loadPackage("sample_package_63");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
Assert.assertEquals(diagnosticResult.errorCount(), 3);
Diagnostic firstDiagnostic = (Diagnostic) diagnosticResult.errors().toArray()[0];
assertDiagnostic(firstDiagnostic, PluginConstants.CompilationErrors.RE_DECLARED_REMOTE_FUNCTIONS);
Diagnostic secondDiagnostic = (Diagnostic) diagnosticResult.errors().toArray()[1];
assertDiagnostic(secondDiagnostic, PluginConstants.CompilationErrors.DUPLICATED_DISPATCHER_MAPPING_VALUE);
Diagnostic thirdDiagnostic = (Diagnostic) diagnosticResult.errors().toArray()[2];
assertDiagnostic(thirdDiagnostic, PluginConstants.CompilationErrors.INVALID_FUNCTION_ANNOTATION);
}

private void assertDiagnostic(Diagnostic diagnostic, PluginConstants.CompilationErrors error) {
Assert.assertEquals(diagnostic.diagnosticInfo().code(), error.getErrorCode());
Assert.assertEquals(diagnostic.diagnosticInfo().messageFormat(),
Expand Down
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"
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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public enum CompilationErrors {
"WEBSOCKET_215"),
INVALID_REMOTE_FUNCTIONS("Cannot have `{0}` with `onMessage` remote function",
"WEBSOCKET_216"),
RE_DECLARED_REMOTE_FUNCTIONS("Cannot have `{0}` because the message type `{1}` is already " +
"associated with `{2}` remote function", "WEBSOCKET_217"),
DUPLICATED_DISPATCHER_MAPPING_VALUE("DispatcherMapping annotation value `{0}` is already " +
"exists", "WEBSOCKET_218"),
INVALID_FUNCTION_ANNOTATION("Invalid annotation provided for `{0}` remote function", "WEBSOCKET_219"),
INVALID_RESOURCE_ERROR("There should be only one `get` resource for the service",
"WEBSOCKET_101"),
MORE_THAN_ONE_RESOURCE_PARAM_ERROR("There should be only http:Request as a parameter",
Expand Down
Loading
Loading