HeaderFunctions { public static HeaderFunction parseFromJson(JsonArray config) throws IllegalArgumentException { LOG.debug("creating header function chain from " + config); Consumer<EvalScope> chain = null; for (int pos = 0; pos < config.size(); pos++) { JsonObject rule = config.getJsonObject(pos); Consumer<EvalScope> c = parseOneFromJason(config, rule); chain = (chain == null) ? c : chain.andThen(c); } return wrapConsumerChain(chain); }  static HeaderFunction parseFromJson(JsonArray config); @Deprecated static HeaderFunction parseStaticHeadersFromJson(JsonObject staticHeaders); static Consumer<EvalScope> remove(String headerName); static Consumer<EvalScope> setAlways(String headerName, String expression); static Consumer<EvalScope> setIfAbsent(String headerName, String expression); static Consumer<EvalScope> setIfPresent(String headerName, String expression); static final HeaderFunction DO_NOTHING; }
@Test public void testJsonConfigParser() { String json = "[" + " { 'header': 'xxx' , 'value': '111' }," + " { 'header': 'yyy' , 'value': '222' }," + " { 'header': 'yyy' , 'value': '333' , 'mode': 'complete' }," + " { 'header': 'zzz' , 'value': '444' , 'mode': 'override' }," + " { 'header': 'oli' , 'value': '{xxx}-{yyy}' }," + " { 'header': 'xxx' , 'value': null }," + " { 'header': 'preSuff', 'value': 'pre-{yyy}-suff' }," + " { 'header': 'aaa' , 'value': 'yes' }," + " { 'header': 'aaa' , 'value': '' } " + "]"; json = json.replace('\'', '"'); JsonArray config = new JsonArray(json); HeaderFunction chain = HeaderFunctions.parseFromJson(config); MultiMap headers = new CaseInsensitiveHeaders(); final EvalScope evalScope = chain.apply(headers); Assert.assertFalse(headers.contains("xxx")); Assert.assertFalse(headers.contains("zzz")); Assert.assertEquals("222" , headers.get("yyy" )); Assert.assertEquals("111-222" , headers.get("oli" )); Assert.assertEquals("pre-222-suff", headers.get("preSuff")); Assert.assertNull("no eval error occured", evalScope.getErrorMessage()); Assert.assertFalse(headers.contains("aaa")); }