Mercurial > stress-tester
changeset 746:05758e673530
HttpVarsFilter
author | Devel 2 |
---|---|
date | Fri, 08 Dec 2017 10:29:00 +0100 |
parents | 6c06ad27997a |
children | a86bd0a170ad |
files | stress-tester/src/main/java/com/passus/st/vars/HttpVarsFilter.java stress-tester/src/main/java/com/passus/st/vars/VarsCompiler.java stress-tester/src/main/java/com/passus/st/vars/VarsExecutor.java |
diffstat | 3 files changed, 82 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/vars/HttpVarsFilter.java Fri Dec 08 10:29:00 2017 +0100 @@ -0,0 +1,72 @@ +package com.passus.st.vars; + +import com.passus.commons.Assert; +import com.passus.data.ByteBuff; +import com.passus.data.HeapByteBuff; +import com.passus.net.http.HttpMessageHelper; +import com.passus.net.http.HttpRequest; +import com.passus.net.http.HttpResponse; +import com.passus.st.client.http.HttpFlowContext; +import com.passus.st.client.http.filter.HttpFilter; +import com.passus.st.client.http.filter.HttpMessageWrapper; +import java.io.IOException; +import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * + * @author Mirosław Hawrot + */ +public class HttpVarsFilter extends HttpFilter { + + private static final Logger LOGGER = LogManager.getLogger(HttpVarsFilter.class); + + private final HttpMessageHelper helper = HttpMessageHelper.get(); + + private final VarsCompiler compiler; + + private final VarsExecutor executor; + + public HttpVarsFilter() { + compiler = new VarsCompiler(); + executor = new VarsExecutor(); + } + + public HttpVarsFilter(VarsCompiler compiler, VarsExecutor executor) { + Assert.notNull(compiler, "compiler"); + Assert.notNull(executor, "executor"); + this.compiler = compiler; + this.executor = executor; + } + + @Override + public HttpFilter instanceForWorker(int index) { + return new HttpVarsFilter(); + } + + @Override + public int filterOutbound(HttpRequest req, HttpResponse resp, HttpFlowContext context) { + //Przetwarzamy tylko requesty, response'a nie ma sensu + if (req != null) { + try { + //Zakladamy, ze kontent jest zdekodowany + ByteBuff buffer = req.getContentByteBuff(); + if (buffer != null) { + List<Var> vars = compiler.search(buffer); + if (vars != null && !vars.isEmpty()) { + ByteBuff result = new HeapByteBuff(buffer.readableBytes()); + executor.execute(buffer, result, vars, new HttpMessageWrapper(req, resp, context)); + } + } + } catch (IOException e) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(e.getMessage(), e); + } + } + } + + return DUNNO; + } + +}
--- a/stress-tester/src/main/java/com/passus/st/vars/VarsCompiler.java Thu Dec 07 14:34:38 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/vars/VarsCompiler.java Fri Dec 08 10:29:00 2017 +0100 @@ -1,6 +1,7 @@ package com.passus.st.vars; import com.passus.commons.Assert; +import com.passus.data.ByteBuff; import com.passus.data.ByteBuffUtils; import com.passus.filter.ValueExtractor; import com.passus.filter.config.DefaultValueExtractorResolver; @@ -35,6 +36,11 @@ return search(data, 0, data.length); } + public List<Var> search(ByteBuff value) { + return search(value.buffer(), value.startIndex(), value.endIndex()); + } + + public List<Var> search(byte[] data) { return search(data, 0, data.length); }
--- a/stress-tester/src/main/java/com/passus/st/vars/VarsExecutor.java Thu Dec 07 14:34:38 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/vars/VarsExecutor.java Fri Dec 08 10:29:00 2017 +0100 @@ -15,6 +15,10 @@ return execute(content.getBytes(DEFAULT_CHARSET), result, vars, context); } + public boolean execute(ByteBuff content, ByteBuff result, List<Var> vars, Object context) { + return execute(content.buffer(), content.startIndex(), content.endIndex(), result, vars, context); + } + public boolean execute(byte[] data, ByteBuff result, List<Var> vars, Object context) { return execute(data, 0, data.length, result, vars, context); }