From 831008f42d028ef3feae3e58794a6590d401144a Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Fri, 27 Jul 2018 16:08:29 -0400 Subject: [PATCH] Handle ClassCastException --- .../handler/predicate/ReadBodyPredicateFactory.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/ReadBodyPredicateFactory.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/ReadBodyPredicateFactory.java index 798d09460..621d2f243 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/ReadBodyPredicateFactory.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/handler/predicate/ReadBodyPredicateFactory.java @@ -60,8 +60,12 @@ public class ReadBodyPredicateFactory Object cachedBody = exchange.getAttribute(CACHE_REQUEST_BODY_OBJECT_KEY); Mono modifiedBody; if(cachedBody != null) { - boolean test = config.predicate.test(cachedBody); - exchange.getAttributes().put(TEST_ATTRIBUTE, test); + try { + boolean test = config.predicate.test(cachedBody); + exchange.getAttributes().put(TEST_ATTRIBUTE, test); + } catch(ClassCastException e) { + //predicate test failed because class in predicate does not match the cached body object + } modifiedBody = Mono.just(cachedBody); } else { ServerRequest serverRequest = new DefaultServerRequest(exchange);