From 12973ac702d2262c3ea5c785a332ebc6fce0391a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 24 Jan 2017 00:12:53 +0100 Subject: [PATCH] Polishing --- build.gradle | 4 +- .../stomp/StompBrokerRelayMessageHandler.java | 4 +- .../web/socket/sockjs/frame/SockJsFrame.java | 137 +++++++++--------- 3 files changed, 73 insertions(+), 72 deletions(-) diff --git a/build.gradle b/build.gradle index eb2702f75e..2675a80008 100644 --- a/build.gradle +++ b/build.gradle @@ -1324,9 +1324,7 @@ configure(rootProject) { doFirst { classpath = files( - // ensure Servlet 3.x has precedence on the javadoc classpath - project(":spring-webmvc").sourceSets.main.compileClasspath.files.find { it =~ "servlet-api" }, - // ensure the javadoc process can resolve types compiled from .aj sources + // Ensure the javadoc process can resolve types compiled from .aj sources project(":spring-aspects").sourceSets.main.output ) classpath += files(subprojects.collect { it.sourceSets.main.compileClasspath }) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index 36357a427b..ef34abfe74 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -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. @@ -973,7 +973,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler private static class VoidCallable implements Callable { @Override - public Void call() { + public Void call() throws Exception { return null; } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java index d2a9753fbe..70e26db64c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java @@ -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. @@ -37,7 +37,8 @@ public class SockJsFrame { private static final SockJsFrame CLOSE_GO_AWAY_FRAME = closeFrame(3000, "Go away!"); - private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME = closeFrame(2010, "Another connection still open"); + private static final SockJsFrame CLOSE_ANOTHER_CONNECTION_OPEN_FRAME = + closeFrame(2010, "Another connection still open"); private final SockJsFrameType type; @@ -47,10 +48,10 @@ public class SockJsFrame { /** * Create a new instance frame with the given frame content. - * @param content the content, must be a non-empty and represent a valid SockJS frame + * @param content the content (must be a non-empty and represent a valid SockJS frame) */ public SockJsFrame(String content) { - Assert.hasText(content); + Assert.hasText(content, "Content must not be empty"); if ("o".equals(content)) { this.type = SockJsFrameType.OPEN; this.content = content; @@ -72,10 +73,74 @@ public class SockJsFrame { this.content = (content.length() > 1 ? content : "c[]"); } else { - throw new IllegalArgumentException("Unexpected SockJS frame type in content=\"" + content + "\""); + throw new IllegalArgumentException("Unexpected SockJS frame type in content \"" + content + "\""); } } + + /** + * Return the SockJS frame type. + */ + public SockJsFrameType getType() { + return this.type; + } + + /** + * Return the SockJS frame content (never {@code null}). + */ + public String getContent() { + return this.content; + } + + /** + * Return the SockJS frame content as a byte array. + */ + public byte[] getContentBytes() { + return this.content.getBytes(CHARSET); + } + + /** + * Return data contained in a SockJS "message" and "close" frames. Otherwise + * for SockJS "open" and "close" frames, which do not contain data, return + * {@code null}. + */ + public String getFrameData() { + if (getType() == SockJsFrameType.OPEN || getType() == SockJsFrameType.HEARTBEAT) { + return null; + } + else { + return getContent().substring(1); + } + } + + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof SockJsFrame)) { + return false; + } + SockJsFrame otherFrame = (SockJsFrame) other; + return (this.type.equals(otherFrame.type) && this.content.equals(otherFrame.content)); + } + + @Override + public int hashCode() { + return this.content.hashCode(); + } + + @Override + public String toString() { + String result = this.content; + if (result.length() > 80) { + result = result.substring(0, 80) + "...(truncated)"; + } + return "SockJsFrame content='" + result.replace("\n", "\\n").replace("\r", "\\r") + "'"; + } + + public static SockJsFrame openFrame() { return OPEN_FRAME; } @@ -101,66 +166,4 @@ public class SockJsFrame { return new SockJsFrame("c[" + code + ",\"" + reason + "\"]"); } - - /** - * Return the SockJS frame type. - */ - public SockJsFrameType getType() { - return this.type; - } - - /** - * Return the SockJS frame content, never {@code null}. - */ - public String getContent() { - return this.content; - } - - /** - * Return the SockJS frame content as a byte array. - */ - public byte[] getContentBytes() { - return this.content.getBytes(CHARSET); - } - - /** - * Return data contained in a SockJS "message" and "close" frames. Otherwise - * for SockJS "open" and "close" frames, which do not contain data, return - * {@code null}. - */ - public String getFrameData() { - if (SockJsFrameType.OPEN == getType() || SockJsFrameType.HEARTBEAT == getType()) { - return null; - } - else { - return getContent().substring(1); - } - } - - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SockJsFrame)) { - return false; - } - return (this.type.equals(((SockJsFrame) other).type) && this.content.equals(((SockJsFrame) other).content)); - } - - @Override - public int hashCode() { - return this.content.hashCode(); - } - - @Override - public String toString() { - String result = this.content; - if (result.length() > 80) { - result = result.substring(0, 80) + "...(truncated)"; - } - return "SockJsFrame content='" + result.replace("\n", "\\n").replace("\r", "\\r") + "'"; - } - }