Backport selected refinements from the nullability efforts

Issue: SPR-15656
This commit is contained in:
Juergen Hoeller
2017-09-27 00:09:58 +02:00
parent 18a3322d2f
commit 9fdc4404a5
194 changed files with 1236 additions and 1218 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2017 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.
@@ -28,15 +28,15 @@ import org.springframework.web.socket.WebSocketSession;
public interface NativeWebSocketSession extends WebSocketSession {
/**
* Return the underlying native WebSocketSession, if available.
* @return the native session or {@code null}
* Return the underlying native WebSocketSession.
*/
Object getNativeSession();
/**
* Return the underlying native WebSocketSession, if available.
* @param requiredType the required type of the session
* @return the native session of the required type or {@code null}
* @return the native session of the required type,
* or {@code null} if not available
*/
<T> T getNativeSession(Class<T> requiredType);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -89,7 +89,7 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
}
/**
* @return the configured origin.
* Return the configured origin.
*/
public String getOrigin() {
return this.headers.getOrigin();
@@ -151,7 +151,9 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
@Override
protected void closeConnection() throws Exception {
this.webSocketSession.close();
if (this.webSocketSession != null) {
this.webSocketSession.close();
}
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -84,9 +84,8 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
/**
* Set an {@link AsyncListenableTaskExecutor} to use when opening connections.
* If this property is set to {@code null}, calls to any of the
* If this property is set to {@code null}, calls to any of the
* {@code doHandshake} methods will block until the connection is established.
*
* <p>By default an instance of {@code SimpleAsyncTaskExecutor} is used.
*/
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -106,11 +106,11 @@ public class WebSocketMessageBrokerStats {
}
private ScheduledFuture<?> initLoggingTask(long initialDelay) {
if (logger.isInfoEnabled() && this.loggingPeriod > 0) {
if (this.loggingPeriod > 0 && logger.isInfoEnabled()) {
return this.sockJsTaskScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
logger.info(WebSocketMessageBrokerStats.this.toString());
logger.info(WebSocketMessageBrokerStats.this);
}
}, initialDelay, this.loggingPeriod, TimeUnit.MILLISECONDS);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -31,9 +31,9 @@ import org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsSe
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
/**
* A helper class for configuring SockJS fallback options, typically used indirectly, in
* conjunction with {@link org.springframework.web.socket.config.annotation.EnableWebSocket @EnableWebSocket} and
* {@link WebSocketConfigurer}.
* A helper class for configuring SockJS fallback options for use with an
* {@link org.springframework.web.socket.config.annotation.EnableWebSocket} and
* {@link WebSocketConfigurer} setup.
*
* @author Rossen Stoyanchev
* @since 4.0
@@ -264,12 +264,11 @@ public class SockJsServiceRegistration {
if (this.webSocketEnabled != null) {
service.setWebSocketEnabled(this.webSocketEnabled);
}
if (this.allowedOrigins != null) {
service.setAllowedOrigins(this.allowedOrigins);
}
if (this.suppressCors != null) {
service.setSuppressCors(this.suppressCors);
}
service.setAllowedOrigins(this.allowedOrigins);
if (this.messageCodec != null) {
service.setMessageCodec(this.messageCodec);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -16,7 +16,9 @@
package org.springframework.web.socket.config.annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
@@ -32,13 +34,11 @@ import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler
import org.springframework.web.socket.sockjs.SockJsService;
import org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler;
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
import java.util.ArrayList;
import java.util.List;
/**
* An abstract base class for configuring STOMP over WebSocket/SockJS endpoints.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 4.0
*/
public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketEndpointRegistration {
@@ -55,7 +55,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
private final List<String> allowedOrigins = new ArrayList<String>();
private StompSockJsServiceRegistration registration;
private SockJsServiceRegistration registration;
public WebMvcStompWebSocketEndpointRegistration(String[] paths, WebSocketHandler webSocketHandler,
@@ -69,6 +69,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
this.sockJsTaskScheduler = sockJsTaskScheduler;
}
@Override
public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) {
Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null");
@@ -95,14 +96,14 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
@Override
public SockJsServiceRegistration withSockJS() {
this.registration = new StompSockJsServiceRegistration(this.sockJsTaskScheduler);
this.registration = new SockJsServiceRegistration(this.sockJsTaskScheduler);
HandshakeInterceptor[] interceptors = getInterceptors();
if (interceptors.length > 0) {
this.registration.setInterceptors(interceptors);
}
if (this.handshakeHandler != null) {
WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler);
this.registration.setTransportHandlerOverrides(transportHandler);
WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler);
this.registration.setTransportHandlerOverrides(handler);
}
if (!this.allowedOrigins.isEmpty()) {
this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
@@ -146,16 +147,4 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
return mappings;
}
private static class StompSockJsServiceRegistration extends SockJsServiceRegistration {
public StompSockJsServiceRegistration(TaskScheduler defaultTaskScheduler) {
super(defaultTaskScheduler);
}
protected SockJsService getSockJsService() {
return super.getSockJsService();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -134,7 +134,7 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
MappingJackson2MessageConverter messageConverter = super.createJacksonConverter();
// Use Jackson builder in order to have JSR-310 and Joda-Time modules registered automatically
messageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json()
.applicationContext(this.getApplicationContext()).build());
.applicationContext(getApplicationContext()).build());
return messageConverter;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
package org.springframework.web.socket.messaging;
import java.security.Principal;
import org.springframework.messaging.Message;
@@ -31,7 +30,6 @@ import org.springframework.messaging.Message;
@SuppressWarnings("serial")
public class SessionSubscribeEvent extends AbstractSubProtocolEvent {
public SessionSubscribeEvent(Object source, Message<byte[]> message) {
super(source, message);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
package org.springframework.web.socket.messaging;
import java.security.Principal;
import org.springframework.messaging.Message;
@@ -31,7 +30,6 @@ import org.springframework.messaging.Message;
@SuppressWarnings("serial")
public class SessionUnsubscribeEvent extends AbstractSubProtocolEvent {
public SessionUnsubscribeEvent(Object source, Message<byte[]> message) {
super(source, message);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -19,6 +19,7 @@ package org.springframework.web.socket.messaging;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
@@ -28,7 +29,6 @@ import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
import org.springframework.web.method.ControllerAdviceBean;
/**
* A sub-class of {@link SimpAnnotationMethodMessageHandler} to provide support
* for {@link org.springframework.web.bind.annotation.ControllerAdvice
@@ -39,7 +39,6 @@ import org.springframework.web.method.ControllerAdviceBean;
*/
public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMethodMessageHandler {
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel,
MessageChannel clientOutChannel, SimpMessageSendingOperations brokerTemplate) {
@@ -54,13 +53,14 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
}
private void initControllerAdviceCache() {
if (getApplicationContext() == null) {
ApplicationContext context = getApplicationContext();
if (context == null) {
return;
}
if (logger.isDebugEnabled()) {
logger.debug("Looking for @MessageExceptionHandler mappings: " + getApplicationContext());
logger.debug("Looking for @MessageExceptionHandler mappings: " + context);
}
List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(context);
AnnotationAwareOrderComparator.sort(beans);
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(beans));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -63,7 +63,7 @@ public class ServletServerContainerFactoryBean
this.asyncSendTimeout = timeoutInMillis;
}
public long getAsyncSendTimeout() {
public Long getAsyncSendTimeout() {
return this.asyncSendTimeout;
}

View File

@@ -309,15 +309,19 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
}
public void afterTransportClosed(CloseStatus closeStatus) {
this.closeStatus = (this.closeStatus != null ? this.closeStatus : closeStatus);
Assert.state(this.closeStatus != null, "CloseStatus not available");
CloseStatus cs = this.closeStatus;
if (cs == null) {
cs = closeStatus;
this.closeStatus = closeStatus;
}
Assert.state(cs != null, "CloseStatus not available");
if (logger.isDebugEnabled()) {
logger.debug("Transport closed with " + this.closeStatus + " in " + this);
logger.debug("Transport closed with " + cs + " in " + this);
}
this.state = State.CLOSED;
try {
this.webSocketHandler.afterConnectionClosed(this, this.closeStatus);
this.webSocketHandler.afterConnectionClosed(this, cs);
}
catch (Throwable ex) {
logger.error("WebSocketHandler.afterConnectionClosed threw an exception", ex);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
package org.springframework.web.socket.sockjs.client;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.List;
@@ -57,12 +56,7 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
@SuppressWarnings("unchecked")
@Override
public <T> T getNativeSession(Class<T> requiredType) {
if (requiredType != null) {
if (requiredType.isInstance(this.webSocketSession)) {
return (T) this.webSocketSession;
}
}
return null;
return (requiredType == null || requiredType.isInstance(this.webSocketSession) ? (T) this.webSocketSession : null);
}
@Override

View File

@@ -121,8 +121,8 @@ public abstract class AbstractSockJsSession implements SockJsSession {
public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler,
Map<String, Object> attributes) {
Assert.notNull(id, "SessionId must not be null");
Assert.notNull(config, "SockJsConfig must not be null");
Assert.notNull(id, "Session id must not be null");
Assert.notNull(config, "SockJsServiceConfig must not be null");
Assert.notNull(handler, "WebSocketHandler must not be null");
this.id = id;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -140,7 +140,7 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
@Override
public Object getNativeSession() {
return (this.webSocketSession instanceof NativeWebSocketSession ?
((NativeWebSocketSession) this.webSocketSession).getNativeSession() : null);
((NativeWebSocketSession) this.webSocketSession).getNativeSession() : this.webSocketSession);
}
@Override
@@ -190,7 +190,9 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
tryCloseWithSockJsTransportError(ex, CloseStatus.BAD_DATA);
return;
}
delegateMessages(messages);
if (messages != null) {
delegateMessages(messages);
}
}
@Override
@@ -226,7 +228,9 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
synchronized (this.disconnectLock) {
if (isActive()) {
this.disconnected = true;
this.webSocketSession.close(status);
if (this.webSocketSession != null) {
this.webSocketSession.close(status);
}
}
}
}