aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws/configuration
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-25 21:36:50 +0300
committerGravatar Vitaly Takmazov2016-07-27 13:56:09 +0300
commit69af3f60d399157a8951988fa2f91d29c553fbb5 (patch)
tree8c38def00d1b3dc5e38cf421870afb62f3a823ea /juick-ws/src/main/java/com/juick/ws/configuration
parent94c0d43d2765488d715bffe426934ed7caa8f4f2 (diff)
juick-ws: websocket terminal
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws/configuration')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java47
1 files changed, 47 insertions, 0 deletions
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 d432b19c..c25f8f42 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
@@ -2,6 +2,11 @@ package com.juick.ws.configuration;
import com.juick.ws.WebsocketComponent;
import com.juick.ws.XMPPConnection;
+import com.mitchellbosecke.pebble.PebbleEngine;
+import com.mitchellbosecke.pebble.loader.Loader;
+import com.mitchellbosecke.pebble.loader.ServletLoader;
+import com.mitchellbosecke.pebble.spring4.PebbleViewResolver;
+import com.mitchellbosecke.pebble.spring4.extension.SpringExtension;
import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -9,13 +14,18 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
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.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import javax.inject.Inject;
+import javax.servlet.ServletContext;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -47,6 +57,36 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
dataSource.setUrl(env.getProperty("datasource_url"));
return new JdbcTemplate(dataSource);
}
+ @Inject
+ private ServletContext servletContext;
+
+ @Bean
+ public Loader templateLoader(){
+ return new ServletLoader(servletContext);
+ }
+
+ @Bean
+ public SpringExtension springExtension() {
+ return new SpringExtension();
+ }
+
+ @Bean
+ public PebbleEngine pebbleEngine() {
+ return new PebbleEngine.Builder()
+ .loader(this.templateLoader())
+ .extension(springExtension())
+ .build();
+ }
+
+ @Bean
+ public ViewResolver viewResolver() {
+ PebbleViewResolver viewResolver = new PebbleViewResolver();
+ viewResolver.setPrefix("/WEB-INF/templates/");
+ viewResolver.setSuffix(".html");
+ viewResolver.setPebbleEngine(pebbleEngine());
+ return viewResolver;
+ }
+
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
@@ -57,4 +97,11 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(wsHandler(), "/**").setAllowedOrigins("*");
}
+
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.setOrder(0);
+ registry.addResourceHandler("/scripts.js").addResourceLocations("/");
+ registry.addResourceHandler("/style.css").addResourceLocations("/");
+ }
}