aboutsummaryrefslogtreecommitdiff
path: root/juick-ws
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-25 22:48:10 +0300
committerGravatar Vitaly Takmazov2016-07-27 13:56:45 +0300
commita18f5e5012b862992af40db60c83a40098342b53 (patch)
tree73f72b1ec6c374d92cc1ac714d5dc768956b2f4c /juick-ws
parent69af3f60d399157a8951988fa2f91d29c553fbb5 (diff)
fix ws configuration
Diffstat (limited to 'juick-ws')
-rw-r--r--juick-ws/build.gradle1
-rw-r--r--juick-ws/package.json3
-rw-r--r--juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java3
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java23
-rw-r--r--juick-ws/src/main/static/scripts.js4
5 files changed, 29 insertions, 5 deletions
diff --git a/juick-ws/build.gradle b/juick-ws/build.gradle
index d20131b3..f0c6ec33 100644
--- a/juick-ws/build.gradle
+++ b/juick-ws/build.gradle
@@ -22,6 +22,7 @@ dependencies {
compile "org.springframework:spring-jdbc:${springFrameworkVersion}"
compile "org.springframework:spring-webmvc:${springFrameworkVersion}"
compile "org.springframework:spring-websocket:${springFrameworkVersion}"
+ compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.8.0"
compile 'javax.inject:javax.inject:1'
compile 'org.apache.httpcomponents:httpclient:4.5.1'
compile 'org.apache.commons:commons-dbcp2:2.0'
diff --git a/juick-ws/package.json b/juick-ws/package.json
index aa6c7a71..413776c2 100644
--- a/juick-ws/package.json
+++ b/juick-ws/package.json
@@ -25,6 +25,7 @@
},
"dependencies": {
"normalize.css": "^4.2.0",
- "terminal": "https://github.com/juick/terminal.git"
+ "terminal": "https://github.com/juick/terminal.git",
+ "whatwg-fetch": "^1.0.0"
}
}
diff --git a/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java b/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
index ada19f89..82e15765 100644
--- a/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
+++ b/juick-ws/src/main/java/com/juick/ws/api/WebSocketStatus.java
@@ -1,5 +1,7 @@
package com.juick.ws.api;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
/**
* Created by vitalyster on 25.07.2016.
*/
@@ -10,6 +12,7 @@ public class WebSocketStatus {
clientsCount = count;
}
+ @JsonProperty("status")
public int getClientsCount() {
return clientsCount;
}
diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
index c25f8f42..ecd44908 100644
--- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
+++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java
@@ -1,5 +1,7 @@
package com.juick.ws.configuration;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.juick.ws.WebsocketComponent;
import com.juick.ws.XMPPConnection;
import com.mitchellbosecke.pebble.PebbleEngine;
@@ -13,19 +15,22 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import javax.inject.Inject;
import javax.servlet.ServletContext;
+import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -95,6 +100,7 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
}
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
+ ((ServletWebSocketHandlerRegistry)registry).setOrder(2);
registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*");
}
@@ -104,4 +110,17 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
registry.addResourceHandler("/scripts.js").addResourceLocations("/");
registry.addResourceHandler("/style.css").addResourceLocations("/");
}
+
+ @Override
+ protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
+ Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
+ .serializationInclusion(JsonInclude.Include.NON_DEFAULT)
+ .serializationInclusion(JsonInclude.Include.NON_NULL)
+ .serializationInclusion(JsonInclude.Include.NON_ABSENT)
+ .serializationInclusion(JsonInclude.Include.NON_EMPTY);
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
+ converter.getObjectMapper().registerModule(new Jdk8Module());
+ converters.add(converter);
+ super.configureMessageConverters(converters);
+ }
}
diff --git a/juick-ws/src/main/static/scripts.js b/juick-ws/src/main/static/scripts.js
index 2691816d..9b4c721f 100644
--- a/juick-ws/src/main/static/scripts.js
+++ b/juick-ws/src/main/static/scripts.js
@@ -10,7 +10,7 @@ function ready(fn) {
}
ready(function() {
- var ws = new WebSocket('wss://ws.juick.com/_replies');
+ var ws = new WebSocket('wss://ws.juick.com/');
var term = new Terminal('terminal', {}, {});
var status = document.querySelector("#status");
ws.onopen = function() {
@@ -30,7 +30,7 @@ ready(function() {
.then(function(response) {
return response.text();
}).then(function(body) {
- status.textContent = JSON.parse(body).clientsCount;
+ status.textContent = JSON.parse(body).status;
})
}, 5000);
}) \ No newline at end of file