aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main')
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java22
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java5
2 files changed, 24 insertions, 3 deletions
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
index 388fda67..a475ca6f 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiAppConfiguration.java
@@ -21,10 +21,15 @@ import com.juick.api.ApiServer;
import com.juick.server.component.JuickServerComponent;
import com.juick.server.component.JuickServerReconnectManager;
import com.juick.server.configuration.BaseWebConfiguration;
+import com.juick.service.UserService;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.socket.client.WebSocketConnectionManager;
+import org.springframework.web.socket.client.standard.StandardWebSocketClient;
+import org.springframework.web.util.UriComponentsBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
@@ -32,6 +37,7 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
+import javax.inject.Inject;
import java.util.Collections;
/**
@@ -44,6 +50,12 @@ import java.util.Collections;
@PropertySource("classpath:juick.conf")
@ComponentScan(basePackages = "com.juick")
public class ApiAppConfiguration extends BaseWebConfiguration {
+ @Inject
+ UserService userService;
+ @Value("${api_user:juick}")
+ private String serviceUser;
+ @Value("${websocket_url:ws://localhost:8080/}")
+ private String baseUri;
@Lazy
@Bean
public JuickServerComponent juickServerComponent() {
@@ -55,6 +67,16 @@ public class ApiAppConfiguration extends BaseWebConfiguration {
return new JuickServerReconnectManager();
}
@Bean
+ public WebSocketConnectionManager connectionManager() {
+ String websocketURI = UriComponentsBuilder.fromUriString(baseUri)
+ .queryParam("hash", userService.getHashByUID(userService.getUIDbyName(serviceUser))).build().toUriString();
+ return new WebSocketConnectionManager(client(), juickServerComponent(), websocketURI);
+ }
+ @Bean
+ public StandardWebSocketClient client() {
+ return new StandardWebSocketClient();
+ }
+ @Bean
public ApiServer apiServer() {
return new ApiServer();
}
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
index edda931b..8f35e3f7 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiInitializer.java
@@ -18,7 +18,7 @@
package com.juick.api.configuration;
import com.juick.configuration.DataConfiguration;
-import com.juick.server.configuration.JuickServerComponentConfiguration;
+import com.juick.server.configuration.JuickServerWebsocketConfiguration;
import com.juick.server.configuration.StorageConfiguration;
import org.apache.commons.codec.CharEncoding;
import org.springframework.web.filter.CharacterEncodingFilter;
@@ -37,8 +37,7 @@ public class ApiInitializer extends AbstractAnnotationConfigDispatcherServletIni
return new Class<?>[]{
ApiSecurityConfig.class,
DataConfiguration.class,
- StorageConfiguration.class,
- JuickServerComponentConfiguration.class
+ StorageConfiguration.class
};
}