You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/05/28 09:49:45 UTC

[GitHub] [servicecomb-java-chassis] G-Jay-R opened a new issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

G-Jay-R opened a new issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396


   现象:同一个接口调用,在cse版本为2.4.x时返回 404;升级为3.1.7以后,返回405
   
   实现:我们代码中自定义了一个类,将405返回码改成了404;
   ```java
   public class NonSwagerDispatcher extends AbstractEdgeDispatcher {
         ...
         public int getOrder() {
           return 110;
        }
        ....
         protected void onFailure(RoutingContext context) {
             ...
             if (context.failure() instanceof InvocationException) {
                 InvocationException exception = (InvocationException) context
                     .failure();
                 if (exception.getStatusCode() == Response.Status.METHOD_NOT_ALLOWED
                     .getStatusCode()) {
                     //  将 405 改成了  404
                     return;
                  }
           }
   
         protected void onRequest(RoutingContext context) {
             ...
             context.next();
         }
       ....
   }
   ```
   我们排查以后发现,升级以后onFailure方法不再被调用,导致做的定制处理没被执行
   
   想请问这个没被执行的原因是什么,跟那个order的优先级有关系么


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-850797496


   你可以下载对应版本的源代码看下即可。 `onFailure` 是在实现类调用的, 以默认的 `DefaultEdgeDispatcher为例` 实现类需要显示的调用onFailure
   
   ```
     public void init(Router router) {
       prefix = DynamicPropertyFactory.getInstance().getStringProperty(KEY_PREFIX, "api").get();
       withVersion = DynamicPropertyFactory.getInstance().getBooleanProperty(KEY_WITH_VERSION, true).get();
       prefixSegmentCount = DynamicPropertyFactory.getInstance().getIntProperty(KEY_PREFIX_SEGMENT_COUNT, 1).get();
       String regex = generateRouteRegex(prefix, withVersion);
   
       // cookies handler are enabled by default start from 3.8.3
       router.routeWithRegex(regex).handler(createBodyHandler());
       router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
     }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R edited a comment on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R edited a comment on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-865453562


   405非异常,走不到onFailure里,这个可以用什么方式验证一下么,底层代码太多了,debug以后跑到一些看不懂的代码里~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-851103534


   估计得调试下, 看看是否在执行过程中没有抛出异常。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-866674707


   debug发现,没走到onFailure方法的原因是,RoutingContextImplBase类中第1行  failed()  返回值不同
   ```
   boolean iterateNext() {
       // 差异点
   1    boolean failed = failed();
   2   if (currentRoute != null) { // Handle multiple handlers inside route object
   3      try {
   4        if (!failed && currentRoute.hasNextContextHandler(this)) {
   5          currentRouteNextHandlerIndex.incrementAndGet();
   6          resetMatchFailure();
   7          currentRoute.handleContext(this);
   8          return true;
   9        } else if (failed && currentRoute.hasNextFailureHandler(this)) {
   10          currentRouteNextFailureHandlerIndex.incrementAndGet();
   11          currentRoute.handleFailure(this);
   12          return true;
           }
         }
   ```
   failed() 在未升级前返回 true,升级后返回false,11行无法执行则onFailure也无法执行
   升级后的 failed()  返回 true 原因是因为返回的 405 被作为了异常了,而升级以后则没有被处理
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-867258790


   谢谢反馈。 那应该就是vert.x的新版本修改了这里的行为。 我个人感觉这个处理是合理的。 建议你们的逻辑做适当调整,不要依赖于早期的行为。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R edited a comment on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R edited a comment on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-866674707


   debug发现,没走到onFailure方法的原因是,RoutingContextImplBase类中第1行  failed()  返回值不同
   ```
   boolean iterateNext() {
       // 差异点
   1    boolean failed = failed();
   2   if (currentRoute != null) { // Handle multiple handlers inside route object
   3      try {
   4        if (!failed && currentRoute.hasNextContextHandler(this)) {
   5          currentRouteNextHandlerIndex.incrementAndGet();
   6          resetMatchFailure();
   7          currentRoute.handleContext(this);
   8          return true;
   9        } else if (failed && currentRoute.hasNextFailureHandler(this)) {
   10          currentRouteNextFailureHandlerIndex.incrementAndGet();
   11          currentRoute.handleFailure(this);
   12          return true;
           }
         }
   ```
   failed() 在未升级前返回 true,升级后返回false,11行无法执行则onFailure也无法执行
   升级后的 failed()  返回 true 原因是因为返回的 405 被作为了异常了,而升级以后则没有被处理
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-861940233


   edgeservice后的服务返回了405的响应码,属于异常么?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R edited a comment on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R edited a comment on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-866674707


   debug发现,没走到onFailure方法的原因是,RoutingContextImplBase类中第1行  failed()  返回值不同
   ```
   boolean iterateNext() {
       // 差异点
   1    boolean failed = failed();
   2   if (currentRoute != null) { // Handle multiple handlers inside route object
   3      try {
   4        if (!failed && currentRoute.hasNextContextHandler(this)) {
   5          currentRouteNextHandlerIndex.incrementAndGet();
   6          resetMatchFailure();
   7          currentRoute.handleContext(this);
   8          return true;
   9        } else if (failed && currentRoute.hasNextFailureHandler(this)) {
   10          currentRouteNextFailureHandlerIndex.incrementAndGet();
   11          currentRoute.handleFailure(this);
   12          return true;
           }
         }
   ```
   failed() 在未升级前返回 true,升级后返回false,11行无法执行则onFailure也无法执行
   升级后的 failed()  返回 true 原因是因为返回的 405 被作为了异常了,而升级以后则没有被处理
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-850814073


   在此类NonSwagerDispatcher中完成了调用的:
   ```java
   @Override
       public void init(Router router) {
           String regex = "(?!.*edgeservice).*";
   
           urlDispatcherService = BeanUtils.getBean("urlDispatcherService");
   
           // CSE框架依赖
           router.routeWithRegex(regex).handler(CookieHandler.create());
   
           router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
       }
   ```
   不明白为什么没有执行?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-865453562


   405非异常,走不到onFailure里,这个可以用什么方式验证一下么,底层代码太多了,debug以后跑到一些看不懂的代码里~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] G-Jay-R commented on issue #2396: CSE升级后,自定义的错误处理机制方法失效,类继承AbstractEdgeDispatcher

Posted by GitBox <gi...@apache.org>.
G-Jay-R commented on issue #2396:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2396#issuecomment-865453562


   405非异常,走不到onFailure里,这个可以用什么方式验证一下么,底层代码太多了,debug以后跑到一些看不懂的代码里~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org