diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java index d73bad6c1a9..d53b43fce8f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.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. @@ -27,9 +27,8 @@ import org.springframework.util.Assert; */ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec { - @Override - public String encode(String[] messages) { + public String encode(String... messages) { Assert.notNull(messages, "messages must not be null"); StringBuilder sb = new StringBuilder(); sb.append("a["); @@ -76,9 +75,9 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec { * See `escapable_by_server` variable in the SockJS protocol test suite. */ private boolean isSockJsSpecialChar(char ch) { - return (ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u200C' && ch <= '\u200F') - || (ch >= '\u2028' && ch <= '\u202F') || (ch >= '\u2060' && ch <= '\u206F') - || (ch >= '\uFFF0' && ch <= '\uFFFF') || (ch >= '\uD800' && ch <= '\uDFFF'); + return (ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u200C' && ch <= '\u200F') || + (ch >= '\u2028' && ch <= '\u202F') || (ch >= '\u2060' && ch <= '\u206F') || + (ch >= '\uFFF0' && ch <= '\uFFFF') || (ch >= '\uD800' && ch <= '\uDFFF'); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java index f2e89158a8d..33a7da916b6 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.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. @@ -20,10 +20,10 @@ import java.io.IOException; import java.io.InputStream; /** - * Encode and decode messages to and from a SockJS message frame, essentially an array of - * JSON-encoded messages. For example: + * Encode and decode messages to and from a SockJS message frame, + * essentially an array of JSON-encoded messages. For example: * - *
+ ** a["message1","message2"] ** @@ -38,14 +38,14 @@ public interface SockJsMessageCodec { * rules. See the "JSON Unicode Encoding" section of SockJS protocol (i.e. the * protocol test suite). * @param messages the messages to encode - * @return the content for a SockJS message frame, never {@code null} + * @return the content for a SockJS message frame (never {@code null}) */ - String encode(String[] messages); + String encode(String... messages); /** * Decode the given SockJS message frame. * @param content the SockJS message frame - * @return an array of messages or {@code null} + * @return an array of messages, or {@code null} if none * @throws IOException if the content could not be parsed */ String[] decode(String content) throws IOException; @@ -53,7 +53,7 @@ public interface SockJsMessageCodec { /** * Decode the given SockJS message frame. * @param content the SockJS message frame - * @return an array of messages or {@code null} + * @return an array of messages, or {@code null} if none * @throws IOException if the content could not be parsed */ String[] decodeInputStream(InputStream content) throws IOException; 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 7b12d8407c3..c055f10c5b3 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 @@ -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. @@ -56,7 +56,8 @@ public abstract class AbstractHttpReceivingTransportHandler extends AbstractTran } catch (IOException ex) { logger.error("Failed to read message", ex); - if(ex.getClass().getName().contains("Mapping")) { + if (ex.getClass().getName().contains("Mapping")) { + // e.g. Jackson's JsonMappingException, indicating an incomplete payload handleReadError(response, "Payload expected.", sockJsSession.getId()); } else { @@ -85,10 +86,10 @@ public abstract class AbstractHttpReceivingTransportHandler extends AbstractTran sockJsSession.delegateMessages(messages); } - private void handleReadError(ServerHttpResponse resp, String error, String sessionId) { + private void handleReadError(ServerHttpResponse response, String error, String sessionId) { try { - resp.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); - resp.getBody().write(error.getBytes("UTF-8")); + response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); + response.getBody().write(error.getBytes("UTF-8")); } 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/JsonpReceivingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java index e7d1afb35c1..c9525f2a521 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 @@ -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. @@ -55,7 +55,7 @@ public class JsonpReceivingTransportHandler extends AbstractHttpReceivingTranspo try { response.getBody().write("ok".getBytes("UTF-8")); } - catch(IOException ex) { + catch (IOException ex) { throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex); } } @@ -64,10 +64,10 @@ public class JsonpReceivingTransportHandler extends AbstractHttpReceivingTranspo protected String[] readMessages(ServerHttpRequest request) throws IOException { SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec(); MediaType contentType = request.getHeaders().getContentType(); - if ((contentType != null) && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { + if (contentType != null && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { MultiValueMapmap = this.formConverter.read(null, request); String d = map.getFirst("d"); - return (StringUtils.hasText(d)) ? messageCodec.decode(d) : null; + return (StringUtils.hasText(d) ? messageCodec.decode(d) : null); } else { return messageCodec.decodeInputStream(request.getBody());