Author: remy.maucherat(a)jboss.com
Date: 2014-10-22 12:05:37 -0400 (Wed, 22 Oct 2014)
New Revision: 2532
Modified:
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
branches/7.5.x/src/main/java/org/jboss/web/WebsocketsMessages.java
Log:
Port websocket patches.
Modified:
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 2014-10-22
13:58:11 UTC (rev 2531)
+++
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 2014-10-22
16:05:37 UTC (rev 2532)
@@ -120,6 +120,9 @@
public void sendBytes(ByteBuffer data) throws IOException {
+ if (data == null) {
+ throw MESSAGES.invalidNullData();
+ }
stateMachine.binaryStart();
startMessageBlock(Constants.OPCODE_BINARY, data, true);
stateMachine.complete(true);
@@ -134,6 +137,12 @@
public void sendBytesByCompletion(ByteBuffer data, SendHandler handler) {
+ if (data == null) {
+ throw MESSAGES.invalidNullData();
+ }
+ if (handler == null) {
+ throw MESSAGES.invalidNullHandler();
+ }
StateUpdateSendHandler sush = new StateUpdateSendHandler(handler);
stateMachine.binaryStart();
startMessage(Constants.OPCODE_BINARY, data, true, sush);
@@ -142,6 +151,9 @@
public void sendPartialBytes(ByteBuffer partialByte, boolean last)
throws IOException {
+ if (partialByte == null) {
+ throw MESSAGES.invalidNullData();
+ }
stateMachine.binaryPartialStart();
startMessageBlock(Constants.OPCODE_BINARY, partialByte, last);
stateMachine.complete(last);
@@ -163,6 +175,9 @@
public void sendString(String text) throws IOException {
+ if (text == null) {
+ throw MESSAGES.invalidNullData();
+ }
stateMachine.textStart();
sendPartialString(CharBuffer.wrap(text), true);
}
@@ -176,6 +191,12 @@
public void sendStringByCompletion(String text, SendHandler handler) {
+ if (text == null) {
+ throw MESSAGES.invalidNullData();
+ }
+ if (handler == null) {
+ throw MESSAGES.invalidNullHandler();
+ }
stateMachine.textStart();
TextMessageSendHandler tmsh = new TextMessageSendHandler(handler,
CharBuffer.wrap(text), true, encoder, encoderBuffer, this);
@@ -186,6 +207,9 @@
public void sendPartialString(String fragment, boolean isLast)
throws IOException {
+ if (fragment == null) {
+ throw MESSAGES.invalidNullData();
+ }
stateMachine.textPartialStart();
sendPartialString(CharBuffer.wrap(fragment), isLast);
}
@@ -484,14 +508,21 @@
}
- public void sendObject(Object obj) throws IOException {
+ public void sendObject(Object obj) throws IOException, EncodeException {
Future<Void> f = sendObjectByFuture(obj);
try {
f.get();
} catch (InterruptedException e) {
throw new IOException(e);
} catch (ExecutionException e) {
- throw new IOException(e);
+ Throwable cause = e.getCause();
+ if (cause instanceof IOException) {
+ throw (IOException) cause;
+ } else if (cause instanceof EncodeException) {
+ throw (EncodeException) cause;
+ } else {
+ throw new IOException(e);
+ }
}
}
@@ -505,6 +536,13 @@
@SuppressWarnings({"unchecked", "rawtypes"})
public void sendObjectByCompletion(Object obj, SendHandler completion) {
+ if (obj == null) {
+ throw MESSAGES.invalidNullData();
+ }
+ if (completion == null) {
+ throw MESSAGES.invalidNullHandler();
+ }
+
if (Util.isPrimitive(obj.getClass())) {
String msg = obj.toString();
sendStringByCompletion(msg, completion);
Modified:
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2014-10-22
13:58:11 UTC (rev 2531)
+++
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/WsWebSocketContainer.java 2014-10-22
16:05:37 UTC (rev 2532)
@@ -161,6 +161,7 @@
ClientEndpointConfig config = builder.
decoders(Arrays.asList(annotation.decoders())).
encoders(Arrays.asList(annotation.encoders())).
+ preferredSubprotocols(Arrays.asList(annotation.subprotocols())).
build();
return connectToServer(ep, config, path);
}
Modified:
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/server/UpgradeUtil.java
===================================================================
---
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/server/UpgradeUtil.java 2014-10-22
13:58:11 UTC (rev 2531)
+++
branches/7.5.x/src/main/java/org/apache/tomcat/websocket/server/UpgradeUtil.java 2014-10-22
16:05:37 UTC (rev 2532)
@@ -181,10 +181,10 @@
getWebSocketAccept(key));
if (subProtocol != null && subProtocol.length() > 0) {
// RFC6455 4.2.2 explicitly states "" is not valid here
- resp.setHeader("Sec-WebSocket-Protocol", subProtocol);
+ resp.setHeader(Constants.WS_PROTOCOL_HEADER_NAME, subProtocol);
}
if (!transformations.isEmpty()) {
- resp.setHeader("Sec-WebSocket-Extensions",
responseHeaderExtensions.toString());
+ resp.setHeader(Constants.WS_EXTENSIONS_HEADER_NAME,
responseHeaderExtensions.toString());
}
WsHandshakeRequest wsRequest = new WsHandshakeRequest(req);
Modified: branches/7.5.x/src/main/java/org/jboss/web/WebsocketsMessages.java
===================================================================
--- branches/7.5.x/src/main/java/org/jboss/web/WebsocketsMessages.java 2014-10-22 13:58:11
UTC (rev 2531)
+++ branches/7.5.x/src/main/java/org/jboss/web/WebsocketsMessages.java 2014-10-22 16:05:37
UTC (rev 2532)
@@ -338,4 +338,10 @@
@Message(id = 8600, value = "Incompatible RSV bit usage")
String incompatibleRsvBitUsage();
+ @Message(id = 8601, value = "Null data")
+ IllegalArgumentException invalidNullData();
+
+ @Message(id = 8602, value = "Null handler")
+ IllegalArgumentException invalidNullHandler();
+
}