Polishing

This commit is contained in:
Juergen Hoeller
2015-07-21 22:58:34 +02:00
parent 1a636b1023
commit edd6e76b9f
43 changed files with 244 additions and 262 deletions

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.messaging;
import org.springframework.messaging.Message;
@@ -35,7 +36,6 @@ public class StompSubProtocolErrorHandler implements SubProtocolErrorHandler<byt
@Override
public Message<byte[]> handleClientMessageProcessingError(Message<byte[]> clientMessage, Throwable ex) {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.setMessage(ex.getMessage());
accessor.setLeaveMutable(true);
@@ -54,14 +54,11 @@ public class StompSubProtocolErrorHandler implements SubProtocolErrorHandler<byt
@Override
public Message<byte[]> handleErrorMessageToClient(Message<byte[]> errorMessage) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(errorMessage, StompHeaderAccessor.class);
Assert.notNull(accessor, "Expected STOMP headers.");
Assert.notNull(accessor, "Expected STOMP headers");
if (!accessor.isMutable()) {
accessor = StompHeaderAccessor.wrap(errorMessage);
}
return handleInternal(accessor, errorMessage.getPayload(), null, null);
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.messaging;
import org.springframework.messaging.Message;
@@ -28,12 +29,10 @@ public interface SubProtocolErrorHandler<P> {
/**
* Handle errors thrown while processing client messages providing an
* opportunity to prepare the error message or to prevent one from being sent.
*
* <p>Note that the STOMP protocol requires a server to close the connection
* after sending an ERROR frame. To prevent an ERROR frame from being sent,
* a handler could return {@code null} and send a notification message
* through the broker instead, e.g. via a user destination.
*
* @param clientMessage the client message related to the error, possibly
* {@code null} if error occurred while parsing a WebSocket message
* @param ex the cause for the error, never {@code null}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.messaging;
import java.io.IOException;
@@ -87,7 +88,6 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* Class constructor. Sets {@link #setDefaultHeartbeat} to "0,0" but will
* reset it back to the preferred "10000,10000" when a
* {@link #setTaskScheduler} is configured.
*
* @param webSocketClient the WebSocket client to connect with
*/
public WebSocketStompClient(WebSocketClient webSocketClient) {
@@ -302,13 +302,11 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
private final List<ScheduledFuture<?>> inactivityTasks = new ArrayList<ScheduledFuture<?>>(2);
public WebSocketTcpConnectionHandlerAdapter(TcpConnectionHandler<byte[]> connectionHandler) {
Assert.notNull(connectionHandler);
this.connectionHandler = connectionHandler;
}
// ListenableFutureCallback implementation: handshake outcome
@Override
@@ -320,7 +318,6 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
this.connectionHandler.afterConnectFailure(ex);
}
// WebSocketHandler implementation
@Override
@@ -375,7 +372,6 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
return false;
}
// TcpConnection implementation
@Override
@@ -466,12 +462,10 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
private final BufferingStompDecoder bufferingDecoder;
public StompWebSocketMessageCodec(int messageSizeLimit) {
this.bufferingDecoder = new BufferingStompDecoder(DECODER, messageSizeLimit);
}
public List<Message<byte[]>> decode(WebSocketMessage<?> webSocketMessage) {
List<Message<byte[]>> result = Collections.<Message<byte[]>>emptyList();
ByteBuffer byteBuffer;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.server.support;
import javax.servlet.ServletContext;

View File

@@ -172,7 +172,7 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
}
/**
* @deprecated as of 4.2 this method is no longer used.
* @deprecated as of 4.2, since this method is no longer used.
*/
@Deprecated
protected abstract boolean isStreaming();

View File

@@ -47,7 +47,7 @@ public abstract class StreamingSockJsSession extends AbstractHttpSockJsSession {
/**
* @deprecated as of 4.2 this method is no longer used.
* @deprecated as of 4.2, since this method is no longer used.
*/
@Override
@Deprecated
@@ -61,6 +61,7 @@ public abstract class StreamingSockJsSession extends AbstractHttpSockJsSession {
*/
protected abstract byte[] getPrelude(ServerHttpRequest request);
@Override
protected void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
boolean initialRequest) throws IOException {
@@ -84,15 +85,13 @@ public abstract class StreamingSockJsSession extends AbstractHttpSockJsSession {
SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, message);
writeFrame(frame);
this.byteCount += frame.getContentBytes().length + 1;
this.byteCount += (frame.getContentBytes().length + 1);
if (logger.isTraceEnabled()) {
logger.trace(this.byteCount + " bytes written so far, "
+ getMessageCache().size() + " more messages not flushed");
logger.trace(this.byteCount + " bytes written so far, " +
getMessageCache().size() + " more messages not flushed");
}
if (this.byteCount >= getSockJsServiceConfig().getStreamBytesLimit()) {
if (logger.isTraceEnabled()) {
logger.trace("Streamed bytes limit reached. Recycling current request");
}
logger.trace("Streamed bytes limit reached, recycling current request");
resetRequest();
this.byteCount = 0;
break;