changeset 936:d49c6a6c308a

refactoring
author Devel 1
date Mon, 07 May 2018 15:00:01 +0200
parents 53ff4d2e0abc
children 6d35ff7ba9c0
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java stress-tester/src/main/java/com/passus/st/validation/HeaderNameValidator.java stress-tester/src/main/java/com/passus/st/validation/HttpValidators.java
diffstat 4 files changed, 22 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilter.java	Mon May 07 14:51:41 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilter.java	Mon May 07 15:00:01 2018 +0200
@@ -26,7 +26,7 @@
 import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID;
 import com.passus.st.client.http.HttpFlowContext;
 import com.passus.st.plugin.PluginConstants;
-import com.passus.st.validation.HeaderNameValidator;
+import com.passus.st.validation.HttpValidators;
 import static com.passus.st.validation.NodeValidationUtils.validateType;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -320,12 +320,12 @@
         public NodeDefinition create() {
             KeyNameVaryListNodeDefinition extractorsDef = new KeyNameVaryListNodeDefinition()
                     .setNodeTransformer(new HttpCsrfFilterExtractorTransformer())
-                    .add("header", valueDef().addValidator(HeaderNameValidator.INSTANCE))
+                    .add("header", valueDef().addValidator(HttpValidators.HEADER_NAME_VALIDATOR))
                     .add("cookie", valueDef());
 
             KeyNameVaryListNodeDefinition injectorsDef = new KeyNameVaryListNodeDefinition()
                     .setNodeTransformer(new HttpCsrfFilterInjectorTransformer())
-                    .add("header", valueDef().addValidator(HeaderNameValidator.INSTANCE))
+                    .add("header", valueDef().addValidator(HttpValidators.HEADER_NAME_VALIDATOR))
                     .add("cookie", valueDef());
 
             ValueNodeDefinition storeDef = valueDef().setTransformer(new HttpCsrfFilterStoreTransformer());
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Mon May 07 14:51:41 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Mon May 07 15:00:01 2018 +0200
@@ -15,7 +15,6 @@
 import com.passus.st.config.FieldValueExtractorTransformerNodeDefCreator;
 import com.passus.st.config.HeaderOperationNodeDefinition;
 import com.passus.st.plugin.PluginConstants;
-import com.passus.st.validation.HeaderNameValidator;
 import com.passus.st.validation.HttpValidators;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -146,7 +145,7 @@
 
             KeyNameVaryListNodeDefinition operationsDef = new KeyNameVaryListNodeDefinition()
                     .setNodeTransformer(new HttpMessageModificationFilterTransformer())
-                    .add("removeHeader", valueDef().addValidator(HeaderNameValidator.INSTANCE))
+                    .add("removeHeader", valueDef().addValidator(HttpValidators.HEADER_NAME_VALIDATOR))
                     .add("addHeader", headerNodeDef)
                     .add("setHeader", headerNodeDef)
                     .add("removeCookie", valueDef())
--- a/stress-tester/src/main/java/com/passus/st/validation/HeaderNameValidator.java	Mon May 07 14:51:41 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-package com.passus.st.validation;
-
-import com.passus.config.validation.Errors;
-import com.passus.config.validation.Validator;
-import com.passus.net.http.HttpUtils;
-
-/**
- *
- * @author Mirosław Hawrot
- */
-public class HeaderNameValidator implements Validator {
-
-    public static final HeaderNameValidator INSTANCE = new HeaderNameValidator();
-
-    @Override
-    public boolean supports(Class<?> clazz) {
-        return CharSequence.class.isAssignableFrom(clazz);
-    }
-
-    @Override
-    public void validate(Object target, Errors errors) {
-        CharSequence value = ((CharSequence) target);
-        if (!HttpUtils.isValidHeaderName(value)) {
-            errors.reject("Invalid header name \"%s\"", value);
-        }
-    }
-
-}
--- a/stress-tester/src/main/java/com/passus/st/validation/HttpValidators.java	Mon May 07 14:51:41 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/validation/HttpValidators.java	Mon May 07 15:00:01 2018 +0200
@@ -14,7 +14,9 @@
     public static final MethodValidator METHOD_VALIDATOR = new MethodValidator();
 
     public static final VersionValidator VERSION_VALIDATOR = new VersionValidator();
-    
+
+    public static final HeaderNameValidator HEADER_NAME_VALIDATOR = new HeaderNameValidator();
+
     public static class MethodValidator implements Validator {
 
         @Override
@@ -50,4 +52,19 @@
         }
     }
 
+    public static class HeaderNameValidator implements Validator {
+
+        @Override
+        public boolean supports(Class<?> clazz) {
+            return CharSequence.class.isAssignableFrom(clazz);
+        }
+
+        @Override
+        public void validate(Object target, Errors errors) {
+            CharSequence value = ((CharSequence) target);
+            if (!HttpUtils.isValidHeaderName(value)) {
+                errors.reject("Invalid header name \"%s\"", value);
+            }
+        }
+    }
 }