diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java index 493f009283..fe9972e7c8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -209,10 +209,9 @@ public final class CloseStatus implements Serializable { if (this == other) { return true; } - if (!(other instanceof CloseStatus)) { + if (!(other instanceof CloseStatus otherStatus)) { return false; } - CloseStatus otherStatus = (CloseStatus) other; return (this.code == otherStatus.code && ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason)); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java index 84a3503bfc..cb30c423bb 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -311,10 +311,9 @@ public class WebSocketHttpHeaders extends HttpHeaders { if (this == other) { return true; } - if (!(other instanceof WebSocketHttpHeaders)) { + if (!(other instanceof WebSocketHttpHeaders otherHeaders)) { return false; } - WebSocketHttpHeaders otherHeaders = (WebSocketHttpHeaders) other; return this.headers.equals(otherHeaders.headers); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java index 989100f935..c2ad134e8e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ import org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator; * this will be done automatically when the Spring ApplicationContext is refreshed. * * @author Rossen Stoyanchev + * @author Sam Brannen * @since 4.0 */ public class WebSocketConnectionManager extends ConnectionManagerSupport { @@ -46,7 +47,7 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { @Nullable private WebSocketSession webSocketSession; - private WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); + private final WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); public WebSocketConnectionManager(WebSocketClient client, @@ -116,16 +117,16 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { @Override public void startInternal() { - if (this.client instanceof Lifecycle && !((Lifecycle) this.client).isRunning()) { - ((Lifecycle) this.client).start(); + if (this.client instanceof Lifecycle lifecycle && !lifecycle.isRunning()) { + lifecycle.start(); } super.startInternal(); } @Override public void stopInternal() throws Exception { - if (this.client instanceof Lifecycle && ((Lifecycle) this.client).isRunning()) { - ((Lifecycle) this.client).stop(); + if (this.client instanceof Lifecycle lifecycle && lifecycle.isRunning()) { + lifecycle.stop(); } super.stopInternal(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java index 5bef6ac61f..ba9d1f9e54 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,6 +43,7 @@ import org.springframework.util.Assert; * track of connected users and their subscriptions. * * @author Rossen Stoyanchev + * @author Sam Brannen * @since 4.2 */ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicationListener { @@ -105,8 +106,8 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati return; } String name = user.getName(); - if (user instanceof DestinationUserNameProvider) { - name = ((DestinationUserNameProvider) user).getDestinationUserName(); + if (user instanceof DestinationUserNameProvider destinationUserNameProvider) { + name = destinationUserNameProvider.getDestinationUserName(); } synchronized (this.sessionLock) { LocalSimpUser simpUser = this.users.get(name); @@ -238,7 +239,7 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati @Override public boolean equals(@Nullable Object other) { return (this == other || - (other instanceof SimpUser && getName().equals(((SimpUser) other).getName()))); + (other instanceof SimpUser otherSimpUser && getName().equals(otherSimpUser.getName()))); } @Override @@ -294,7 +295,7 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati @Override public boolean equals(@Nullable Object other) { return (this == other || - (other instanceof SimpSubscription && getId().equals(((SimpSubscription) other).getId()))); + (other instanceof SimpSubscription otherSubscription && getId().equals(otherSubscription.getId()))); } @Override @@ -346,10 +347,9 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati if (this == other) { return true; } - if (!(other instanceof SimpSubscription)) { + if (!(other instanceof SimpSubscription otherSubscription)) { return false; } - SimpSubscription otherSubscription = (SimpSubscription) other; return (getId().equals(otherSubscription.getId()) && getSession().getId().equals(otherSubscription.getSession().getId())); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java index ba020c32fe..8ce26a3711 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,9 @@ import org.springframework.web.socket.server.HandshakeInterceptor; /** * An interceptor to copy information from the HTTP session to the "handshake - * attributes" map to made available via{@link WebSocketSession#getAttributes()}. + * attributes" map to be made available via {@link WebSocketSession#getAttributes()}. * - *
Copies a subset or all HTTP session attributes and/or the HTTP session id + *
Copies a subset or all HTTP session attributes and/or the HTTP session ID
* under the key {@link #HTTP_SESSION_ID_ATTR_NAME}.
*
* @author Rossen Stoyanchev
@@ -164,8 +164,7 @@ public class HttpSessionHandshakeInterceptor implements HandshakeInterceptor {
@Nullable
private HttpSession getSession(ServerHttpRequest request) {
- if (request instanceof ServletServerHttpRequest) {
- ServletServerHttpRequest serverRequest = (ServletServerHttpRequest) request;
+ if (request instanceof ServletServerHttpRequest serverRequest) {
return serverRequest.getServletRequest().getSession(isCreateSession());
}
return null;
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
index 32eb9c0f4c..e69f0e2ce6 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ class DefaultTransportRequest implements TransportRequest {
private final TransportType serverTransportType;
- private SockJsMessageCodec codec;
+ private final SockJsMessageCodec codec;
@Nullable
private Principal user;
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java
index 1ac4bc8fba..6f59483348 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,6 +56,7 @@ import org.springframework.web.util.UriComponentsBuilder;
* the transports it is configured with.
*
* @author Rossen Stoyanchev
+ * @author Sam Brannen
* @since 4.1
* @see https://github.com/sockjs/sockjs-client
* @see org.springframework.web.socket.sockjs.client.Transport
@@ -114,8 +115,8 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
private static InfoReceiver initInfoReceiver(List