diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomRoutersGatewayApplication.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomRoutersGatewayApplication.java index b7897edfa3..18a36952fd 100644 --- a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomRoutersGatewayApplication.java +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomRoutersGatewayApplication.java @@ -8,8 +8,8 @@ public class CustomRoutersGatewayApplication { public static void main(String[] args) { new SpringApplicationBuilder(CustomRoutersGatewayApplication.class) - .profiles("customroutes") - .run(args); + .profiles("customroutes") + .run(args); } } \ No newline at end of file diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java index ec75f2152c..0e88b29bcf 100644 --- a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java @@ -24,15 +24,15 @@ public class CustomPredicatesConfig { public RouteLocator routes(RouteLocatorBuilder builder, GoldenCustomerRoutePredicateFactory gf ) { return builder.routes() - .route("dsl_golden_route", r -> r.path("/dsl_api/**") - .filters(f -> f.stripPrefix(1)) - .uri("https://httpbin.org") - .predicate(gf.apply(new Config(true, "customerId")))) - .route("dsl_common_route", r -> r.path("/dsl_api/**") - .filters(f -> f.stripPrefix(1)) - .uri("https://httpbin.org") - .predicate(gf.apply(new Config(false, "customerId")))) - .build(); + .route("dsl_golden_route", r -> r.path("/dsl_api/**") + .filters(f -> f.stripPrefix(1)) + .uri("https://httpbin.org") + .predicate(gf.apply(new Config(true, "customerId")))) + .route("dsl_common_route", r -> r.path("/dsl_api/**") + .filters(f -> f.stripPrefix(1)) + .uri("https://httpbin.org") + .predicate(gf.apply(new Config(false, "customerId")))) + .build(); } } diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java index a60932bd91..cb5c3a0b50 100644 --- a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java @@ -41,27 +41,25 @@ public class GoldenCustomerRoutePredicateFactory extends AbstractRoutePredicateF return (ServerWebExchange t) -> { List cookies = t.getRequest() - .getCookies() - .get(config.getCustomerIdCookie()); + .getCookies() + .get(config.getCustomerIdCookie()); - boolean isGolden; - if ( cookies == null || cookies.isEmpty()) { - isGolden = false; - } - else { - String customerId = cookies.get(0).getValue(); - isGolden = goldenCustomerService.isGoldenCustomer(customerId); - } + boolean isGolden; + if ( cookies == null || cookies.isEmpty()) { + isGolden = false; + } + else { + String customerId = cookies.get(0).getValue(); + isGolden = goldenCustomerService.isGoldenCustomer(customerId); + } - return config.isGolden()?isGolden:!isGolden; + return config.isGolden()?isGolden:!isGolden; }; - } @Validated - public static class Config { - + public static class Config { boolean isGolden = true; @NotEmpty