Polish
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
package sample.websocket;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
|
||||
import sample.data.ActiveWebSocketUser;
|
||||
import sample.data.ActiveWebSocketUserRepository;
|
||||
@@ -51,7 +51,7 @@ public class WebSocketConnectHandler<S> implements ApplicationListener<SessionCo
|
||||
}
|
||||
String id = SimpMessageHeaderAccessor.getSessionId(headers);
|
||||
this.repository.save(new ActiveWebSocketUser(id, user.getName(), Calendar.getInstance()));
|
||||
this.messagingTemplate.convertAndSend("/topic/friends/signin", Arrays.asList(user.getName()));
|
||||
this.messagingTemplate.convertAndSend("/topic/friends/signin", Collections.singletonList(user.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package sample.websocket;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import sample.data.ActiveWebSocketUserRepository;
|
||||
|
||||
@@ -45,7 +45,8 @@ public class WebSocketDisconnectHandler<S> implements ApplicationListener<Sessio
|
||||
}
|
||||
this.repository.findById(id).ifPresent((user) -> {
|
||||
this.repository.deleteById(id);
|
||||
this.messagingTemplate.convertAndSend("/topic/friends/signout", Arrays.asList(user.getUsername()));
|
||||
this.messagingTemplate.convertAndSend("/topic/friends/signout",
|
||||
Collections.singletonList(user.getUsername()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package sample;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -58,7 +58,7 @@ class RestTests {
|
||||
@Test
|
||||
void unauthenticatedUserSentToLogInPage() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
assertThatExceptionOfType(HttpClientErrorException.class)
|
||||
.isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class))
|
||||
.satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
|
||||
@@ -85,7 +85,7 @@ class RestTests {
|
||||
String token = entity.getHeaders().getFirst(X_AUTH_TOKEN);
|
||||
|
||||
HttpHeaders authTokenHeader = new HttpHeaders();
|
||||
authTokenHeader.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
||||
authTokenHeader.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
authTokenHeader.set(X_AUTH_TOKEN, token);
|
||||
ResponseEntity<User> authTokenResponse = getForUser(this.baseUrl + "/", authTokenHeader, User.class);
|
||||
assertThat(authTokenResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@@ -113,7 +113,7 @@ class RestTests {
|
||||
|
||||
private HttpHeaders getHttpHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,21 +71,12 @@ public class Initializer implements ServletContextListener {
|
||||
}
|
||||
|
||||
private static int getAvailablePort() {
|
||||
ServerSocket socket = null;
|
||||
try {
|
||||
socket = new ServerSocket(0);
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
return socket.getLocalPort();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user