changeset 743:b405a798b5b1

FieldExtractorFactory -> ValueExtractorResolver
author Devel 1
date Thu, 07 Dec 2017 10:12:10 +0100
parents 28a21c9c2bf2
children 50e2a0229e7b
files stress-tester/src/main/java/com/passus/st/filter/HttpMessageFieldExtractorFactory.java stress-tester/src/main/java/com/passus/st/filter/HttpMessageValueExtractorResolver.java stress-tester/src/main/java/com/passus/st/filter/Transformers.java stress-tester/src/main/java/com/passus/st/vars/VarsCompiler.java stress-tester/src/main/java/com/passus/st/vars/VarsValueExtractorResolver.java
diffstat 5 files changed, 68 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/filter/HttpMessageFieldExtractorFactory.java	Wed Dec 06 15:09:02 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-package com.passus.st.filter;
-
-import com.passus.filter.ValueExtractor;
-import com.passus.filter.config.DefaultFieldExtractorFactory;
-import com.passus.filter.config.FieldExtractorFactory;
-
-/**
- *
- * @author mikolaj.podbielski
- */
-public class HttpMessageFieldExtractorFactory implements FieldExtractorFactory {
-
-    private final FieldExtractorFactory extractorFactory = new DefaultFieldExtractorFactory();
-
-    @Override
-    public ValueExtractor createFieldExtractor(String fieldName) {
-        ValueExtractor fieldExtractor = extractorFactory.createFieldExtractor(fieldName);
-        HttpMessageHeaderValueExtractor.Operation operation = HttpMessageHeaderValueExtractor.createForFunction(fieldName);
-        if (operation != null) {
-            return new HttpMessageHeaderValueExtractor(operation, fieldExtractor);
-        } else {
-            return new HttpMessageValueExtractor(fieldName, fieldExtractor);
-        }
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/filter/HttpMessageValueExtractorResolver.java	Thu Dec 07 10:12:10 2017 +0100
@@ -0,0 +1,26 @@
+package com.passus.st.filter;
+
+import com.passus.filter.ValueExtractor;
+import com.passus.filter.config.DefaultValueExtractorResolver;
+import com.passus.filter.config.ValueExtractorResolver;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public class HttpMessageValueExtractorResolver implements ValueExtractorResolver {
+
+    private final ValueExtractorResolver extractorFactory = new DefaultValueExtractorResolver();
+
+    @Override
+    public ValueExtractor resolveValueExtractor(String fieldName) {
+        ValueExtractor valueExtractor = extractorFactory.resolveValueExtractor(fieldName);
+        HttpMessageHeaderValueExtractor.Operation operation = HttpMessageHeaderValueExtractor.createForFunction(fieldName);
+        if (operation != null) {
+            return new HttpMessageHeaderValueExtractor(operation, valueExtractor);
+        } else {
+            return new HttpMessageValueExtractor(fieldName, valueExtractor);
+        }
+    }
+
+}
--- a/stress-tester/src/main/java/com/passus/st/filter/Transformers.java	Wed Dec 06 15:09:02 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/filter/Transformers.java	Thu Dec 07 10:12:10 2017 +0100
@@ -2,8 +2,8 @@
 
 import com.passus.filter.ValueExtractorParser;
 import com.passus.filter.config.ExpressionNodeTransformer;
-import com.passus.filter.config.FieldExtractorFactory;
 import com.passus.filter.config.PredicateNodeTransformer;
+import com.passus.filter.config.ValueExtractorResolver;
 
 /**
  *
@@ -11,7 +11,7 @@
  */
 public class Transformers {
 
-    public static final FieldExtractorFactory FIELD_EXTRACTOR_FACTORY = new HttpMessageFieldExtractorFactory();
+    public static final ValueExtractorResolver FIELD_EXTRACTOR_FACTORY = new HttpMessageValueExtractorResolver();
 
     public static final PredicateNodeTransformer PREDICATE = new PredicateNodeTransformer(FIELD_EXTRACTOR_FACTORY);
 
--- a/stress-tester/src/main/java/com/passus/st/vars/VarsCompiler.java	Wed Dec 06 15:09:02 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/vars/VarsCompiler.java	Thu Dec 07 10:12:10 2017 +0100
@@ -3,8 +3,8 @@
 import com.passus.commons.Assert;
 import com.passus.data.ByteBuffUtils;
 import com.passus.filter.ValueExtractor;
-import com.passus.filter.config.DefaultFieldExtractorFactory;
-import com.passus.filter.config.FieldExtractorFactory;
+import com.passus.filter.config.DefaultValueExtractorResolver;
+import com.passus.filter.config.ValueExtractorResolver;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -19,15 +19,15 @@
 
     private static final byte VAR_END = (byte) '}';
 
-    private final FieldExtractorFactory fieldExtractorFactory;
+    private final ValueExtractorResolver valueExtractorResolver;
 
     public VarsCompiler() {
-        fieldExtractorFactory = new DefaultFieldExtractorFactory();
+        valueExtractorResolver = new DefaultValueExtractorResolver();
     }
 
-    public VarsCompiler(FieldExtractorFactory fieldExtractorFactory) {
-        Assert.notNull(fieldExtractorFactory, "fieldExtractorFactory");
-        this.fieldExtractorFactory = fieldExtractorFactory;
+    public VarsCompiler(ValueExtractorResolver valueExtractorResolver) {
+        Assert.notNull(valueExtractorResolver, "valueExtractorResolver");
+        this.valueExtractorResolver = valueExtractorResolver;
     }
 
     public List<Var> search(String value) {
@@ -63,7 +63,7 @@
                     vars = new ArrayList<>();
                 }
 
-                ValueExtractor valueExtractor = fieldExtractorFactory.createFieldExtractor(varName);
+                ValueExtractor valueExtractor = valueExtractorResolver.resolveValueExtractor(varName);
                 vars.add(new Var(varName, valueExtractor, startOffset, varEndOffset));
             }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/vars/VarsValueExtractorResolver.java	Thu Dec 07 10:12:10 2017 +0100
@@ -0,0 +1,32 @@
+package com.passus.st.vars;
+
+import com.passus.filter.CompoundValueExtractor;
+import com.passus.filter.ValueExtractor;
+import com.passus.filter.config.DefaultValueExtractorResolver;
+import java.util.Map;
+import com.passus.filter.config.ValueExtractorResolver;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public class VarsValueExtractorResolver implements ValueExtractorResolver {
+
+    private final ValueExtractorResolver extractorFactory = new DefaultValueExtractorResolver();
+    private final Map<String, ValueExtractor> globalVars;
+
+    public VarsValueExtractorResolver(Map<String, ValueExtractor> globalVars) {
+        this.globalVars = globalVars;
+    }
+
+    @Override
+    public ValueExtractor resolveValueExtractor(String fieldName) {
+        ValueExtractor defaultExtractor = extractorFactory.resolveValueExtractor(fieldName);
+        if (globalVars.containsKey(fieldName)) {
+            return CompoundValueExtractor.create(globalVars.get(fieldName), defaultExtractor);
+        } else {
+            return defaultExtractor;
+        }
+    }
+
+}