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 41e6b01703..dc5d81af9b 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 @@ -67,21 +67,20 @@ public class StompDecoder { } /** - * @return the configured {@code MessageHeaderInitializer} if any. + * Return the configured {@code MessageHeaderInitializer}, if any. */ public MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } + /** * Decodes one or more STOMP frames from the given {@code ByteBuffer} into a - * list of {@link Message}s. If the input buffer contains any incplcontains partial STOMP frame content, or additional - * content with a partial STOMP frame, the buffer is reset and {@code null} is - * returned. - * + * list of {@link Message}s. If the input buffer contains partial STOMP frame + * content, or additional content with a partial STOMP frame, the buffer is + * reset and {@code null} is returned. * @param buffer The buffer to decode the STOMP frame from - * - * @return the decoded messages or an empty list + * @return the decoded messages, or an empty list if none */ public List> decode(ByteBuffer buffer) { return decode(buffer, null); @@ -90,33 +89,28 @@ public class StompDecoder { /** * Decodes one or more STOMP frames from the given {@code buffer} and returns * a list of {@link Message}s. - * *

If the given ByteBuffer contains only partial STOMP frame content and no * complete STOMP frames, an empty list is returned, and the buffer is reset to * to where it was. - * *

If the buffer contains one ore more STOMP frames, those are returned and * the buffer reset to point to the beginning of the unused partial content. - * *

The output partialMessageHeaders map is used to store successfully parsed * headers in case of partial content. The caller can then check if a * "content-length" header was read, which helps to determine how much more * content is needed before the next attempt to decode. - * * @param buffer The buffer to decode the STOMP frame from * @param partialMessageHeaders an empty output map that will store the last * successfully parsed partialMessageHeaders in case of partial message content * in cases where the partial buffer ended with a partial STOMP frame - * * @return decoded messages or an empty list * @throws StompConversionException raised in case of decoding issues */ public List> decode(ByteBuffer buffer, MultiValueMap partialMessageHeaders) { List> messages = new ArrayList>(); while (buffer.hasRemaining()) { - Message m = decodeMessage(buffer, partialMessageHeaders); - if (m != null) { - messages.add(m); + Message message = decodeMessage(buffer, partialMessageHeaders); + if (message != null) { + messages.add(message); } else { break; @@ -129,28 +123,23 @@ public class StompDecoder { * Decode a single STOMP frame from the given {@code buffer} into a {@link Message}. */ private Message decodeMessage(ByteBuffer buffer, MultiValueMap headers) { - Message decodedMessage = null; skipLeadingEol(buffer); buffer.mark(); String command = readCommand(buffer); if (command.length() > 0) { - StompHeaderAccessor headerAccessor = null; byte[] payload = null; - if (buffer.remaining() > 0) { StompCommand stompCommand = StompCommand.valueOf(command); headerAccessor = StompHeaderAccessor.create(stompCommand); initHeaders(headerAccessor); - readHeaders(buffer, headerAccessor); payload = readPayload(buffer, headerAccessor); } - if (payload != null) { - if ((payload.length > 0) && (!headerAccessor.getCommand().isBodyAllowed())) { + if (payload.length > 0 && !headerAccessor.getCommand().isBodyAllowed()) { throw new StompConversionException(headerAccessor.getCommand() + " shouldn't have a payload: length=" + payload.length + ", headers=" + headers); } @@ -185,12 +174,14 @@ public class StompDecoder { logger.trace("Decoded " + headerAccessor.getDetailedLogMessage(null)); } } + return decodedMessage; } private void initHeaders(StompHeaderAccessor headerAccessor) { - if (getHeaderInitializer() != null) { - getHeaderInitializer().initHeaders(headerAccessor); + MessageHeaderInitializer initializer = getHeaderInitializer(); + if (initializer != null) { + initializer.initHeaders(headerAccessor); } } @@ -253,14 +244,13 @@ public class StompDecoder { * "Value Encoding". */ private String unescape(String inString) { - - StringBuilder sb = new StringBuilder(); - int pos = 0; // position in the old string + StringBuilder sb = new StringBuilder(inString.length()); + int pos = 0; // position in the old string int index = inString.indexOf("\\"); while (index >= 0) { sb.append(inString.substring(pos, index)); - if((index + 1) >= inString.length()) { + if (index + 1 >= inString.length()) { throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString); } Character c = inString.charAt(index + 1); @@ -289,7 +279,6 @@ public class StompDecoder { } private byte[] readPayload(ByteBuffer buffer, StompHeaderAccessor headerAccessor) { - Integer contentLength; try { contentLength = headerAccessor.getContentLength(); @@ -329,7 +318,6 @@ public class StompDecoder { /** * Try to read an EOL incrementing the buffer position if successful. - * * @return whether an EOL was consumed */ private boolean tryConsumeEndOfLine(ByteBuffer buffer) { 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 08de8b3986..bc197db52a 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 @@ -51,7 +51,6 @@ public final class StompEncoder { /** * Encodes the given STOMP {@code message} into a {@code byte[]} - * * @param message the message to encode * @return the encoded message */ @@ -61,7 +60,6 @@ public final class StompEncoder { /** * Encodes the given payload and headers into a {@code byte[]}. - * * @param headers the headers * @param payload the payload * @return the encoded message @@ -69,6 +67,7 @@ public final class StompEncoder { public byte[] encode(Map headers, byte[] payload) { Assert.notNull(headers, "'headers' is required"); Assert.notNull(payload, "'payload' is required"); + try { ByteArrayOutputStream baos = new ByteArrayOutputStream(128 + payload.length); DataOutputStream output = new DataOutputStream(baos); @@ -89,8 +88,8 @@ public final class StompEncoder { return baos.toByteArray(); } - catch (IOException e) { - throw new StompConversionException("Failed to encode STOMP frame, headers=" + headers + ".", e); + catch (IOException ex) { + throw new StompConversionException("Failed to encode STOMP frame, headers=" + headers, ex); } } @@ -102,7 +101,7 @@ public final class StompEncoder { (Map>) headers.get(NativeMessageHeaderAccessor.NATIVE_HEADERS); if (logger.isTraceEnabled()) { - logger.trace("Encoding STOMP " + command + ", headers=" + nativeHeaders + "."); + logger.trace("Encoding STOMP " + command + ", headers=" + nativeHeaders); } if (nativeHeaders == null) { @@ -137,8 +136,8 @@ public final class StompEncoder { } private byte[] encodeHeaderString(String input, boolean escape) { - input = escape ? escape(input) : input; - return input.getBytes(StompDecoder.UTF8_CHARSET); + String inputToUse = (escape ? escape(input) : input); + return inputToUse.getBytes(StompDecoder.UTF8_CHARSET); } /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 987817bbc7..4d21315fab 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -86,6 +86,8 @@ import org.springframework.util.StringUtils; */ public class FormHttpMessageConverter implements HttpMessageConverter> { + public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); + private static final byte[] BOUNDARY_CHARS = new byte[] {'-', '_', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', @@ -93,7 +95,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter availableCharsets; @@ -66,6 +67,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter(Charset.availableCharsets().values()); } + /** * Indicates whether the {@code Accept-Charset} should be written to any outgoing request. *

Default is {@code true}. @@ -74,6 +76,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter clazz) { return String.class.equals(clazz); @@ -86,10 +89,10 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverterBy default, returns {@link Charset#availableCharsets()}. Can be overridden in subclasses. + * Return the list of supported {@link Charset}s. + *

By default, returns {@link Charset#availableCharsets()}. + * Can be overridden in subclasses. * @return the list of accepted charsets */ protected List getAcceptedCharsets() { @@ -123,4 +128,5 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter { - private static final Charset UTF_8 = Charset.forName("UTF-8"); + private static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); private final byte[] bytes; @@ -46,7 +46,7 @@ public final class TextMessage extends AbstractWebSocketMessage { * @param payload the non-null payload */ public TextMessage(byte[] payload) { - super(new String(payload, UTF_8)); + super(new String(payload, UTF8_CHARSET)); this.bytes = payload; } @@ -70,7 +70,7 @@ public final class TextMessage extends AbstractWebSocketMessage { } public byte[] asBytes() { - return (this.bytes != null ? this.bytes : getPayload().getBytes(UTF_8)); + return (this.bytes != null ? this.bytes : getPayload().getBytes(UTF8_CHARSET)); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/DefaultHandshakeHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/DefaultHandshakeHandler.java index 442436887d..46e8c2402c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/DefaultHandshakeHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/DefaultHandshakeHandler.java @@ -17,6 +17,7 @@ package org.springframework.web.socket.server.support; import java.io.IOException; +import java.nio.charset.Charset; import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; @@ -60,6 +61,9 @@ import org.springframework.web.socket.server.RequestUpgradeStrategy; */ public class DefaultHandshakeHandler implements HandshakeHandler { + private static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); + + private static final boolean jettyWsPresent = ClassUtils.isPresent( "org.eclipse.jetty.websocket.server.WebSocketServerFactory", DefaultHandshakeHandler.class.getClassLoader()); @@ -223,7 +227,7 @@ public class DefaultHandshakeHandler implements HandshakeHandler { logger.error("Handshake failed due to invalid Upgrade header: " + request.getHeaders().getUpgrade()); } response.setStatusCode(HttpStatus.BAD_REQUEST); - response.getBody().write("Can \"Upgrade\" only to \"WebSocket\".".getBytes("UTF-8")); + response.getBody().write("Can \"Upgrade\" only to \"WebSocket\".".getBytes(UTF8_CHARSET)); } protected void handleInvalidConnectHeader(ServerHttpRequest request, ServerHttpResponse response) throws IOException { @@ -231,7 +235,7 @@ public class DefaultHandshakeHandler implements HandshakeHandler { logger.error("Handshake failed due to invalid Connection header " + request.getHeaders().getConnection()); } response.setStatusCode(HttpStatus.BAD_REQUEST); - response.getBody().write("\"Connection\" must be \"upgrade\".".getBytes("UTF-8")); + response.getBody().write("\"Connection\" must be \"upgrade\".".getBytes(UTF8_CHARSET)); } protected boolean isWebSocketVersionSupported(WebSocketHttpHeaders httpHeaders) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java index 373f4efc21..984845b034 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java @@ -337,8 +337,8 @@ public abstract class AbstractSockJsService implements SockJsService { try { if (sockJsPath.equals("") || sockJsPath.equals("/")) { logger.debug(requestInfo); - response.getHeaders().setContentType(new MediaType("text", "plain", Charset.forName("UTF-8"))); - response.getBody().write("Welcome to SockJS!\n".getBytes("UTF-8")); + response.getHeaders().setContentType(new MediaType("text", "plain", UTF8_CHARSET)); + response.getBody().write("Welcome to SockJS!\n".getBytes(UTF8_CHARSET)); } else if (sockJsPath.equals("/info")) { logger.debug(requestInfo); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java index e96c725bc9..df03d0bc9f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpReceivingTransportHandler.java @@ -87,7 +87,7 @@ public abstract class AbstractHttpReceivingTransportHandler extends AbstractTran private void handleReadError(ServerHttpResponse response, String error, String sessionId) { try { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); - response.getBody().write(error.getBytes("UTF-8")); + response.getBody().write(error.getBytes(UTF8_CHARSET)); } catch (IOException ex) { throw new SockJsException("Failed to send error: " + error, sessionId, ex); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java index b21847ac14..06b11c5ac1 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java @@ -49,7 +49,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession; - String protocol = null; // https://github.com/sockjs/sockjs-client/issues/130 + String protocol = null; // https://github.com/sockjs/sockjs-client/issues/130 sockJsSession.setAcceptedProtocol(protocol); // Set content type before writing @@ -99,20 +99,22 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp } } + protected abstract MediaType getContentType(); protected abstract SockJsFrameFormat getFrameFormat(ServerHttpRequest request); + protected final String getCallbackParam(ServerHttpRequest request) { String query = request.getURI().getQuery(); MultiValueMap params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams(); String value = params.getFirst("c"); try { - return StringUtils.isEmpty(value) ? null : UriUtils.decode(value, "UTF-8"); + return (!StringUtils.isEmpty(value) ? UriUtils.decode(value, "UTF-8") : null); } - catch (UnsupportedEncodingException e) { + catch (UnsupportedEncodingException ex) { // should never happen - throw new SockJsException("Unable to decode callback query parameter", null, e); + throw new SockJsException("Unable to decode callback query parameter", null, ex); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java index ded74d4988..2009450821 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -49,8 +49,8 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan } @Override - public StreamingSockJsSession createSession(String sessionId, WebSocketHandler handler, - Map attributes) { + public StreamingSockJsSession createSession( + String sessionId, WebSocketHandler handler, Map attributes) { return new EventSourceStreamingSockJsSession(sessionId, getServiceConfig(), handler, attributes); } @@ -61,9 +61,9 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan } - private final class EventSourceStreamingSockJsSession extends StreamingSockJsSession { + private class EventSourceStreamingSockJsSession extends StreamingSockJsSession { - private EventSourceStreamingSockJsSession(String sessionId, SockJsServiceConfig config, + public EventSourceStreamingSockJsSession(String sessionId, SockJsServiceConfig config, WebSocketHandler wsHandler, Map attributes) { super(sessionId, config, wsHandler, attributes); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java index 28fae126ee..9382c895c8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java @@ -26,6 +26,7 @@ import org.springframework.http.server.ServerHttpResponse; import org.springframework.util.StringUtils; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.sockjs.SockJsException; import org.springframework.web.socket.sockjs.SockJsTransportFailureException; import org.springframework.web.socket.sockjs.frame.DefaultSockJsFrameFormat; import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat; @@ -52,6 +53,7 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle // http://code.google.com/p/browsersec/wiki/Part2#Survey_of_content_sniffing_behaviors private static final int MINIMUM_PARTIAL_HTML_CONTENT_LENGTH = 1024; + static { StringBuilder sb = new StringBuilder( "\n" + @@ -71,7 +73,6 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle while (sb.length() < MINIMUM_PARTIAL_HTML_CONTENT_LENGTH) { sb.append(" "); } - PARTIAL_HTML_CONTENT = sb.toString(); } @@ -87,25 +88,25 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle } @Override - public StreamingSockJsSession createSession(String sessionId, WebSocketHandler handler, - Map attributes) { + public StreamingSockJsSession createSession( + String sessionId, WebSocketHandler handler, Map attributes) { return new HtmlFileStreamingSockJsSession(sessionId, getServiceConfig(), handler, attributes); } @Override public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, - AbstractHttpSockJsSession sockJsSession) { + AbstractHttpSockJsSession sockJsSession) throws SockJsException { String callback = getCallbackParam(request); - if (! StringUtils.hasText(callback)) { + if (!StringUtils.hasText(callback)) { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); try { - response.getBody().write("\"callback\" parameter required".getBytes("UTF-8")); + response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET)); } - catch (IOException t) { - sockJsSession.tryCloseWithSockJsTransportError(t, CloseStatus.SERVER_ERROR); - throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), t); + catch (IOException ex) { + sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); + throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex); } return; } @@ -124,9 +125,9 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle } - private final class HtmlFileStreamingSockJsSession extends StreamingSockJsSession { + private class HtmlFileStreamingSockJsSession extends StreamingSockJsSession { - private HtmlFileStreamingSockJsSession(String sessionId, SockJsServiceConfig config, + public HtmlFileStreamingSockJsSession(String sessionId, SockJsServiceConfig config, WebSocketHandler wsHandler, Map attributes) { super(sessionId, config, wsHandler, attributes); @@ -134,18 +135,16 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle @Override protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) { - // we already validated the parameter above.. + // We already validated the parameter above... String callback = getCallbackParam(request); - String html = String.format(PARTIAL_HTML_CONTENT, callback); - try { - response.getBody().write(html.getBytes("UTF-8")); + response.getBody().write(html.getBytes(UTF8_CHARSET)); response.flush(); } - catch (IOException e) { - tryCloseWithSockJsTransportError(e, CloseStatus.SERVER_ERROR); - throw new SockJsTransportFailureException("Failed to write HTML content", getId(), e); + catch (IOException ex) { + tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); + throw new SockJsTransportFailureException("Failed to write HTML content", getId(), ex); } } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpPollingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpPollingTransportHandler.java index ee445db594..98b8310eea 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpPollingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpPollingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -53,8 +53,8 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa } @Override - public PollingSockJsSession createSession(String sessionId, WebSocketHandler handler, - Map attributes) { + public PollingSockJsSession createSession( + String sessionId, WebSocketHandler handler, Map attributes) { return new PollingSockJsSession(sessionId, getServiceConfig(), handler, attributes); } @@ -65,9 +65,9 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa try { String callback = getCallbackParam(request); - if (! StringUtils.hasText(callback)) { + if (!StringUtils.hasText(callback)) { response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); - response.getBody().write("\"callback\" parameter required".getBytes("UTF-8")); + response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET)); return; } } @@ -81,7 +81,7 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa @Override protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) { - // we already validated the parameter above... + // We already validated the parameter above... String callback = getCallbackParam(request); return new DefaultSockJsFrameFormat(callback + "(\"%s\");\r\n") { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java index c9525f2a52..f889cd75e9 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java @@ -53,7 +53,7 @@ public class JsonpReceivingTransportHandler extends AbstractHttpReceivingTranspo super.handleRequestInternal(request, response, wsHandler, sockJsSession); try { - response.getBody().write("ok".getBytes("UTF-8")); + response.getBody().write("ok".getBytes(UTF8_CHARSET)); } catch (IOException ex) { throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java index 7f6594bb76..df1c81617f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -67,8 +67,8 @@ public class WebSocketTransportHandler extends AbstractTransportHandler } @Override - public AbstractSockJsSession createSession(String sessionId, WebSocketHandler handler, - Map attributes) { + public AbstractSockJsSession createSession( + String sessionId, WebSocketHandler handler, Map attributes) { return new WebSocketServerSockJsSession(sessionId, getServiceConfig(), handler, attributes); } @@ -88,8 +88,6 @@ public class WebSocketTransportHandler extends AbstractTransportHandler } } - // HandshakeHandler methods - @Override public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, Map attributes) throws HandshakeFailureException { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java index b813bbaf74..8735578049 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -51,8 +51,8 @@ public class XhrPollingTransportHandler extends AbstractHttpSendingTransportHand } @Override - public PollingSockJsSession createSession(String sessionId, WebSocketHandler handler, - Map attributes) { + public PollingSockJsSession createSession( + String sessionId, WebSocketHandler handler, Map attributes) { return new PollingSockJsSession(sessionId, getServiceConfig(), handler, attributes); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java index a27f369778..5bb1350a79 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -49,8 +49,8 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa } @Override - public StreamingSockJsSession createSession(String sessionId, WebSocketHandler handler, - Map attributes) { + public StreamingSockJsSession createSession( + String sessionId, WebSocketHandler handler, Map attributes) { return new XhrStreamingSockJsSession(sessionId, getServiceConfig(), handler, attributes); } @@ -61,9 +61,9 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa } - private final class XhrStreamingSockJsSession extends StreamingSockJsSession { + private class XhrStreamingSockJsSession extends StreamingSockJsSession { - private XhrStreamingSockJsSession(String sessionId, SockJsServiceConfig config, + public XhrStreamingSockJsSession(String sessionId, SockJsServiceConfig config, WebSocketHandler wsHandler, Map attributes) { super(sessionId, config, wsHandler, attributes); @@ -71,11 +71,12 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa @Override protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws IOException { - for (int i=0; i < 2048; i++) { + for (int i = 0; i < 2048; i++) { response.getBody().write('h'); } response.getBody().write('\n'); response.flush(); } } + }