spring-cloud-gateway
spring-cloud-gateway copied to clipboard
Gateway gives error while reading response from GRPC requests "ResponseFacade cannot be cast to class HttpServerResponse"
I have configured the api gateway with grpc. The requests route correctly to the grpc url, however gateway is unable to read the response and it fails with below error
<html>
<body>
<!--StartFragment-->
java.lang.ClassCastException: class org.apache.catalina.connector.ResponseFacade cannot be cast to class reactor.netty.http.server.HttpServerResponse (org.apache.catalina.connector.ResponseFacade and reactor.netty.http.server.HttpServerResponse are in unnamed module of loader org.springframework.boot.loader.launch.LaunchedClassLoader @378fd1ac)
--
| at org.springframework.cloud.gateway.filter.headers.GRPCResponseHeadersFilter.filter(GRPCResponseHeadersFilter.java:56) ~[spring-cloud-gateway-server-4.1.0.jar!/:4.1.0]
| Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
| Error has been observed at the following site(s):
| *__checkpoint ? org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
| *__checkpoint ? AuthorizationWebFilter [DefaultWebFilterChain]
| *__checkpoint ? ExceptionTranslationWebFilter [DefaultWebFilterChain]
| *__checkpoint ? LogoutWebFilter [DefaultWebFilterChain]
| *__checkpoint ? ServerRequestCacheWebFilter [DefaultWebFilterChain]
| *__checkpoint ? SecurityContextServerWebExchangeWebFilter [DefaultWebFilterChain]
| *__checkpoint ? ReactorContextWebFilter [DefaultWebFilterChain]
| *__checkpoint ? HttpHeaderWriterWebFilter [DefaultWebFilterChain]
| *__checkpoint ? ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
| *__checkpoint ? org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
| *__checkpoint ? HTTP POST "/grpc-api/com.ds.test.adapter.grpc.generated.GraphDataService/fetchGraphIndex" [ExceptionHandlingWebHandler]
| Original Stack Trace:
| at org.springframework.cloud.gateway.filter.headers.GRPCResponseHeadersFilter.filter(GRPCResponseHeadersFilter.java:56) ~[spring-cloud-gateway-server-4.1.0.jar!/:4.1.0]
| at org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter.filter(HttpHeadersFilter.java:38) ~[spring-cloud-gateway-server-4.1.0.jar!/:4.1.0]
| at org.springframework.cloud.gateway.filter.NettyRoutingFilter.lambda$filter$4(NettyRoutingFilter.java:170) ~[spring-cloud-gateway-server-4.1.0.jar!/:4.1.0]
| at reactor.netty.http.client.HttpClientFinalizer.lambda$responseConnection$4(HttpClientFinalizer.java:102) ~[reactor-netty-http-1.1.16.jar!/:1.1.16]
| at reactor.core.publisher.MonoFlatMapMany$FlatMapManyMain.onNext(MonoFlatMapMany.java:163) ~[reactor-core-3.6.3.jar!/:3.6.3]
| at reactor.core.publisher.SerializedSubscriber.onNext(SerializedSubscriber.java:99) ~[reactor-core-3.6.3.jar!/:3.6.3]
| at reactor.core.publisher.FluxRetryWhen$RetryWhenMainSubscriber.onNext(FluxRetryWhen.java:178) ~[reactor-core-3.6.3.jar!/:3.6.3]
| at reactor.core.publisher.MonoCreate$DefaultMonoSink.success(MonoCreate.java:176) ~[reactor-core-3.6.3.jar!/:3.6.3]
<!--EndFragment-->
</body>
</html>
The api gateway config is as below
...
..
..
server:
port: 8080
http2:
enabled: true
spring:
application:
name: API Gateway
main:
banner-mode: "off"
web-environment: false
web-application-type: reactive
allow-bean-definition-overriding: true
allow-circular-references: true
cloud:
gateway:
filter:
remove-hop-by-hop:
headers:
- connection
- keep-alive
- transfer-encoding
- proxy-authenticate
- proxy-authorization
- x-application-context
- upgrade
httpclient:
wiretrap: true
ssl:
use-insecure-trust-manager: true
httpserver:
wiretrap: true
routes:
- id: grpc-test
uri: ${service_grpc_url:grpc://grpc-test:50053}
predicates:
- Path= /grpc-api/**
filters:
- RewritePath=/grpc-api(?<segment>/?.*), $\{segment}
..
..
..