aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java
index 3e8b3865..23f550a5 100644
--- a/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java
+++ b/juick-server-web/src/main/java/com/juick/server/configuration/JuickServerComponentConfiguration.java
@@ -2,6 +2,9 @@ package com.juick.server.configuration;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.server.component.JuickServerComponent;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -11,6 +14,7 @@ import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
import org.springframework.http.client.support.BasicAuthorizationInterceptor;
import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
@@ -24,6 +28,7 @@ import java.util.List;
@Configuration
@EnableScheduling
public class JuickServerComponentConfiguration {
+ private static final Logger logger = LoggerFactory.getLogger(JuickServerComponentConfiguration.class);
@Value("${websocket_url:ws://localhost:8080/}")
private String baseUri;
@Value("${api_user:juick}")
@@ -44,10 +49,15 @@ public class JuickServerComponentConfiguration {
return rest;
}
@Bean
- public WebSocketConnectionManager connectionManager() throws IOException {
- ResponseEntity<String> response = rest().exchange("https://api.juick.com/auth",
- HttpMethod.GET, null, String.class);
- String hash = jsonMapper.readValue(response.getBody(), String.class);
+ public WebSocketConnectionManager connectionManager() {
+ String hash = StringUtils.EMPTY;
+ try {
+ ResponseEntity<String> response = rest().exchange("https://api.juick.com/auth",
+ HttpMethod.GET, null, String.class);
+ hash = jsonMapper.readValue(response.getBody(), String.class);
+ } catch (HttpClientErrorException | IOException e) {
+ logger.warn("service component is not authenticated", e);
+ }
String websocketURI = UriComponentsBuilder.fromUriString(baseUri)
.queryParam("hash", hash).build().toUriString();
WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), juickServerComponent, websocketURI);