BrowserTool enhancements

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-01-15 16:28:01 +11:00
parent 12655a0944
commit 4f570b62e3
3 changed files with 23 additions and 2 deletions

View File

@ -23,10 +23,12 @@ import java.io.InputStream;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Locale;
import java.util.Random;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.StringUtil;
@ -38,8 +40,11 @@ import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.core.OpCode;
@WebSocket
public class BrowserSocket
@ -187,6 +192,19 @@ public class BrowserSocket
break;
}
case "ping":
{
try
{
LOG.info("PING!");
this.session.getRemote().sendPing(BufferUtil.toBuffer("ping from server"));
}
catch (IOException e)
{
LOG.warn(e);
}
break;
}
case "many":
{
String parts[] = val.split(",");
@ -231,7 +249,7 @@ public class BrowserSocket
{
String dump = (session instanceof Dumpable) ? ((Dumpable) session).dump() : session.toString();
System.err.println(dump);
writeMessage("Dump: %s", dump);
Arrays.stream(dump.split("\n")).forEach(d->writeMessage("Dump: %s", d));
break;
}
default:

View File

@ -11,6 +11,7 @@
<input id="connect" class="button" type="submit" name="connect" value="connect"/>
<input id="close" class="button" type="submit" name="close" value="close" disabled="disabled"/>
<input id="info" class="button" type="submit" name="info" value="info" disabled="disabled"/>
<input id="ping" class="button" type="submit" name="ping" value="ping" disabled="disabled"/>
<input id="time" class="button" type="submit" name="time" value="time" disabled="disabled"/>
<input id="many" class="button" type="submit" name="many" value="many" disabled="disabled"/>
<input id="manythreads" class="button" type="submit" name="many" value="manythreads" disabled="disabled"/>
@ -27,6 +28,7 @@
$("connect").onclick = function(event) { wstool.connect(); return false; }
$("close").onclick = function(event) {wstool.close(); return false; }
$("info").onclick = function(event) {wstool.write("info:"); return false; }
$("ping").onclick = function(event) {wstool.write("ping:"); return false; }
$("time").onclick = function(event) {wstool.write("time:"); return false; }
$("many").onclick = function(event) {wstool.write("many:15,300"); return false; }
$("manythreads").onclick = function(event) {wstool.write("manythreads:20,25,60"); return false; }

View File

@ -68,7 +68,7 @@ var wstool = {
infos : function(message) {
this._scount++;
if(message.length > 300) {
if(message.length > 300 && !message.startsWith("Dump:")) {
wstool._out("server", "[s" + this._scount + "] [big message: " + message.length + " characters]");
} else {
wstool._out("server", "[s" + this._scount + "] " + message);
@ -79,6 +79,7 @@ var wstool = {
$('connect').disabled = enabled;
$('close').disabled = !enabled;
$('info').disabled = !enabled;
$('ping').disabled = !enabled;
$('time').disabled = !enabled;
$('many').disabled = !enabled;
$('manythreads').disabled = !enabled;