diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java index e56b2a3703e..708f277b9cc 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -26,15 +26,14 @@ import org.springframework.util.Assert; /** * Base class for STOMP client implementations. * - *

Subclasses can connect over WebSocket or TCP using any library. - * When creating a new connection a sub-class can create an instance of - * {@link DefaultStompSession} which extends - * {@link org.springframework.messaging.tcp.TcpConnectionHandler - * TcpConnectionHandler} whose lifecycle methods the sub-class must then invoke. + *

Subclasses can connect over WebSocket or TCP using any library. When creating + * a new connection, a subclass can create an instance of @link DefaultStompSession} + * which extends {@link org.springframework.messaging.tcp.TcpConnectionHandler} + * whose lifecycle methods the subclass must then invoke. * - *

In effect {@code TcpConnectionHandler} and {@code TcpConnection} are the - * contracts any sub-class must adapt to while using {@link StompEncoder} and - * {@link StompDecoder} to encode and decode STOMP messages. + *

In effect, {@code TcpConnectionHandler} and {@code TcpConnection} are the + * contracts that any subclass must adapt to while using {@link StompEncoder} + * and {@link StompDecoder} to encode and decode STOMP messages. * * @author Rossen Stoyanchev * @since 4.2 @@ -58,7 +57,7 @@ public abstract class StompClientSupport { * @param messageConverter the message converter to use */ public void setMessageConverter(MessageConverter messageConverter) { - Assert.notNull(messageConverter, "'messageConverter' must not be null"); + Assert.notNull(messageConverter, "MessageConverter must not be null"); this.messageConverter = messageConverter; } @@ -92,7 +91,7 @@ public abstract class StompClientSupport { * CONNECT frame. The first number represents how often the client will write * or send a heart-beat. The second is how often the server should write. * A value of 0 means no heart-beats. - *

By default this is set to "10000,10000" but sub-classes may override + *

By default this is set to "10000,10000" but subclasses may override * that default and for example set it to "0,0" if they require a * TaskScheduler to be configured first. * @param heartbeat the value for the CONNECT "heart-beat" header @@ -100,22 +99,23 @@ public abstract class StompClientSupport { * http://stomp.github.io/stomp-specification-1.2.html#Heart-beating */ public void setDefaultHeartbeat(long[] heartbeat) { - Assert.notNull(heartbeat); - Assert.isTrue(heartbeat[0] >= 0 && heartbeat[1] >=0 , "Invalid heart-beat: " + Arrays.toString(heartbeat)); + if (heartbeat == null || heartbeat.length != 2 || heartbeat[0] < 0 || heartbeat[1] < 0) { + throw new IllegalArgumentException("Invalid heart-beat: " + Arrays.toString(heartbeat)); + } this.defaultHeartbeat = heartbeat; } /** - * Return the configured default heart-beat value, never {@code null}. + * Return the configured default heart-beat value (never {@code null}). */ public long[] getDefaultHeartbeat() { return this.defaultHeartbeat; } /** - * Whether heartbeats are enabled. Returns {@code false} if - * {@link #setDefaultHeartbeat defaultHeartbeat} is set to "0,0", and - * {@code true} otherwise. + * Determine whether heartbeats are enabled. + *

Returns {@code false} if {@link #setDefaultHeartbeat defaultHeartbeat} + * is set to "0,0", and {@code true} otherwise. */ public boolean isDefaultHeartbeatEnabled() { return (getDefaultHeartbeat() != null && getDefaultHeartbeat()[0] != 0 && getDefaultHeartbeat()[1] != 0); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index 9becb2dfa05..cd35ed13aae 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -18,7 +18,6 @@ package org.springframework.messaging.simp.stomp; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java index c1608e1bb03..4939b506ab1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java @@ -20,7 +20,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -47,7 +47,7 @@ public final class StompEncoder { private static final byte COLON = ':'; - private final Log logger = LogFactory.getLog(StompEncoder.class); + private static final Log logger = LogFactory.getLog(StompEncoder.class); /** @@ -79,6 +79,7 @@ public final class StompEncoder { } output.write(StompDecoder.HEARTBEAT_PAYLOAD); } + else { StompCommand command = StompHeaderAccessor.getCommand(headers); if (command == null) { @@ -100,8 +101,8 @@ public final class StompEncoder { } } - private void writeHeaders(StompCommand command, Map headers, byte[] payload, DataOutputStream output) - throws IOException { + private void writeHeaders(StompCommand command, Map headers, byte[] payload, + DataOutputStream output) throws IOException { @SuppressWarnings("unchecked") Map> nativeHeaders = @@ -125,7 +126,7 @@ public final class StompEncoder { List values = entry.getValue(); if (StompCommand.CONNECT.equals(command) && StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) { - values = Arrays.asList(StompHeaderAccessor.getPasscode(headers)); + values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers)); } byte[] encodedKey = encodeHeaderString(entry.getKey(), shouldEscape);