From eab254a5f438edcf7b0973ff8fdc4e02159354c9 Mon Sep 17 00:00:00 2001 From: regadas Date: Thu, 27 Apr 2023 01:14:36 +0100 Subject: [PATCH] Fix: random ParserException with routing rules engine --- .../ha/router/RoutingGroupSelector.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gateway-ha/src/main/java/com/lyft/data/gateway/ha/router/RoutingGroupSelector.java b/gateway-ha/src/main/java/com/lyft/data/gateway/ha/router/RoutingGroupSelector.java index e1aa06e5..c0551911 100644 --- a/gateway-ha/src/main/java/com/lyft/data/gateway/ha/router/RoutingGroupSelector.java +++ b/gateway-ha/src/main/java/com/lyft/data/gateway/ha/router/RoutingGroupSelector.java @@ -37,23 +37,22 @@ static RoutingGroupSelector byRoutingRulesEngine(String rulesConfigPath) { RulesEngine rulesEngine = new DefaultRulesEngine(); MVELRuleFactory ruleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader()); - return request -> { - try { - Rules rules = ruleFactory.createRules( - new FileReader(rulesConfigPath)); + try { + Rules rules = ruleFactory.createRules(new FileReader(rulesConfigPath)); + + return request -> { Facts facts = new Facts(); HashMap result = new HashMap(); facts.put("request", request); facts.put("result", result); rulesEngine.fire(rules, facts); return result.get("routingGroup"); - } catch (Exception e) { - Logger.log.error("Error opening rules configuration file," - + " using routing group header as default.", e); - return Optional.ofNullable(request.getHeader(ROUTING_GROUP_HEADER)) - .orElse(request.getHeader(ALTERNATE_ROUTING_GROUP_HEADER)); - } - }; + }; + } catch (Exception e) { + Logger.log.error("Error opening rules configuration file," + + " using routing group header as default.", e); + return byRoutingGroupHeader(); + } } /**