Question about CommonFilter
Issue Description
Type: bug report or feature request
Describe what happened (or what feature you want)
@sczyh30 i try to integrate spring-cloud-starter-alibaba-sentinel(0.1.2.RELEASE) to test the FlowControl function,in my program, i wrote test code like this
@SentinelResource(value ="clusterFlowControl")
public int clusterFlowControlTest(int i) throws BlockException{
return i;
}
and the flow control works。
but i try to set all the request blocked by Sentinel a common response,so i wrote my own UrlBlockHandler and register it to WebCallbackManager。
the situation is that i found that in com.alibaba.csp.sentinel.adapter.servlet.CommonFilter,when flow control happens,the BlockException was wrapped by FrameworkServlet,so the BlockException changed to NestedServletException,only BlockException will be catched and use UrlBlockHandler to customize a response, so my own UrlBlockHandler does not work
spring-webmvc-4.3.13.RELEASE-sources.jar!/org/springframework/web/servlet/FrameworkServlet.java:980
try {
doService(request, response);
}
catch (ServletException ex) {
failureCause = ex;
throw ex;
}
catch (IOException ex) {
failureCause = ex;
throw ex;
}
catch (Throwable ex) {
// BlockException was wrapped here
failureCause = ex;
throw new NestedServletException("Request processing failed", ex);
}
it might be a problem of excution orders of filters and servlets,and i want to know how to solve this problem
Describe what you expected to happen
there will be BlockException catched in com.alibaba.csp.sentinel.adapter.servlet.CommonFilter ,not NestedServletException
How to reproduce it (as minimally and precisely as possible)
Tell us your environment
spring-cloud-starter-alibaba-sentinel(0.1.2.RELEASE) springboot(1.5.9.RELEASE)
Anything else we need to know?
Using CommonFilter of sentinel-web-servlet, each incoming different URL will be treated as a different resource, so we may needn't use @SentinelResource.
If use @SentinelResource, seems no need to use CommonFilter, suggest use blockHandler / blockHandlerClass, fallback, defaultFallback to do custorm block logic.
@see https://github.com/alibaba/Sentinel/wiki/注解支持#sentinelresource-注解
If use them together, the BlockException thrown by aop of @SentinelResource will be firstly catch by FrameworkServlet of SpringMVC, and it wrapped to NestedServletException(which is not RuntimeException), and UrlBlockHandler take no effect.
Using
CommonFilterofsentinel-web-servlet, each incoming different URL will be treated as a different resource, so we may needn't use@SentinelResource.If use
@SentinelResource, seems no need to useCommonFilter, suggest useblockHandler / blockHandlerClass,fallback,defaultFallbackto do custorm block logic. @see https://github.com/alibaba/Sentinel/wiki/注解支持#sentinelresource-注解If use them together, the
BlockExceptionthrown by aop of@SentinelResourcewill be firstly catch byFrameworkServletof SpringMVC, and it wrapped toNestedServletException(which is not RuntimeException), andUrlBlockHandlertake no effect.
thanks for your anwser,so if i use CommonFilter,and i want to limit the Qps of some method , the resouceName (which i config in the sentinel dashboard) will be exactly the method name?
for example , the method is
public int clusterFlowControlTest(int i) throws BlockException{
return i;
}
and resouceName will be clusterFlowControlTest ?
CommonFilter is used for web servlet adaptation, e.g. If use SpringMVC, the full path declared in @RequestMapping of Controller will be marked as resourceName, other methods will not be treated as resource.
CommonFilteris used for web servlet adaptation, e.g. If use SpringMVC, the full path declared in@RequestMappingofControllerwill be marked asresourceName, other methods will not be treated as resource.
thanks and i will have a try