- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
Fix the ClassCastException when CacheRequestBodyFilter is used with CircuitBreakerFilter. #3547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix the ClassCastException when CacheRequestBodyFilter is used with CircuitBreakerFilter. #3547
Conversation
…Body in ServerWebExchangeUtils
…ircuitBreakerFilter.
| I'm afraid, I still don't understand the reason for this change. It is also a breaking change, so this is something that will not happen soon. | 
| @spencergibb Thank you for your quick reply. This issue arises because the  .route(
       r -> r.order(-2000).path("/routeTest")
             .filters(f -> f.cacheRequestBody(String.class))
             .uri("forward:/cacheBodyTest"))
.route(
       r -> r.order(-2000).path("/cacheBodyTest")
             .uri("http://127.0.0.1:8888"))I understand this is a breaking change, and I will follow your arrangements. | 
…rcuit-breaker-cce # Conflicts: # spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/support/ServerWebExchangeUtils.java
Currently, the
CacheRequestBodyFilteroverrides theCACHED_REQUEST_BODY_ATTRattribute with the decoded object. If thefallbackUriof the CircuitBreaker is routed to another route, passing through theAdaptCachedBodyGlobalFiltertriggers a ClassCastException(see unit test). TheCacheRequestBodyFilterbehaves similarly to aReadBodyRoutePredicateFactorywithout a predicate. The current modification places the decoded body into CACHE_REQUEST_BODY_OBJECT_KEY to distinguish the responsibilities.