Repository: cxf Updated Branches: refs/heads/master 969cdb02e -> 2d131122c
some clean up in websocket test html pages; add a plain html test page for logbrowser sample Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/2d131122 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/2d131122 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/2d131122 Branch: refs/heads/master Commit: 2d131122cdcd5b50df91b497ba55a1d9e91fb175 Parents: 969cdb0 Author: Akitoshi Yoshida <a...@apache.org> Authored: Fri Nov 14 15:47:30 2014 +0100 Committer: Akitoshi Yoshida <a...@apache.org> Committed: Fri Nov 14 15:47:51 2014 +0100 ---------------------------------------------------------------------- .../websocket/src/main/resources/index.html | 8 +- .../samples/logbrowser-blueprint/README.txt | 7 + .../src/test/resources/index_plain.html | 211 +++++++++++++++++++ 3 files changed, 222 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/2d131122/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html b/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html index 2b1cc18..87c8eaf 100644 --- a/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html +++ b/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html @@ -29,18 +29,18 @@ <div id="output"> <div id="config" style="float: left;"> <strong>Service Endpoint URL:</strong><br /> - <input id="wsUri" size="72" style="width: 450px" value="ws://localhost:9000/"/> + <input id="wsUri" size="72" style="width: 100%" value="ws://localhost:9000/"/> <br/> <button id="connect">Connect</button> <button id="disconnect">Disconnect</button> <br /> <br /> <strong>Request:</strong><br /> - <textarea id="request" rows="10" cols="72" style="width: 450px;">GET /customerservice/customers/123</textarea> + <textarea id="request" rows="10" cols="72" style="width: 100%;">GET /customerservice/customers/123</textarea> <br/> <button id="send">Send</button> </div> - <div id="log" style="float: left; margin-left: 20px; padding-left: 20px; width: 450px; height: 500px; border-left: solid 1px #cccccc;"> + <div id="log" style="float: left; margin-left: 20px; padding-left: 20px; width: 60%; height: 500px; border-left: solid 1px #cccccc;"> <strong>Log:</strong><br /> <button id="clearLogBut" style="position: relative; top: 3px;">Clear log</button> <div id="consoleLog" style="margin-top: 5px; border: solid 1px #aaaaaa; overflow-y: scroll; height:100%"></div> @@ -122,7 +122,7 @@ writeToLog('<span style="color:red; font-size:75%; font-style:italic">ERROR</span><span style="color: red;"><pre>' + evt.data + '</pre></span>'); } - function doSend(message) { + function doSend(evt) { var reqmsg = document.getElementById("request"); writeToLog('<span style="color:green; font-size:75%; font-style:italic">SENT</span><span style="color: green;"><pre>' + createMessage(reqmsg.value) + '</pre></span>'); websocket.send(reqmsg.value); http://git-wip-us.apache.org/repos/asf/cxf/blob/2d131122/distribution/src/main/release/samples/logbrowser-blueprint/README.txt ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser-blueprint/README.txt b/distribution/src/main/release/samples/logbrowser-blueprint/README.txt index c7aa735..80bf7e3 100644 --- a/distribution/src/main/release/samples/logbrowser-blueprint/README.txt +++ b/distribution/src/main/release/samples/logbrowser-blueprint/README.txt @@ -25,6 +25,13 @@ Assuming you have a freshly intalled Apache Karaf-3.x, 4) To generate custom log entry, run some CXF scenarios that write some logs. +Additional features +5) Open the Log-Browser(PlainView) page by opening file test/resources/index_plain.html in the browser. + +6) Click on the Connect button to open a WebSocket connection to the log browser service. +Once the connection is open, click on the Subscribe button to subscribe to the logging feed. +When there are new log entries, they will be pushed to the socket and displayed on the Log text area. + *Note: - CXF version 3.0.2 is used in this example, but any verions that include this sample code may be used. http://git-wip-us.apache.org/repos/asf/cxf/blob/2d131122/distribution/src/main/release/samples/logbrowser-blueprint/src/test/resources/index_plain.html ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser-blueprint/src/test/resources/index_plain.html b/distribution/src/main/release/samples/logbrowser-blueprint/src/test/resources/index_plain.html new file mode 100644 index 0000000..f30ecf6 --- /dev/null +++ b/distribution/src/main/release/samples/logbrowser-blueprint/src/test/resources/index_plain.html @@ -0,0 +1,211 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<html> +<head> +<meta charset="utf-8"/> +<title>CXF Log-Browser using WebSocket (PlainView)</title> +</head> +<body> +<h2>CXF Log-Browser using WebSocket (PlainView)</h2> +<p>The purpose of this page is simply show how the log-feed can be subscribed and the log records are pushed over the WebSocket.</p> +<div id="output"> + <div id="config" style="float: left; width: 600px"> + <strong>Log-Browser Endpoint URL:</strong><br /> + <input id="wsUri" size="72" style="width: 100%" value="ws://localhost:8181/cxf/samples/logbrowser"/> + <br/> + <button id="connect">Connect</button> + <button id="disconnect">Disconnect</button> + <br /> + <br /> + <button id="subscribe">Subscribe</button> + <button id="unsubscribe">Unsubscribe</button> + <br /> + <br /> + <input id="modeatom" type="checkbox" name="mode" value="atom"/>Atom<br/> + <br /> + <br /> + </div> + <div id="log" style="float: left; width: 90%; height: 500px"> + <strong>Log:</strong><br /> + <button id="clearLogBut" style="position: relative; top: 3px;">Clear log</button> + <div id="consoleLog" style="margin-top: 5px; border: solid 1px #aaaaaa; overflow-y: scroll; height:100%"></div> + </div> + <div class="clearfix"></div> +</div> +<script language="javascript" type="text/javascript"> + var output; + + var connectBut = document.getElementById("connect"); + connectBut.onclick = doConnect; + + var disconnectBut = document.getElementById("disconnect"); + disconnectBut.onclick = doDisconnect; + + var subBut = document.getElementById("subscribe"); + subBut.onclick = doSub; + + var unsubBut = document.getElementById("unsubscribe"); + unsubBut.onclick = doUnsub; + + var modeatomCB = document.getElementById("modeatom"); + + var consoleLog = document.getElementById("consoleLog"); + + var clearLogBut = document.getElementById("clearLogBut"); + clearLogBut.onclick = clearLog; + + function init() { + output = document.getElementById("output"); + setGuiConnected(false); + } + + function doConnect() { + var wsUri = document.getElementById("wsUri"); + + websocket = new WebSocket(wsUri.value); + websocket.binaryType = 'arraybuffer'; + + websocket.onopen = function(evt) { + onOpen(evt) + }; + + websocket.onclose = function(evt) { + onClose(evt) + }; + + websocket.onmessage = function(evt) { + onMessage(evt) + }; + + websocket.onerror = function(evt) { + onError(evt) + }; + } + + function doDisconnect() { + // unsubscribe + websocket.close() + } + + function clearLog() { + while (consoleLog.childNodes.length > 0) { + consoleLog.removeChild(consoleLog.lastChild); + } + } + + function onOpen(evt) { + writeToLog('<span style="color:black; font-size:75%; font-style:italic">CONNECTED</span>'); + setGuiConnected(true); + } + + function onClose(evt) { + writeToLog('<span style="color:black; font-size:75%; font-style:italic">DISCONNECTED</span>'); + setGuiConnected(false); + } + + function onMessage(evt) { + writeToLog(createMessage(extractBody(evt.data)), true); + } + + function onError(evt) { + writeToLog('<span style="color:red; font-size:75%; font-style:italic">ERROR</span><span style="color: red;"><pre>' + evt.data + '</pre></span>'); + } + + function doSub(evt) { + var msg = modeatomCB.checked ? "GET /cxf/samples/logbrowser/logs/subscribe" : "GET /cxf/samples/logbrowser/logs/subscribe/alternate"; + writeToLog('<span style="color:green; font-size:75%; font-style:italic">SENT</span><span style="color: green;"><pre>' + createMessage(msg) + '</pre></span>'); + websocket.send(msg); + setGuiSubscribed(true); + } + + function doUnsub(evt) { + var msg = "GET /cxf/samples/logbrowser/logs/unsubscribe/*"; + writeToLog('<span style="color:green; font-size:75%; font-style:italic">SENT</span><span style="color: green;"><pre>' + createMessage(msg) + '</pre></span>'); + websocket.send(msg); + setGuiSubscribed(false); + } + + function setGuiConnected(isConnected) { + wsUri.disabled = isConnected; + connectBut.disabled = isConnected; + disconnectBut.disabled = !isConnected; + subBut.disabled = !isConnected; + unsubBut.disabled = true; + modeatomCB.disabled = !isConnected; + } + + function setGuiSubscribed(isSubscribed) { + subBut.disabled = isSubscribed; + unsubBut.disabled = !isSubscribed; + modeatomCB.disabled = isSubscribed; + } + + // painfully extracting the body by finding the \n delimiter + function extractBody(data) { + var ba = new Uint8Array(data); + var aa = new Array(ba.length); + var skipping = true; + var maystart = true; + for (i = 0; i < ba.length; i++) { + if (skipping) { + if (ba[i] == 10) { + if (maystart) { + skipping = false; + } else { + maystart = true; + } + } else { + if (ba[i] != 13) { + maystart = false; + } + continue; + } + } + aa[i] = String.fromCharCode(ba[i]); + } + return Array.prototype.slice.call(aa).join(""); + } + + function createMessage(data) { + return data.replace(/&/g, '&').replace(/</g, '<'); + } + + function writeToLog(message, raw) { + var pre = document.createElement(raw ? "code" : "p"); + pre.wordWrap = "break-word"; + pre.innerHTML = message; + consoleLog.appendChild(pre); + if (raw) { + consoleLog.appendChild(document.createElement("br")); + consoleLog.appendChild(document.createElement("br")); + } + while (consoleLog.childNodes.length > 100) { + consoleLog.removeChild(consoleLog.firstChild); + } + + consoleLog.scrollTop = consoleLog.scrollHeight; + } + + window.addEventListener("load", init, false); + + </script> +</body> +</html>