Mercurial > stress-tester
changeset 740:bd686b6618b1
HttpWriteMode
author | Devel 1 |
---|---|
date | Wed, 06 Dec 2017 11:02:21 +0100 |
parents | 3fa7d471145f |
children | 5dff250da346 |
files | stress-tester/src/main/java/com/passus/st/ConverterMain.java stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataWriter.java stress-tester/src/main/java/com/passus/st/reader/nc/HttpWriteMode.java stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java |
diffstat | 4 files changed, 75 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ConverterMain.java Wed Dec 06 09:54:50 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/ConverterMain.java Wed Dec 06 11:02:21 2017 +0100 @@ -7,6 +7,7 @@ import com.passus.config.validation.ObjectError; import com.passus.net.PortRangeSet; import com.passus.st.client.http.filter.HttpFiltersConfigurator; +import com.passus.st.reader.nc.HttpWriteMode; import com.passus.st.source.NcEventDestination; import com.passus.st.source.PcapSessionEventSource; import static com.passus.st.utils.CliUtils.option; @@ -23,6 +24,44 @@ */ public class ConverterMain { + private static final String WRITE_MODES + = "1|req|reqonly|req-only | " + + "2|rrh|reqresphdr|req-resp-hdr | " + + "3|rr|reqresp|req-resp (default) | " + + "0|mix|mixed|dyn|dynamic (not implemented)"; + + private static HttpWriteMode resolveWriteMode(String raw) { + if (raw == null) { + return HttpWriteMode.defaultMode(); + } + raw = raw.toLowerCase(); + switch (raw) { + case "0": + case "mix": + case "mixed": + case "dyn": + case "dynamic": + return HttpWriteMode.REQUEST_FULL_RESPONSE_IF_TAGGED; + case "1": + case "req": + case "reqonly": + case "req-only": + return HttpWriteMode.REQUEST_FULL_RESPONSE_NO; + case "2": + case "rrh": + case "reqresphdr": + case "req-resp-hdr": + return HttpWriteMode.REQUEST_FULL_RESPONSE_HEADERS; + case "3": + case "rr": + case "reqresp": + case "req-resp": + return HttpWriteMode.REQUEST_FULL_RESPONSE_FULL; + default: + throw new IllegalArgumentException("Invalid write mode: " + raw); + } + } + private boolean askOverwriteIfExists(String output) { File f = new File(output); if (f.exists()) { @@ -71,8 +110,8 @@ // .hasArg().argName("file") // .build() // ); - options.addOption(option("req", "requestOnly").desc("Write only HTTP requests") - .hasArg(false) + options.addOption(option("hwm", "http-write-mode").desc(WRITE_MODES) + .hasArg().argName("mode") .build() ); @@ -121,8 +160,8 @@ NcEventDestination dst = new NcEventDestination(output); dst.setAllowOverwrite(overwrite); - dst.setRequestOnly(cl.hasOption("req")); - + dst.setHttpWriteMode(resolveWriteMode(cl.getOptionValue("hwm"))); + ConverterHttpClient client = new ConverterHttpClient(dst); if (cl.hasOption("ff")) {
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataWriter.java Wed Dec 06 09:54:50 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataWriter.java Wed Dec 06 11:02:21 2017 +0100 @@ -25,24 +25,10 @@ private final NcDataHelper ncDataHelper = NcDataHelper.getInstance(); - private boolean encodeRequest = true; - - private boolean encodeResponse = true; - - public boolean isEncodeRequest() { - return encodeRequest; - } + private HttpWriteMode mode = HttpWriteMode.defaultMode(); - public void setEncodeRequest(boolean encodeRequest) { - this.encodeRequest = encodeRequest; - } - - public boolean isEncodeResponse() { - return encodeResponse; - } - - public void setEncodeResponse(boolean encodeResponse) { - this.encodeResponse = encodeResponse; + public void setHttpWriteMode(HttpWriteMode mode) { + this.mode = mode; } public int encodeHeaders(HttpHeaders headers, ByteBuff buff) { @@ -183,7 +169,7 @@ long size = 1; HttpRequest req = messages.getRequest(); DataSource reqContent = null; - if (encodeRequest && req != null) { + if (req != null) { flags |= FLAG_REQUEST; size += encodeRequest(req, reqBuffer); reqContent = req.getContent(); @@ -197,6 +183,9 @@ HttpResponse resp = messages.getResponse(); DataSource respContent = null; + boolean encodeResponse + = (mode == HttpWriteMode.REQUEST_FULL_RESPONSE_FULL + || mode == HttpWriteMode.REQUEST_FULL_RESPONSE_HEADERS); if (encodeResponse && resp != null) { flags |= FLAG_RESPONSE; size += encodeResponse(resp, respBuffer);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/HttpWriteMode.java Wed Dec 06 11:02:21 2017 +0100 @@ -0,0 +1,16 @@ +package com.passus.st.reader.nc; + +/** + * + * @author mikolaj.podbielski + */ +public enum HttpWriteMode { + REQUEST_FULL_RESPONSE_NO, + REQUEST_FULL_RESPONSE_HEADERS, + REQUEST_FULL_RESPONSE_FULL, + REQUEST_FULL_RESPONSE_IF_TAGGED; + + public static HttpWriteMode defaultMode() { + return REQUEST_FULL_RESPONSE_FULL; + } +}
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java Wed Dec 06 09:54:50 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventDestination.java Wed Dec 06 11:02:21 2017 +0100 @@ -11,6 +11,7 @@ import com.passus.st.client.SessionStatusEvent; import com.passus.st.client.http.HttpSessionPayloadEvent; import com.passus.st.reader.nc.HttpSessionPayloadEventDataWriter; +import com.passus.st.reader.nc.HttpWriteMode; import com.passus.st.reader.nc.NcDataBlockWriter; import java.io.File; import java.io.IOException; @@ -37,7 +38,7 @@ private boolean allowOverwrite; - private boolean requestOnly; + private HttpWriteMode mode = HttpWriteMode.defaultMode(); public NcEventDestination() { } @@ -79,13 +80,9 @@ this.allowOverwrite = allowOverwrite; } - public boolean isRequestOnly() { - return requestOnly; - } - - public void setRequestOnly(boolean requestOnly) { - this.requestOnly = requestOnly; - httpPayloadWriter.setEncodeResponse(!requestOnly); + public void setHttpWriteMode(HttpWriteMode mode) { + this.mode = mode; + httpPayloadWriter.setHttpWriteMode(mode); } @Override @@ -143,7 +140,10 @@ writer.writeSessionPayload(event.getTimestamp(), event.getSessionInfo(), (byte) 1, buff); } - if (event.getResponse() != null && !requestOnly) { + boolean encodeResponse + = (mode == HttpWriteMode.REQUEST_FULL_RESPONSE_FULL + || mode == HttpWriteMode.REQUEST_FULL_RESPONSE_HEADERS); + if (event.getResponse() != null && encodeResponse) { ByteBuff buff = new HeapByteBuff(); responseEncoder.encode(event.getResponse(), buff); writer.writeSessionPayload(event.getTimestamp(), event.getSessionInfo(), (byte) 1, buff);