Skip to content

Commit 429dce8

Browse files
committed
Resolve merge conflicts
2 parents 6b97a42 + d269bd6 commit 429dce8

File tree

7 files changed

+176
-37
lines changed

7 files changed

+176
-37
lines changed

Diff for: ballerina/tests/basic_hub_test.bal

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ listener Listener functionWithArgumentsListener = new(9090);
2424

2525
service /websubhub on functionWithArgumentsListener {
2626

27-
isolated remote function onRegisterTopic(TopicRegistration message)
27+
isolated remote function onRegisterTopic(TopicRegistration message, http:Headers headers)
2828
returns TopicRegistrationSuccess|TopicRegistrationError {
2929
if (message.topic == "test") {
3030
TopicRegistrationSuccess successResult = {
@@ -38,7 +38,7 @@ service /websubhub on functionWithArgumentsListener {
3838
}
3939
}
4040

41-
isolated remote function onDeregisterTopic(TopicDeregistration message)
41+
isolated remote function onDeregisterTopic(TopicDeregistration message, http:Headers headers)
4242
returns TopicDeregistrationSuccess|TopicDeregistrationError {
4343

4444
map<string> body = { isDeregisterSuccess: "true" };
@@ -52,7 +52,7 @@ service /websubhub on functionWithArgumentsListener {
5252
}
5353
}
5454

55-
isolated remote function onUpdateMessage(UpdateMessage msg)
55+
isolated remote function onUpdateMessage(UpdateMessage msg, http:Headers headers)
5656
returns Acknowledgement|UpdateMessageError {
5757
Acknowledgement ack = {};
5858
if (msg.hubTopic == "test") {

Diff for: ballerina/tests/hub_authentication_test.bal

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final http:ListenerJwtAuthHandler handler = new({
3939

4040
service /websubhub on securedListener {
4141

42-
remote function onRegisterTopic(TopicRegistration message, http:Headers headers)
42+
remote function onRegisterTopic(http:Headers headers, TopicRegistration message)
4343
returns TopicRegistrationSuccess|TopicRegistrationError {
4444
string? auth = doAuth(headers);
4545
if (auth is string) {
@@ -49,7 +49,7 @@ service /websubhub on securedListener {
4949
return TOPIC_REGISTRATION_SUCCESS;
5050
}
5151

52-
remote function onDeregisterTopic(TopicDeregistration message, http:Headers headers)
52+
remote function onDeregisterTopic(http:Headers headers, TopicDeregistration message)
5353
returns TopicDeregistrationSuccess|TopicDeregistrationError {
5454
string? auth = doAuth(headers);
5555
if (auth is string) {
@@ -59,7 +59,7 @@ service /websubhub on securedListener {
5959
return TOPIC_DEREGISTRATION_SUCCESS;
6060
}
6161

62-
remote function onUpdateMessage(UpdateMessage message, http:Headers headers)
62+
remote function onUpdateMessage(http:Headers headers, UpdateMessage message)
6363
returns Acknowledgement|UpdateMessageError {
6464
string? auth = doAuth(headers);
6565
if (auth is string) {
@@ -69,7 +69,7 @@ service /websubhub on securedListener {
6969
return ACKNOWLEDGEMENT;
7070
}
7171

72-
remote function onSubscription(Subscription message, http:Headers headers)
72+
remote function onSubscription(http:Headers headers, Subscription message)
7373
returns SubscriptionAccepted|InternalSubscriptionError {
7474
string? auth = doAuth(headers);
7575
if (auth is string) {
@@ -82,7 +82,7 @@ service /websubhub on securedListener {
8282
isolated remote function onSubscriptionIntentVerified(VerifiedSubscription message) {
8383
}
8484

85-
remote function onUnsubscription(Unsubscription message, http:Headers headers)
85+
remote function onUnsubscription(http:Headers headers, Unsubscription message)
8686
returns UnsubscriptionAccepted|InternalUnsubscriptionError {
8787
string? auth = doAuth(headers);
8888
if (auth is string) {

Diff for: changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- [Introduce dynamic parameter order for the `websubhub:Service` remote methods](https://github.com/ballerina-platform/ballerina-library/issues/7600)
11+
912
## [1.11.1] - 2024-11-22
1013

1114
### Changed

Diff for: native/src/main/java/io/ballerina/stdlib/websubhub/Constants.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface Constants {
2525
String PACKAGE_ORG = "ballerina";
2626
String PACKAGE_NAME = "websubhub";
2727

28-
String SERVICE_OBJECT = "WEBSUBHUB_SERVICE_OBJECT";
28+
String NATIVE_HUB_SERVICE = "NATIVE_HUB_SERVICE";
2929

3030
String ON_REGISTER_TOPIC = "onRegisterTopic";
3131
String ON_DEREGISTER_TOPIC = "onDeregisterTopic";
@@ -37,6 +37,9 @@ public interface Constants {
3737
String ON_UNSUBSCRIPTION_VALIDATION = "onUnsubscriptionValidation";
3838
String ON_UNSUBSCRIPTION_INTENT_VERIFIED = "onUnsubscriptionIntentVerified";
3939

40+
String HTTP_HEADERS_TYPE = "http:Headers";
41+
String WEBSUBHUB_CONTROLLER_TYPE = "websubhub:Controller";
42+
4043
String COMMON_RESPONSE = "CommonResponse";
4144
String STATUS_CODE = "statusCode";
4245
String SERVICE_EXECUTION_ERROR = "ServiceExecutionError";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. 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.websubhub;
20+
21+
import io.ballerina.runtime.api.types.Type;
22+
import io.ballerina.runtime.api.values.BMap;
23+
import io.ballerina.runtime.api.values.BObject;
24+
import io.ballerina.runtime.api.values.BString;
25+
26+
import static io.ballerina.stdlib.websubhub.Constants.HTTP_HEADERS_TYPE;
27+
import static io.ballerina.stdlib.websubhub.Constants.WEBSUBHUB_CONTROLLER_TYPE;
28+
29+
/**
30+
* {@code InteropArgs} is a wrapper object which contains the parameters for inter-op calls.
31+
*/
32+
public class InteropArgs {
33+
private final BMap<BString, Object> message;
34+
private final BObject httpHeaders;
35+
private BObject hubController;
36+
37+
InteropArgs(BMap<BString, Object> message, BObject httpHeaders) {
38+
this.message = message;
39+
this.httpHeaders = httpHeaders;
40+
}
41+
42+
public InteropArgs(BMap<BString, Object> message, BObject httpHeaders, BObject hubController) {
43+
this.message = message;
44+
this.httpHeaders = httpHeaders;
45+
this.hubController = hubController;
46+
}
47+
48+
public Object getMappingArg(Type argType) {
49+
String argTypeName = argType.toString();
50+
if (HTTP_HEADERS_TYPE.equals(argTypeName)) {
51+
return httpHeaders;
52+
} else if (WEBSUBHUB_CONTROLLER_TYPE.equals(argTypeName)) {
53+
return hubController;
54+
}
55+
return message;
56+
}
57+
}

Diff for: native/src/main/java/io/ballerina/stdlib/websubhub/NativeHttpToWebsubhubAdaptor.java

+39-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import io.ballerina.runtime.api.values.BObject;
3636
import io.ballerina.runtime.api.values.BString;
3737

38-
import java.util.ArrayList;
3938
import java.util.List;
4039
import java.util.concurrent.CompletableFuture;
4140

@@ -48,7 +47,7 @@
4847
import static io.ballerina.stdlib.websubhub.Constants.ON_UNSUBSCRIPTION_INTENT_VERIFIED;
4948
import static io.ballerina.stdlib.websubhub.Constants.ON_UNSUBSCRIPTION_VALIDATION;
5049
import static io.ballerina.stdlib.websubhub.Constants.ON_UPDATE_MESSAGE;
51-
import static io.ballerina.stdlib.websubhub.Constants.SERVICE_OBJECT;
50+
import static io.ballerina.stdlib.websubhub.Constants.NATIVE_HUB_SERVICE;
5251

5352
/**
5453
* {@code NativeHttpToWebsubhubAdaptor} is a wrapper object used for service method execution.
@@ -57,124 +56,136 @@ public final class NativeHttpToWebsubhubAdaptor {
5756
private NativeHttpToWebsubhubAdaptor() {}
5857

5958
public static void externInit(BObject adaptor, BObject serviceObj) {
60-
adaptor.addNativeData(SERVICE_OBJECT, serviceObj);
59+
adaptor.addNativeData(NATIVE_HUB_SERVICE, new NativeHubService(serviceObj));
6160
}
6261

6362
public static BArray getServiceMethodNames(BObject adaptor) {
64-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
65-
List<BString> methodNamesList = new ArrayList<>();
66-
ObjectType serviceType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(bHubService));
67-
for (MethodType method : serviceType.getMethods()) {
68-
methodNamesList.add(StringUtils.fromString(method.getName()));
69-
}
70-
return ValueCreator.createArrayValue(methodNamesList.toArray(BString[]::new));
63+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
64+
List<BString> remoteMethodNames = nativeHubService.getRemoteMethodNames().stream()
65+
.map(StringUtils::fromString).toList();
66+
return ValueCreator.createArrayValue(remoteMethodNames.toArray(BString[]::new));
7167
}
7268

7369
public static Object callRegisterMethod(Environment env, BObject adaptor,
7470
BMap<BString, Object> message, BObject bHttpHeaders) {
75-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
71+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
72+
BObject bHubService = nativeHubService.getBHubService();
7673
boolean isReadOnly = isReadOnlyParam(bHubService, ON_REGISTER_TOPIC);
7774
if (isReadOnly) {
7875
message.freezeDirect();
7976
}
80-
Object[] args = new Object[]{message, bHttpHeaders};
77+
Object[] args = nativeHubService.getMethodArgs(ON_REGISTER_TOPIC, new InteropArgs(message, bHttpHeaders));
8178
return invokeRemoteFunction(env, bHubService, args,
8279
"callRegisterMethod", ON_REGISTER_TOPIC);
8380
}
8481

8582
public static Object callDeregisterMethod(Environment env, BObject adaptor,
8683
BMap<BString, Object> message, BObject bHttpHeaders) {
87-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
84+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
85+
BObject bHubService = nativeHubService.getBHubService();
8886
boolean isReadOnly = isReadOnlyParam(bHubService, ON_DEREGISTER_TOPIC);
8987
if (isReadOnly) {
9088
message.freezeDirect();
9189
}
92-
Object[] args = new Object[]{message, bHttpHeaders};
90+
Object[] args = nativeHubService.getMethodArgs(ON_DEREGISTER_TOPIC, new InteropArgs(message, bHttpHeaders));
9391
return invokeRemoteFunction(env, bHubService, args,
9492
"callDeregisterMethod", ON_DEREGISTER_TOPIC);
9593
}
9694

9795
public static Object callOnUpdateMethod(Environment env, BObject adaptor,
9896
BMap<BString, Object> message, BObject bHttpHeaders) {
99-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
97+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
98+
BObject bHubService = nativeHubService.getBHubService();
10099
boolean isReadOnly = isReadOnlyParam(bHubService, ON_UPDATE_MESSAGE);
101100
if (isReadOnly) {
102101
message.freezeDirect();
103102
}
104-
Object[] args = new Object[]{message, bHttpHeaders};
103+
Object[] args = nativeHubService.getMethodArgs(ON_UPDATE_MESSAGE, new InteropArgs(message, bHttpHeaders));
105104
return invokeRemoteFunction(env, bHubService, args,
106105
"callOnUpdateMethod", ON_UPDATE_MESSAGE);
107106
}
108107

109108
public static Object callOnSubscriptionMethod(Environment env, BObject adaptor, BMap<BString, Object> message,
110109
BObject bHttpHeaders, BObject bHubController) {
111-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
110+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
111+
BObject bHubService = nativeHubService.getBHubService();
112112
boolean isReadOnly = isReadOnlyParam(bHubService, ON_SUBSCRIPTION);
113113
if (isReadOnly) {
114114
message.freezeDirect();
115115
}
116-
Object[] args = new Object[]{message, bHttpHeaders, bHubController};
116+
Object[] args = nativeHubService.getMethodArgs(ON_SUBSCRIPTION, new InteropArgs(
117+
message, bHttpHeaders, bHubController));
117118
return invokeRemoteFunction(env, bHubService, args,
118119
"callOnSubscriptionMethod", ON_SUBSCRIPTION);
119120
}
120121

121122
public static Object callOnSubscriptionValidationMethod(Environment env, BObject adaptor,
122123
BMap<BString, Object> message, BObject bHttpHeaders) {
123-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
124+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
125+
BObject bHubService = nativeHubService.getBHubService();
124126
boolean isReadOnly = isReadOnlyParam(bHubService, ON_SUBSCRIPTION_VALIDATION);
125127
if (isReadOnly) {
126128
message.freezeDirect();
127129
}
128-
Object[] args = new Object[]{message, bHttpHeaders};
130+
Object[] args = nativeHubService.getMethodArgs(ON_SUBSCRIPTION_VALIDATION,
131+
new InteropArgs(message, bHttpHeaders));
129132
return invokeRemoteFunction(env, bHubService, args,
130133
"callOnSubscriptionValidationMethod", ON_SUBSCRIPTION_VALIDATION);
131134
}
132135

133136
public static Object callOnSubscriptionIntentVerifiedMethod(Environment env, BObject adaptor,
134137
BMap<BString, Object> message, BObject bHttpHeaders) {
135-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
138+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
139+
BObject bHubService = nativeHubService.getBHubService();
136140
boolean isReadOnly = isReadOnlyParam(bHubService, ON_SUBSCRIPTION_INTENT_VERIFIED);
137141
if (isReadOnly) {
138142
message.freezeDirect();
139143
}
140-
Object[] args = new Object[]{message, bHttpHeaders};
144+
Object[] args = nativeHubService.getMethodArgs(ON_SUBSCRIPTION_INTENT_VERIFIED,
145+
new InteropArgs(message, bHttpHeaders));
141146
return invokeRemoteFunction(env, bHubService, args,
142147
"callOnSubscriptionIntentVerifiedMethod",
143148
ON_SUBSCRIPTION_INTENT_VERIFIED);
144149
}
145150

146151
public static Object callOnUnsubscriptionMethod(Environment env, BObject adaptor, BMap<BString, Object> message,
147152
BObject bHttpHeaders, BObject bHubController) {
148-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
153+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
154+
BObject bHubService = nativeHubService.getBHubService();
149155
boolean isReadOnly = isReadOnlyParam(bHubService, ON_UNSUBSCRIPTION);
150156
if (isReadOnly) {
151157
message.freezeDirect();
152158
}
153-
Object[] args = new Object[]{message, bHttpHeaders, bHubController};
159+
Object[] args = nativeHubService.getMethodArgs(ON_UNSUBSCRIPTION, new InteropArgs(
160+
message, bHttpHeaders, bHubController));
154161
return invokeRemoteFunction(env, bHubService, args,
155162
"callOnUnsubscriptionMethod", ON_UNSUBSCRIPTION);
156163
}
157164

158165
public static Object callOnUnsubscriptionValidationMethod(Environment env, BObject adaptor,
159166
BMap<BString, Object> message, BObject bHttpHeaders) {
160-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
167+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
168+
BObject bHubService = nativeHubService.getBHubService();
161169
boolean isReadOnly = isReadOnlyParam(bHubService, ON_UNSUBSCRIPTION_VALIDATION);
162170
if (isReadOnly) {
163171
message.freezeDirect();
164172
}
165-
Object[] args = new Object[]{message, bHttpHeaders};
173+
Object[] args = nativeHubService.getMethodArgs(ON_UNSUBSCRIPTION_VALIDATION,
174+
new InteropArgs(message, bHttpHeaders));
166175
return invokeRemoteFunction(env, bHubService, args, "callOnUnsubscriptionValidationMethod",
167176
ON_UNSUBSCRIPTION_VALIDATION);
168177
}
169178

170179
public static Object callOnUnsubscriptionIntentVerifiedMethod(Environment env, BObject adaptor,
171180
BMap<BString, Object> message, BObject bHttpHeaders) {
172-
BObject bHubService = (BObject) adaptor.getNativeData(SERVICE_OBJECT);
181+
NativeHubService nativeHubService = (NativeHubService) adaptor.getNativeData(NATIVE_HUB_SERVICE);
182+
BObject bHubService = nativeHubService.getBHubService();
173183
boolean isReadOnly = isReadOnlyParam(bHubService, ON_UNSUBSCRIPTION_INTENT_VERIFIED);
174184
if (isReadOnly) {
175185
message.freezeDirect();
176186
}
177-
Object[] args = new Object[]{message, bHttpHeaders};
187+
Object[] args = nativeHubService.getMethodArgs(ON_UNSUBSCRIPTION_INTENT_VERIFIED,
188+
new InteropArgs(message, bHttpHeaders));
178189
return invokeRemoteFunction(env, bHubService, args, "callOnUnsubscriptionIntentVerifiedMethod",
179190
ON_UNSUBSCRIPTION_INTENT_VERIFIED);
180191
}

0 commit comments

Comments
 (0)