diff --git a/src/main/java/io/hyperfoil/tools/qdup/JsonServer.java b/src/main/java/io/hyperfoil/tools/qdup/JsonServer.java index e1e97f74..ae1e63c7 100644 --- a/src/main/java/io/hyperfoil/tools/qdup/JsonServer.java +++ b/src/main/java/io/hyperfoil/tools/qdup/JsonServer.java @@ -287,6 +287,15 @@ public void start(){ e.printStackTrace(); } }); + router.get("/session/:sessionId/buffer").handler(rc->{ + String cmdUid = rc.request().getParam("sessionId"); + Context found = dispatcher.getContext(cmdUid); + if(found != null){ + rc.response().setStatusCode(200).end(found.getShell().bufferJson()); + }else{ + rc.response().setStatusCode(400).end("could not find session "+cmdUid); + } + }); router.post("/session/:sessionId/parse").handler(rc->{ String cmdUid = rc.request().getParam("sessionId"); Context found = dispatcher.getContext(cmdUid); diff --git a/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java b/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java index b53acfe1..0d1f8a8e 100644 --- a/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java +++ b/src/main/java/io/hyperfoil/tools/qdup/shell/AbstractShell.java @@ -658,6 +658,9 @@ private void lineConsumers(String line) { } } + public String bufferJson(){ + return sessionStreams.jsonBuffers(); + } public String peekOutput() { return sessionStreams.currentOutput(); } diff --git a/src/main/java/io/hyperfoil/tools/qdup/stream/SessionStreams.java b/src/main/java/io/hyperfoil/tools/qdup/stream/SessionStreams.java index 60b603b2..153ca25b 100644 --- a/src/main/java/io/hyperfoil/tools/qdup/stream/SessionStreams.java +++ b/src/main/java/io/hyperfoil/tools/qdup/stream/SessionStreams.java @@ -1,5 +1,7 @@ package io.hyperfoil.tools.qdup.stream; +import io.hyperfoil.tools.yaup.json.Json; + import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -105,7 +107,23 @@ public void write(byte b[], int off, int len) throws IOException { super.write(b,off,len); //escapeFilteredStream.write(b,off,len); } - + public String jsonBuffers(){ + Json rtrn = new Json(); + rtrn.set("escapeFiltered",new Json()); + rtrn.getJson("escapeFiltered").set("buffer",escapeFilteredStream.getBuffered().replaceAll("[\r\n]","\\\\n")); + rtrn.getJson("escapeFiltered").set("suffixStream",new Json()); + rtrn.getJson("escapeFiltered").getJson("suffixStream").set("buffer",suffixStream.getBuffered().replaceAll("[\r\n]","\\\\n")); + rtrn.getJson("escapeFiltered").getJson("suffixStream").set("filteredStream",new Json()); + rtrn.getJson("escapeFiltered").getJson("suffixStream").getJson("filteredStream").set("buffer",filteredStream.getBuffered().replaceAll("[\r\n]","\\\\n")); + rtrn.getJson("escapeFiltered").getJson("suffixStream").getJson("filteredStream").set("lineEmitting",new Json()); + rtrn.getJson("escapeFiltered").getJson("suffixStream").getJson("filteredStream").getJson("lineEmitting").set("buffer",lineEmittingStream.getBuffered().replaceAll("[\r\n]","\\\\n")); + rtrn.getJson("escapeFiltered").getJson("suffixStream").getJson("filteredStream").set("shStream",new Json()); + rtrn.getJson("escapeFiltered").getJson("suffixStream").getJson("filteredStream").getJson("shStream").set("buffer",shStream.toString().replaceAll("[\r\n]","\\\\n")); + rtrn.getJson("escapeFiltered").getJson("suffixStream").set("promptStream",new Json()); + rtrn.getJson("escapeFiltered").getJson("suffixStream").getJson("promptStream").set("buffer",promptStream.getBuffered().replaceAll("[\r\n]","\\\\n")); + + return rtrn.toString(); + } public String printBuffers(){ StringBuilder sb = new StringBuilder(); sb.append(getName()+"\n");