-
Notifications
You must be signed in to change notification settings - Fork 33
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
Implement new service type changes and client changes #13
Conversation
Removed the callbackService from client configuration and added it as a optional parameter in the client init.
79212b0
to
39030ee
Compare
39030ee
to
f605a8a
Compare
e8e014b
to
f92d754
Compare
7af0d81
to
edeae8e
Compare
@@ -1,75 +1,73 @@ | |||
//// Copyright (c) 2020 WSO2 Inc. (//www.wso2.org) All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to think of a way to rewrite this test once this issue gets fixed. Kept the test commented for reference.
@@ -1,61 +1,62 @@ | |||
//// Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to think of a way to rewrite this test once this issue gets fixed. Kept the test commented for reference.
3b3d6cb
to
5fd63ed
Compare
websocket-ballerina/Package.md
Outdated
} | ||
resource function upgrader(http:Caller caller, http:Request req, string name) { | ||
service /basePath on new websocket:Listener(21003) { | ||
resource function onUpgrade .(http:Caller caller, http:Request req) returns websocket:Service|websocket:UpgradeError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct ? I thought it should be
resource function get .(http:Caller caller, http:Request req) returns websocket:Service|websocket:UpgradeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the resource(method) name, right? In HTTP it is mapped to the accessor get, post, etc. In WebSocket, we always get a specific get request which is always dispatched to this single resource. I think it is clear to have onUpgrade
as the name in websocket context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually what comes first is the accessor name. @chamil321 can you confirm this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, The first identifier is the accessor name. The second one is the resource name(path). In this case she has used onUpgrade
as accessor name which is a custom accessor. Here the HTTP dispatching logic does not apply as webscoket as its own implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this could lead to confusions as we maintain all the HTTP semantics in this resource. Initial request is HTTP and HTTP does not have an onUpgrade verb.
@Bhashinee it is not the resource name. So what we need is
resource function get .(http:Caller caller, http:Request req) returns websocket:Service|websocket:UpgradeError
websocket-ballerina/Package.md
Outdated
} | ||
} | ||
resource function upgrader(http:Caller caller, http:Request req, string name) { | ||
service /basePath on new websocket:Listener(21003) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the base path is not given does it default to /ws ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is '/'. ws://localhost:21029
or ws://localhost:21029/
will get dispatched to this service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should default to /ws as that is most common case ? wdyt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the discussion had, we decided not to do this for now.
websocket-ballerina/Package.md
Outdated
|
||
**onOpen resource**: As soon as the WebSocket handshake is completed and the connection is established, the `onOpen` resource is dispatched. This resource is only available in the service of the server. | ||
**onConnect resource**: As soon as the WebSocket handshake is completed and the connection is established, the `onConnect` resource is dispatched. This resource is only available in the service of the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it resource or remote ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a remote method. Will change this.
public isolated function init(int port, ListenerConfiguration? config = ()) { | ||
# + port - Listening port of the websocket service listener | ||
# + config - Configurations for the websocket service listener | ||
public isolated function init(int|http:Listener listenerPort, ListenerConfiguration? config = ()) returns Error? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say listener not listenerport
service UpgradeService /onTextString on new Listener(21003) { | ||
remote isolated function onUpgrade(http:Caller caller, http:Request req) returns Service|WebSocketError { | ||
service /onTextString on l2 { | ||
resource function onUpgrade .() returns Service|UpgradeError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct ? Do we have an accessor named onUpgrade ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to get
remote isolated function onText(Caller caller, string data, boolean finalFrame) { | ||
checkpanic caller->pushText(data); | ||
remote isolated function onString(Caller caller, string data) { | ||
checkpanic caller->writeString(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of panic I think it is better if we can check and return the error
service object {} clientPushCallbackService = service object { | ||
remote function onText(Client wsEp, string text) { | ||
service class clientPushCallbackService { | ||
remote function onString(AsyncClient wsEp, string text) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here what we need is the caller right not the AsyncClient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller is for the server-side. Here we pass in the created WebSocket client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I thought we should expose the same client in the form of the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be the caller even when it is on the client side. Is there a specific reason to do otherwise ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rename this to Caller. But isn't it confusing for the users? They have created an AsyncClient and for sending messages they are using something called Caller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the discussion had, renaming this to Caller
} | ||
}) { | ||
remote isolated function onUpgrade(http:Caller caller, http:Request req) returns Service { | ||
listener Listener l7 = checkpanic new(21029, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need checkpanic here ? I see, it seems like the spec has changed. ballerina-platform/ballerina-spec#671
If we need it can't we use check instead of checkpanic ?
}); | ||
|
||
service /sslEcho on l7 { | ||
resource function upgrade .(http:Request req) returns Service { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
5afb3cd
to
2b5eec6
Compare
65f8602
to
4482487
Compare
d17eadd
to
9989a2d
Compare
…ation Migrate ballerina/http module
Purpose
This PR addresses following issues,
pushText
towriteString
,pushBinary
towriteBytes
,onText
toonString
,onBinary
toonBytes
,onOpen
toonConnect
Samples
websocket service
Websocket Async client
Websocket Sync client
Read string
Read binary data
byte[] resp3 = check wsClient->readBytes();