changeset 612:7fd0b286b240

switching to HttpMessageHelper.get()
author Devel 1
date Mon, 09 Oct 2017 14:55:37 +0200
parents d3c6e21084cd
children e38011acae15
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFormFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFormLoginFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java
diffstat 4 files changed, 9 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFormFilter.java	Mon Oct 09 13:44:39 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFormFilter.java	Mon Oct 09 14:55:37 2017 +0200
@@ -51,8 +51,6 @@
 
     private static final Logger LOGGER = LogManager.getLogger(HttpCsrfFormFilter.class);
 
-    private final HttpMessageHelper helper = new HttpMessageHelper(); // needs instance, because header decoders are not thread safe
-
     private String inputName;
     private final Set<ByteString> contentTypesToScan;
 
@@ -103,10 +101,10 @@
                 if (entry != null) {
                     LOGGER.debug("Found token matching current rerquest.");
                     try {
-                        HttpParameters parameters = helper.decodeFormUrlencoded(request);
+                        HttpParameters parameters = HttpMessageHelper.get().decodeFormUrlencoded(request);
                         if (parameters != null && parameters.contains(inputName)) {
                             parameters.set(inputName, entry.value);
-                            helper.setFormUrlencoded(request, parameters);
+                            HttpMessageHelper.get().setFormUrlencoded(request, parameters);
                             LOGGER.debug("Token inserted.");
                         } else {
                             LOGGER.debug("Could not find request parameter {}", parameters);
@@ -123,11 +121,11 @@
 
     @Override
     public int filterInbound(HttpRequest request, HttpResponse resp, HttpFlowContext context) {
-        HttpContentType contentType = helper.getContentType(resp);
+        HttpContentType contentType = HttpMessageHelper.get().getContentType(resp);
         if (contentType != null && contentTypesToScan.contains(contentType.getMimeType())) {
             try {
                 HeapByteBuff contentBuff = new HeapByteBuff();
-                helper.readContent(resp, contentBuff, true);
+                HttpMessageHelper.get().readContent(resp, contentBuff, true);
                 String content = contentBuff.toString();
 
                 ParametersBag session = context.scopes().getSession(resp);
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFormLoginFilter.java	Mon Oct 09 13:44:39 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFormLoginFilter.java	Mon Oct 09 14:55:37 2017 +0200
@@ -33,7 +33,7 @@
 
     public static final String TYPE = "formLogin";
 
-    private final HttpMessageHelper helper = new HttpMessageHelper(); // needs instance, because header decoders are not thread safe
+    private final HttpMessageHelper helper = new HttpMessageHelper(false); // used in outbound only, instance per filter is OK
     private CharSequence userField;
     private CharSequence passwordField;
 
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Mon Oct 09 13:44:39 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java	Mon Oct 09 14:55:37 2017 +0200
@@ -465,7 +465,7 @@
 
     private final List<Operation> operations = new ArrayList<>();
 
-    private static final HttpMessageHelper HELPER = new HttpMessageHelper(true);
+    private static final HttpMessageHelper HELPER = new HttpMessageHelper(true); // used in outbound only, instance per filter is OK
 
     private HttpMessagePredicate predicate;
 
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java	Mon Oct 09 13:44:39 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSessionCookieFilter.java	Mon Oct 09 14:55:37 2017 +0200
@@ -55,13 +55,6 @@
      */
     private final Map<ByteString, ByteString> cookiesMap = new ConcurrentHashMap<>();
 
-    private static final ThreadLocal<HttpMessageHelper> HELPER = new ThreadLocal<HttpMessageHelper>() {
-        @Override
-        protected HttpMessageHelper initialValue() {
-            return new HttpMessageHelper(false);
-        }
-    };
-
     private boolean removeInvalidSessionId = false;
 
     public HttpSessionCookieFilter() {
@@ -102,7 +95,7 @@
 
         HttpCookie sessionCookie = null;
         for (CharSequence cookieName : cookieNames) {
-            sessionCookie = HELPER.get().getCookie(msg, cookieName);
+            sessionCookie = HttpMessageHelper.get().getCookie(msg, cookieName);
             if (sessionCookie != null) {
                 break;
             }
@@ -130,14 +123,14 @@
             ByteString liveValue = cookiesMap.get(inValue);
             if (liveValue != null) {
                 String sessionId = liveValue.toString();
-                HELPER.get().updateCookieValue(pcapRequest, requestCookie.getName(), liveValue);
+                HttpMessageHelper.get().updateCookieValue(pcapRequest, requestCookie.getName(), liveValue);
                 LOGGER.debug("Mapping used {} -> {} [{}]", inValue, liveValue, pcapRequest.getUrl());
                 setTag(pcapRequest, TAG_SESSION_ID, sessionId);
                 setTag(pcapResponse, TAG_SESSION_ID, sessionId);
             } else {
                 LOGGER.debug("Mapping not found for {} [{}]", inValue, pcapRequest.getUrl());
                 if (removeInvalidSessionId) {
-                    HELPER.get().removeCookie(pcapRequest, requestCookie.getName());
+                    HttpMessageHelper.get().removeCookie(pcapRequest, requestCookie.getName());
                 } else {
                     setTag(pcapRequest, TAG_SESSION_ID, requestCookie.getValue().toString());
                 }