changeset 862:c189e87bfaaa

HttpFilterConfigurator bugfix
author Devel 2
date Wed, 24 Jan 2018 11:23:54 +0100
parents 74a25a7af9e3
children 09b03bd0ad00
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreator.java
diffstat 2 files changed, 38 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java	Wed Jan 24 10:54:34 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersConfigurator.java	Wed Jan 24 11:23:54 2018 +0100
@@ -4,8 +4,8 @@
 import com.passus.config.*;
 import com.passus.config.schema.ConfigurationSchema;
 import com.passus.config.schema.ConfigurationSchemaImpl;
+import com.passus.config.schema.NodeDefinition;
 import com.passus.config.validation.Errors;
-import com.passus.st.config.ClientConfigurator;
 import com.passus.st.plugin.PluginConstants;
 import com.passus.st.utils.ConfigurationContextConsts;
 
@@ -14,8 +14,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import static com.passus.config.ConfigurationUtils.tupleNodeStringValue;
-
 /**
  * @author Mirosław Hawrot
  */
@@ -26,6 +24,10 @@
 
     private static final ConfigurationSchema SCHEMA = new ConfigurationSchemaImpl(new HttpFiltersNodeDefinitionCreator().create());
 
+    private final HttpFiltersNodeDefinitionCreator nodeDefinitionCreator = new HttpFiltersNodeDefinitionCreator();
+
+    private final NodeDefinition nodedef = nodeDefinitionCreator.create();
+
     @Override
     public String getDomain() {
         return DOMAIN;
@@ -42,44 +44,48 @@
     }
 
     public static List<HttpFilter> getFilters(Configuration config, Errors errors, ConfigurationContext context) {
-        SCHEMA.validate(config, errors, context);
-        // TODO: wywala się, bo robi transform mimo błędów
-        Configuration tConfig = SCHEMA.transform(config, errors, context);
-        if (errors.getErrorCount() == 0) {
-            List<HttpFilter> filters = new ArrayList<>();
-            CMapNode node = (CMapNode) tConfig.getRootNode();
-            CListNode filtersNodes = (CListNode) node.get("httpFilters").getNode();
-            HttpFilterFactory factory = new HttpFilterFactory();
-
-            for (CNode child : filtersNodes.getChildren()) {
-                CMapNode configNode = (CMapNode) child;
-                String filterType = tupleNodeStringValue(configNode.get("type"));
-                HttpFilter filter = factory.getInstanceByName(filterType);
-                if (configNode.hasChild()) {
-                    Configuration filterConfig = new ConfigurationImpl(configNode);
-                    filter.configure(filterConfig, null);
-                }
-
-                filters.add(filter);
-            }
-
-            return filters;
+        if (!config.containsKey(DOMAIN)) {
+            return null;
         }
 
-        return null;
+        HttpFiltersNodeDefinitionCreator nodeDefinitionCreator = new HttpFiltersNodeDefinitionCreator();
+        NodeDefinition nodeDef = nodeDefinitionCreator.create();
+        CCompositeNode rootNode = config.subConfiguration(DOMAIN).getRootNode();
+        nodeDef.validate(rootNode, errors, context);
+        if (errors.hasError()) {
+            return null;
+        }
+
+        nodeDef.transform(rootNode, errors, context);
+        if (errors.hasError()) {
+            return null;
+        }
+
+        try {
+            return (List<HttpFilter>) config.get(DOMAIN);
+        } catch (Exception e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
     }
 
     @Override
     public void validate(Configuration config, Errors errors, ConfigurationContext context) {
-        SCHEMA.validate(config, errors, context);
+        CCompositeNode rootNode = config.getRootNode();
+        nodedef.validate(rootNode, errors, context);
     }
 
     @Override
     public void configure(Configuration config, Errors errors, ConfigurationContext context) {
-        List<HttpFilter> cfgFilters = getFilters(config, errors, context);
-        if (errors.getErrorCount() == 0) {
-            List<HttpFilter> filters = new ArrayList<>(cfgFilters);
-            context.add(ConfigurationContextConsts.HTTP_FILTERS_FILTERS, filters);
+        CCompositeNode rootNode = config.getRootNode();
+        nodedef.transform(rootNode, errors, context);
+        if (!errors.hasError()) {
+            try {
+                List<HttpFilter> filters = ConfigurationUtils.convertToList(config.getRootNode(), HttpFilter.class);
+                context.add(ConfigurationContextConsts.HTTP_FILTERS_FILTERS, filters);
+            } catch (Exception e) {
+                throw new RuntimeException(e.getMessage(), e);
+            }
+
         }
     }
 
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreator.java	Wed Jan 24 10:54:34 2018 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFiltersNodeDefinitionCreator.java	Wed Jan 24 11:23:54 2018 +0100
@@ -23,7 +23,7 @@
 
     @Override
     public NodeDefinition create() {
-        return mapDef(tupleDef("httpFilters", createFiltersList()));
+        return createFiltersList(true);
     }