当Content-Length标头为0时,WebFilter的doOnSuccessOrError使用者不起作用[Spring Cloud Gateway]

时间:2018-09-20 06:54:20

标签: spring-cloud spring-cloud-gateway

public class MainActivity extends AppCompatActivity { int count=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout parentLayout = (LinearLayout) findViewById(R.id.linearLayout); int elements = parentLayout.getChildCount(); View v = null; for(int i=0; i<elements; i++) { v = parentLayout.getChildAt(i); if(v.getTag()!=null && v.getTag().equals("et")){ count= count++; } } } } 标头为0时,WebFilter的doOnSuccessOrErrordoAfterSuccessOrError使用者不工作。

我的WebFilter如下:

Content-Length

网关使用以下配置将所有流量路由到tomcat应用程序:

@Bean
WebFilter webFilter() {
  return (exchange, chain) ->
      chain.filter(exchange)
          .doOnRequest(value -> {
            logger.error("webFilter" + " doOnRequest");
          })
          .doOnSuccessOrError((aVoid, throwable) -> {
            logger.error("webFilter" + " doOnSuccessOrError");
          })
          .doAfterSuccessOrError((aVoid, throwable) -> {
            logger.error("webFilter" + " doAfterSuccessOrError");
          });
}

我在spring boot tomcat应用程序上具有以下三个端点:

@Bean
public RouteLocator routeLocator(RouteLocatorBuilder builder) {
  return builder.routes()
      .route(r -> r.path("/**")
          .uri("http://localhost:9001").filter(gatewayFilter()))
      .build();
}

通过网关对@GetMapping("/redirect") public ModelAndView redirectWithUsingRedirectPrefix(ModelMap model) { return new ModelAndView("redirect:http://google.com", model); } @GetMapping("/empty-response") public ResponseEntity<Void> responseEntity() { return ResponseEntity.ok().build(); } @GetMapping("/foo") public ResponseEntity<String> string() { return ResponseEntity.ok("foo"); } 的请求按预期工作

/foo

对于[ctor-http-nio-2] GatewayConfiguration : webFilter doOnRequest [ctor-http-nio-2] GatewayConfiguration : globalFilter doOnRequest [ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnRequest [ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnSuccessOrError [ctor-http-nio-3] GatewayConfiguration : globalFilter doOnSuccessOrError [ctor-http-nio-3] GatewayConfiguration : globalFilter doAfterSuccessOrError [ctor-http-nio-3] GatewayConfiguration : gatewayFilter doAfterSuccessOrError [ctor-http-nio-2] GatewayConfiguration : webFilter doOnSuccessOrError [ctor-http-nio-2] GatewayConfiguration : webFilter doAfterSuccessOrError

/empty-response

[ctor-http-nio-4] GatewayConfiguration : webFilter doOnRequest [ctor-http-nio-4] GatewayConfiguration : globalFilter doOnRequest [ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnRequest [ctor-http-nio-3] GatewayConfiguration : gatewayFilter doOnSuccessOrError [ctor-http-nio-3] GatewayConfiguration : globalFilter doOnSuccessOrError [ctor-http-nio-3] GatewayConfiguration : globalFilter doAfterSuccessOrError [ctor-http-nio-3] GatewayConfiguration : gatewayFilter doAfterSuccessOrError GlobalFilter可以正常工作。但是,如您所见,GatewayFilter中缺少webFilter doOnSuccessOrErrorwebFilter doAfterSuccessOrError。对于/empty-response终结点相同。

您可以使用enter image description here复制它。

0 个答案:

没有答案