-
Notifications
You must be signed in to change notification settings - Fork 66
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
HTTP annotations allow mutable objects #4300
Comments
I see. We can change it to |
Had a chat with @jclark @shafreenAnfar @MaryamZi @hasithaa and came up with the below solution for configuring interceptors rather than having it in the annotation. import ballerina/http;
// This service type will be a part of `http` module.
public type InterceptableService distinct service object {
*http:Service;
function intercetors() returns http:Interceptor[];
};
service class MyRequestInterceptor {
*http:RequestInterceptor;
resource function 'default [string... path](http:RequestContext ctx)
returns http:NextService|error? {
return ctx.next();
}
}
service class MyResponseInterceptor {
*http:ResponseInterceptor;
remote function interceptResponse(http:RequestContext ctx)
returns http:NextService|error? {
return ctx.next();
}
}
// Making the service as a part of `InterceptorableService` will validate the
// the availability of the `interceptors` function with the matching signature
service InterceptableService / on new http:Listener(9090) {
function intercetors() returns [MyRequestInterceptor, MyResponseInterceptor] {
return [new MyRequestInterceptor(), new MyResponseInterceptor()];
}
resource function get hello() returns string {
return "Hello, World!";
}
} |
@shafreenAnfar Having second thoughts on having a function because of the following concerns:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
@shafreenAnfar @dilanSachi and myself had a discussion on the above comments and decided on the following:
So in order to add this service level interceptor change we have to do the following tasks:
@dilanSachi can you check the above tasks and create a separate issue to track the progress of this change? |
For the listener we could do something like this as defining a function type: import ballerina/http;
service class MyRequestInterceptor {
*http:RequestInterceptor;
resource function 'default [string... path](http:RequestContext ctx) returns http:NextService|error? {
return ctx.next();
}
}
service class MyResponseInterceptor {
*http:ResponseInterceptor;
remote function interceptResponse(http:RequestContext ctx) returns http:NextService|error? {
return ctx.next();
}
}
// Ideally, this will be a part of `http` module
public type CreateInterceptorsFunction function () returns http:Interceptor[];
// The function implementation. Note the tuple return type.
function createInterceptors() returns [MyResponseInterceptor, MyRequestInterceptor] {
return [new MyResponseInterceptor(), new MyRequestInterceptor()];
}
// This class is just to mock the `http:Listener`
public class Listener {
http:Interceptor[] interceptors;
int port;
function init(int port, CreateInterceptorsFunction interceptors) {
self.port = port;
self.interceptors = interceptors();
}
}
Listener serverEP = new(9090, interceptors = createInterceptors); |
We have currently deprecated the usage of |
This issue has been fixed now |
Description:
The spec requires the type in annotations to be a subtype of
true
,map<value:Cloneable>
, ormap<value:Cloneable>[]
. But the jBallerina implementation allowed mutable object since stdlib annotations used mutable objects. This was tracked by #74 and since that seemed to have been fixed we tried updating this validation in the compiler, but it seems like there are new mutable objects now -http:Inteceptor
.Affected Versions:
2.6.0
Related Issues (optional):
#74
The text was updated successfully, but these errors were encountered: