Re: [DEV] Can we bind custom interceptors in msf4j2.3.0-m2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: [DEV] Can we bind custom interceptors in msf4j2.3.0-m2

Thusitha Thilina Dayaratne
Hi Ishara,

IMHO this is a valid requirement. But as Vidura mentioned ATM we don;t support dynamic binding from MSF4J. 
So we need to implement this from MSF4J level. Then we can provide the ability to add/remove interceptors at the runtime.

@Azeez, Kishanthan WDYT?

Thanks
Thusitha


On Mon, Jun 5, 2017 at 4:39 AM, Ishara Cooray <[hidden email]> wrote:
+ architecture

I
f you are asking about the dynamic interceptors similar to the dynamic binding of filters in JAX-RS spec [1],  MSF4J currently do not support dynamic binding of interceptors.



Yes,

We need a way to bind Interceptors which are coming from a configuration.
But that also has to be per service , not the global.

Because
For instance, We have the publisher REST API implemented as a micro service.
We need to secure this service using interceptors. Further, we are planning to have one interceptor per authentication type(BasicAuth, OAuth2, etc.).

Now, if someone need to add a custom authenticator, it should be possible to write a custom authentication interceptor and plug it into the Microservice.

Can this be supported?

Thanks & Regards,
Ishara Cooray
Senior Software Engineer
Mobile : <a href="tel:+94%2077%20262%209512" value="+94772629512" target="_blank">+9477 262 9512
WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware

On Thu, Jun 1, 2017 at 2:25 PM, Vidura Nanayakkara <[hidden email]> wrote:
Hi Ishara,

So, can we have the support to be able to plug custom interceptors for microservices?
 
I
f you are asking about the dynamic interceptors similar to the dynamic binding of filters in JAX-RS spec [1],  MSF4J currently do not support dynamic binding of interceptors.



Best Regards,
Vidura Nanayakkara

On Thu, Jun 1, 2017 at 1:19 PM, Ishara Cooray <[hidden email]> wrote:
Thanks for the clarification Vidura.

So, can we have the support to be able to plug custom interceptors for microservices?
 

Thanks & Regards,
Ishara Cooray
Senior Software Engineer
Mobile : <a href="tel:+94%2077%20262%209512" value="+94772629512" target="_blank">+9477 262 9512
WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware

On Thu, Jun 1, 2017 at 1:02 PM, Vidura Nanayakkara <[hidden email]> wrote:
Hi Ishara,

On Thu, Jun 1, 2017 at 12:29 PM, Ishara Cooray <[hidden email]> wrote:
According to the new Interceptor support in msf4j-2.3.0-m2

AFAIU,
We can bind interceptors for a given microservice as below.

InterceptorService is the micro service that is going to be intercepted by RequestInterceptors and Responseinterceptors annotated by 
@RequestInterceptor and @ResponseInterceptor                
@Component(
        name = "InterceptorService",
        service = Microservice.class,
        immediate = true
)
@Path("/interceptor-service")
public class InterceptorService implements Microservice {
    

    private static final Logger log = LoggerFactory.getLogger(InterceptorService.class);
    

    /**
     * Method for getting the micro-service name.
     *
     * @return name of the micro-service.
     */
    @GET
    @Path("/service-name")
    @RequestInterceptor(
​​
HTTPRequestLogger
.class) @ResponseInterceptor(HTTPResponseLogger.class) public String getServiceName() { log.info("HTTP Method Execution - getServiceName()"); return "WSO2 Service"; } }
1. Can we use @RequestInterceptor and @ResponseInterceptor annotations to the class level so that it will apply for every resource invocation?

​Yes, you can use @RequestInterceptor and @ResponseInterceptor to the class level so that it will apply to every resource invocation in the service.

Example:

@Path("/stockquote")
@RequestInterceptor(
HTTPRequestLogger.class)
@ResponseInterceptor({HTTPResponseLogger.class, LogTextResponseInterceptor.class})
public class StockQuoteService {
// Your resource methods here
}
Furthermore, if you want to apply the interceptors to all the services in a micro-service in OSGi mode please refer [1] and for non-OSGi mode please refer [2] and [3]. 

2. Can we plug a custom request/response interceptors?

 Can it be supported something similar to below.
 We have a class called ABCRequestInterceptor which implements RequestInterceptor and there can be classes that extends
 ABCRequestInterceptor

But , we bind the interceptor as
 @RequestInterceptor(ABCRequestInterceptor.class)
Will this bind extended Interceptors too to the InterceptorService?

​In this case the ABCRequestInterceptor will be the interceptor which gets executed. Please note that the other interceptors which is extended from this class do not get executed​ (The class you mention in the annotation is taken exactly as it is)



Thanks & Regards,
Ishara Cooray
Senior Software Engineer
Mobile : <a href="tel:+94%2077%20262%209512" value="+94772629512" target="_blank">+9477 262 9512
WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware



Best Regards,
Vidura Nanayakkara

--
Best Regards,

Vidura Nanayakkara
Software Engineer

Mobile : <a href="tel:+94%2071%20791%209277" value="+94717919277" target="_blank">+94 (0) 717 919277




--
Best Regards,

Vidura Nanayakkara
Software Engineer

Mobile : <a href="tel:+94%2071%20791%209277" value="+94717919277" target="_blank">+94 (0) 717 919277




--
Thusitha Dayaratne
WSO2 Inc. - lean . enterprise . middleware |  wso2.com

Mobile  +94712756809



_______________________________________________
Architecture mailing list
[hidden email]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture