Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @MessageMapping("/emitter")
- @SendTo("/topic/response")
- public SseEmitter output(RunData runData) throws Exception {
- SseEmitter emitter = new SseEmitter();
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- RemoteHostController rhc = new RemoteHostController(runData);
- rhc.execute();
- while (rhc.getActiveCount() > 0) {
- emitter.send(rhc.getAllOutput());
- Thread.sleep(2000);
- }
- emitter.complete();
- } catch (Exception ee) {
- ee.printStackTrace();
- emitter.completeWithError(ee);
- }
- }
- }).start();
- return emitter;
- }
- function connect() {
- var socket = new SockJS('http://localhost:8080/emitter');
- stompClient = Stomp.over(socket);
- stompClient.connect({}, function(frame) {
- setConnected(true);
- console.log('Connected: ' + frame);
- stompClient.subscribe('/topic/response', function(greeting){
- showOutput(greeting.body);
- });
- });
- }
- function sendData() {
- var hostname = document.getElementById('hostname').value;
- var username = document.getElementById('username').value;
- var password = document.getElementById('password').value;
- var command = document.getElementById('command').value;
- stompClient.send("/app/emitter", {}, JSON.stringify({ 'hostname': hostname,
- 'username': username,
- 'password': password,
- 'command': command}));
- }
- function showOutput(message) {
- var response = document.getElementById('response');
- var p = document.createElement('p');
- p.style.wordWrap = 'break-word';
- p.appendChild(document.createTextNode(message));
- response.appendChild(p);
- }
- {"timeout":null}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement