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..e02c70ef 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 @@ -36,24 +36,21 @@ static RoutingGroupSelector byRoutingGroupHeader() { 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 { + final 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(); + } } /**