diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java index 46723c87bac..7b782d6a0ee 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -272,8 +272,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { } private boolean isEmpty(@Nullable Object payload) { - return payload == null || StringUtils.isEmpty(payload) || - (payload instanceof byte[] && ((byte[]) payload).length == 0); + return (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0)); } private void execute(Message message) { @@ -689,8 +688,10 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { if (conn != null) { conn.send(HEARTBEAT).addCallback( new ListenableFutureCallback() { + @Override public void onSuccess(@Nullable Void result) { } + @Override public void onFailure(Throwable ex) { handleFailure(ex); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java index 5fbb9ead26d..fbd70f3598d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java @@ -82,7 +82,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { /** - * Sub-classes can use this method to access the "native" headers sub-map. + * Subclasses can use this method to access the "native" headers sub-map. */ @SuppressWarnings("unchecked") @Nullable @@ -139,6 +139,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { /** * Whether the native header map contains the give header name. + * @param headerName the name of the header */ public boolean containsNativeHeader(String headerName) { Map> map = getNativeHeaders(); @@ -146,7 +147,9 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { } /** - * Return the values for the specified native header, if present. + * Return all values for the specified native header, if present. + * @param headerName the name of the header + * @return the associated values, or {@code null} if none */ @Nullable public List getNativeHeader(String headerName) { @@ -156,13 +159,15 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { /** * Return the first value for the specified native header, if present. + * @param headerName the name of the header + * @return the associated value, or {@code null} if none */ @Nullable public String getFirstNativeHeader(String headerName) { Map> map = getNativeHeaders(); if (map != null) { List values = map.get(headerName); - if (values != null) { + if (!CollectionUtils.isEmpty(values)) { return values.get(0); } } @@ -200,6 +205,8 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * Add the specified native header value to existing values. *

In order for this to work, the accessor must be {@link #isMutable() * mutable}. See {@link MessageHeaderAccessor} for details. + * @param name the name of the header + * @param value the header value to set */ public void addNativeHeader(String name, @Nullable String value) { Assert.state(isMutable(), "Already immutable"); @@ -216,6 +223,10 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { setModified(true); } + /** + * Add the specified native headers to existing values. + * @param headers the headers to set + */ public void addNativeHeaders(@Nullable MultiValueMap headers) { if (headers == null) { return; @@ -227,24 +238,34 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * Remove the specified native header value replacing existing values. *

In order for this to work, the accessor must be {@link #isMutable() * mutable}. See {@link MessageHeaderAccessor} for details. + * @param headerName the name of the header + * @return the associated values, or {@code null} if the header was not present */ @Nullable - public List removeNativeHeader(String name) { + public List removeNativeHeader(String headerName) { Assert.state(isMutable(), "Already immutable"); Map> nativeHeaders = getNativeHeaders(); - if (nativeHeaders == null) { + if (CollectionUtils.isEmpty(nativeHeaders)) { return null; } - return nativeHeaders.remove(name); + return nativeHeaders.remove(headerName); } + + /** + * Return the first value for the specified native header, + * or {@code null} if none. + * @param headerName the name of the header + * @param headers the headers map to introspect + * @return the associated value, or {@code null} if none + */ @SuppressWarnings("unchecked") @Nullable public static String getFirstNativeHeader(String headerName, Map headers) { Map> map = (Map>) headers.get(NATIVE_HEADERS); if (map != null) { List values = map.get(headerName); - if (values != null) { + if (!CollectionUtils.isEmpty(values)) { return values.get(0); } } diff --git a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java b/spring-web/src/main/java/org/springframework/http/ResponseCookie.java index 68373c46388..d11b5dad0ed 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseCookie.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -185,7 +185,7 @@ public final class ResponseCookie extends HttpCookie { * with a name-value pair and may also include attributes. * @param name the cookie name * @param value the cookie value - * @return the created cookie instance + * @return a builder to create the cookie with */ public static ResponseCookieBuilder from(final String name, final String value) { diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java index b019a6192cb..7532945a88d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -38,7 +38,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.lang.Nullable; -import org.springframework.util.Assert; /** * {@link ClientHttpRequest} implementation for the Jetty ReactiveStreams HTTP client. @@ -65,9 +64,7 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { @Override public HttpMethod getMethod() { - HttpMethod method = HttpMethod.resolve(this.jettyRequest.getMethod()); - Assert.state(method != null, "Method must not be null"); - return method; + return HttpMethod.valueOf(this.jettyRequest.getMethod()); } @Override @@ -119,7 +116,6 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { public void succeeded() { DataBufferUtils.release(buffer); } - @Override public void failed(Throwable x) { DataBufferUtils.release(buffer);