From 978b3384b1dc6a68ccaca44b1e6ea344ae190e75 Mon Sep 17 00:00:00 2001 From: bcopy <brice.copy@gmail.com> Date: Mon, 22 May 2017 08:51:52 +0200 Subject: [PATCH] Add atmosphere test page --- pom.xml | 11 ++++++ .../client/atmosphere/TagUpdateMessage.java | 2 +- src/main/resources/static/index.html | 5 ++- src/main/resources/static/test/index.html | 39 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/static/test/index.html diff --git a/pom.xml b/pom.xml index e11e611..8f43474 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,17 @@ <artifactId>slf4j-api</artifactId> </dependency> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>webjars-locator</artifactId> + <version>[0.30,)</version> + </dependency> + <dependency> + <groupId>org.webjars</groupId> + <artifactId>atmosphere-javascript</artifactId> + <version>2.3.2</version> + </dependency> + <dependency> <groupId>org.springframework</groupId> <artifactId>spring-websocket</artifactId> diff --git a/src/main/java/cern/c2mon/client/atmosphere/TagUpdateMessage.java b/src/main/java/cern/c2mon/client/atmosphere/TagUpdateMessage.java index 814166f..d3ee864 100644 --- a/src/main/java/cern/c2mon/client/atmosphere/TagUpdateMessage.java +++ b/src/main/java/cern/c2mon/client/atmosphere/TagUpdateMessage.java @@ -25,7 +25,7 @@ public class TagUpdateMessage implements SimplifiedTag { public TagUpdateMessage(Tag tag){ this.setId(tag.getId()) .setName(tag.getName()) - .setValue(tag.getValue().toString()) + .setValue(tag.getValue()!=null?tag.getValue().toString():"") .setControlTag(tag.isControlTag()) .setAliveTag(tag.isAliveTag()) .setTimestamp(tag.getTimestamp().getTime()) diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index a6175b5..64c2165 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -1,5 +1,8 @@ <html> -<head><title>C2MON Atmosphere Publisher</title></head> +<head> +<title>C2MON Atmosphere Publisher</title> + +</head> <body> <h1>Hello world !</h1> </body> diff --git a/src/main/resources/static/test/index.html b/src/main/resources/static/test/index.html new file mode 100644 index 0000000..e172f24 --- /dev/null +++ b/src/main/resources/static/test/index.html @@ -0,0 +1,39 @@ +<html> +<head> +<title>C2MON Atmosphere Publisher Sanity Testing Page</title> +<script src="../webjars/atmosphere-javascript/atmosphere.js"></script> +</head> +<body> +<h1>Test</h1> +<script> + var socket = atmosphere; + var request = new atmosphere.AtmosphereRequest(); + request.url = "../broadcast"; + request.contentType = "application/json"; + request.transport = 'websocket'; + request.fallbackTransport = 'long-polling'; + request.onOpen = function(response){ + console.log('Atmosphere connected using ' + response.transport); + subSocket.push(JSON.stringify({add:["dip://dip/acc/LHC/RunControl/Page1"]})); + }; + request.onMessage = function (response) { + console.log('Atmosphere received : '+response.responseBody); + try { + var json = JSON.parse(response.responseBody); + console.log('JSON message : ',json); + } catch (e) { + console.log('Error: ', response.responseBody); + return; + } + + }; + + request.onError = function(response) { + console.log('Atmosphere error :', response.responseBody); + }; + + var subSocket = socket.subscribe(request); + +</script> +</body> +</html> \ No newline at end of file -- GitLab