Hi Ishara,

On Thu, Jun 1, 2017 at 12:29 PM, Ishara Cooray <[email protected]> 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 : +9477 262 9512 <+94%2077%20262%209512>
> WSO2, Inc. | http://wso2.com/
> Lean . Enterprise . Middleware
>


​[1]
https://github.com/wso2/msf4j/blob/release-2.3.0-m1/samples/interceptor/osgi-interceptor-service/README.md
​
[2]
https://github.com/wso2/msf4j/tree/release-2.3.0-m1/samples/interceptor/fatjar-interceptor-service
[3]
https://github.com/wso2/msf4j/blob/release-2.3.0-m1/samples/interceptor/fatjar-interceptor-service/src/main/java/org/wso2/msf4j/samples/fatjarinterceptorservice/Application.java

Best Regards,
Vidura Nanayakkara

-- 
Best Regards,

*Vidura Nanayakkara*
Software Engineer

Email : [email protected]
Mobile : +94 (0) 717 919277
Web : http://wso2.com
Blog : https://medium.com/@viduran
LinkedIn : https://lk.linkedin.com/in/vidura-nanayakkara
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to