Mercurial > stress-tester
changeset 467:f9c1c9d3fa0f
HttpMessageModificationFilter improvements
author | Devel 2 |
---|---|
date | Thu, 03 Aug 2017 10:53:14 +0200 |
parents | d76b45adf852 |
children | 39b770911027 |
files | stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java |
diffstat | 2 files changed, 13 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Thu Aug 03 10:21:23 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Thu Aug 03 10:53:14 2017 +0200 @@ -51,14 +51,7 @@ public abstract void process(HttpRequest req, HttpResponse resp, HttpFlowContext context); protected final CharSequence extractValue(ValueExtractor extractor, HttpRequest req, HttpResponse resp, HttpFlowContext context) { - Object value; - if (extractor instanceof UnmutableValueExtractor) { - value = extractor.extract(null); - } else { - HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, context); - value = extractor.extract(wrapper); - } - + Object value = HttpFiltersUtils.extractValue(extractor, req, resp, context); if (value instanceof CharSequence) { return (CharSequence) value; } @@ -320,7 +313,7 @@ if (name != null) { return params.remove(name); } - + return false; } @@ -512,7 +505,7 @@ } } - predicate = (HttpMessagePredicate) config.get("applyIf"); + predicate = (HttpMessagePredicate) config.get("applyIf", null); } public List<Operation> getOperations() { @@ -521,7 +514,7 @@ @Override public int filterOutbound(HttpRequest req, HttpResponse resp, HttpFlowContext context) { - if (!operations.isEmpty()) { + if (req != null && !operations.isEmpty()) { boolean exec = true; if (predicate != null) { HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, context); @@ -564,8 +557,7 @@ mapDef(tupleDef("$expr", valueDef())) ) ); - - + KeyNameVaryListNodeDefinition operationsDef = new KeyNameVaryListNodeDefinition() .setNodeTransformer(new HttpMessageModificationFilterTransformer()) .add("$removeHeader", valueDef().addValidator(HeaderNameValidator.INSTANCE))
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Thu Aug 03 10:21:23 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTransformer.java Thu Aug 03 10:53:14 2017 +0200 @@ -26,8 +26,6 @@ private final ExpressionNodeTransformer exprTransformer = new ExpressionNodeTransformer(); - private final ValueExtractorParser valueExtractorParser = new ValueExtractorParser(); - private Operation createNameOperation(CTupleNode tuple, Errors errors, Class<? extends Operation> clazz) { if (validateType(tuple.getNode(), NodeType.VALUE, errors)) { CValueNode valNode = (CValueNode) tuple.getNode(); @@ -48,27 +46,21 @@ CTupleNode valTupleNode = ((CMapNode) tuple.getNode()).getFirstChild(); if (valTupleNode != null) { ValueExtractor valueTransformer = null; - - if (valTupleNode.getNode().getType() == NodeType.VALUE) { + + CNode valNode = valTupleNode.getNode(); + if (valNode.getType() == NodeType.VALUE + || valNode.getType() == NodeType.MAP) { try { - CValueNode valNode = (CValueNode) valTupleNode.getNode(); - valueTransformer = valueExtractorParser.parse((String) valNode.getValue()); + valueTransformer = exprTransformer.transform(valNode); } catch (Exception e) { - errors.reject("Invalid value definition."); - return null; - } - } else if (valTupleNode.getNode().getType() == NodeType.MAP) { - try { - valueTransformer = exprTransformer.transform(valTupleNode); - } catch (Exception e) { - errors.reject("Invalid expression."); + errors.reject("Invalid expression.", valNode); return null; } } else { - errors.reject("Invalid node."); + errors.reject("Invalid node.", valNode); return null; } - + if (valueTransformer != null) { try { return clazz