changeset 804:3700c4a39b27

HttpScopeModificationFilter.direction
author Devel 2
date Thu, 04 Jan 2018 15:08:34 +0100
parents 91e8f64cae1e
children 4f6b12b34947
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java
diffstat 1 files changed, 32 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Thu Jan 04 15:03:34 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Thu Jan 04 15:08:34 2018 +0100
@@ -4,12 +4,14 @@
 import com.passus.commons.annotations.Plugin;
 import com.passus.config.Configuration;
 import com.passus.config.annotations.NodeDefinitionCreate;
+import static com.passus.config.schema.ConfigurationSchemaBuilder.enumDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.listDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.mixedDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.valueDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.mappingDef;
+import static com.passus.config.schema.ConfigurationSchemaBuilder.tupleDef;
 import com.passus.config.schema.KeyNameVaryListNodeDefinition;
 import com.passus.config.schema.NodeDefinition;
 import com.passus.config.schema.NodeDefinitionCreator;
@@ -505,6 +507,8 @@
 
     private HttpMessagePredicate predicate;
 
+    private HttpFilterDirection direction = HttpFilterDirection.OUT;
+
     public HttpMessagePredicate getPredicate() {
         return predicate;
     }
@@ -513,6 +517,15 @@
         this.predicate = predicate;
     }
 
+    public HttpFilterDirection getDirection() {
+        return direction;
+    }
+
+    public void setDirection(HttpFilterDirection direction) {
+        Assert.notNull(direction, "direction");
+        this.direction = direction;
+    }
+
     public void addOperation(Operation operation) {
         Assert.notNull(operation, "operation");
         operations.add(operation);
@@ -529,6 +542,7 @@
             }
         }
 
+        direction = (HttpFilterDirection) config.get("dir", HttpFilterDirection.OUT);
         predicate = (HttpMessagePredicate) config.get("applyIf", null);
     }
 
@@ -536,8 +550,7 @@
         return Collections.unmodifiableList(operations);
     }
 
-    @Override
-    public int filterOutbound(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
+    private void filter(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
         if (req != null && !operations.isEmpty()) {
             boolean exec = true;
             if (predicate != null) {
@@ -550,7 +563,22 @@
                     op.process(req, resp, context);
                 }
             }
+        }
+    }
 
+    @Override
+    public int filterOutbound(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
+        if (direction == HttpFilterDirection.BOTH || direction == HttpFilterDirection.OUT) {
+            filter(req, resp, context);
+        }
+
+        return DUNNO;
+    }
+
+    @Override
+    public int filterInbound(HttpRequest req, HttpResponse resp, HttpFlowContext context) {
+        if (direction == HttpFilterDirection.BOTH || direction == HttpFilterDirection.IN) {
+            filter(req, resp, context);
         }
 
         return DUNNO;
@@ -601,7 +629,8 @@
 
             return mapDef(
                     tupleDef("operations", operationsDef),
-                    tupleDef("applyIf", new HttpFilterMessagePredicateNodeDefinition()).setRequired(false)
+                    tupleDef("applyIf", new HttpFilterMessagePredicateNodeDefinition()).setRequired(false),
+                    tupleDef("dir", enumDef(HttpFilterDirection.class)).setRequired(false)
             );
         }