You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/07/01 07:49:50 UTC
[tomcat] 02/02: Align with 8.5.x
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 0ef94cefaa6ae86791806e83d5f6161786231803
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Sun Jun 30 23:53:57 2019 +0100
Align with 8.5.x
---
.../tomcat/websocket/AsyncChannelGroupUtil.java | 2 +-
.../websocket/AsyncChannelWrapperSecure.java | 27 ++++-----
.../tomcat/websocket/BackgroundProcessManager.java | 2 +-
java/org/apache/tomcat/websocket/Constants.java | 14 +++--
.../tomcat/websocket/FutureToSendHandler.java | 2 +-
.../apache/tomcat/websocket/PerMessageDeflate.java | 2 +-
.../apache/tomcat/websocket/Transformation.java | 9 +++
.../tomcat/websocket/TransformationFactory.java | 2 +-
java/org/apache/tomcat/websocket/Util.java | 3 +-
java/org/apache/tomcat/websocket/WsFrameBase.java | 70 +++++++++-------------
.../org/apache/tomcat/websocket/WsFrameClient.java | 22 +++----
11 files changed, 72 insertions(+), 83 deletions(-)
diff --git a/java/org/apache/tomcat/websocket/AsyncChannelGroupUtil.java b/java/org/apache/tomcat/websocket/AsyncChannelGroupUtil.java
index 0e81011..fe0136e 100644
--- a/java/org/apache/tomcat/websocket/AsyncChannelGroupUtil.java
+++ b/java/org/apache/tomcat/websocket/AsyncChannelGroupUtil.java
@@ -37,7 +37,7 @@ import org.apache.tomcat.util.threads.ThreadPoolExecutor;
public class AsyncChannelGroupUtil {
private static final StringManager sm =
- StringManager.getManager(Constants.PACKAGE_NAME);
+ StringManager.getManager(AsyncChannelGroupUtil.class);
private static AsynchronousChannelGroup group = null;
private static int usageCount = 0;
diff --git a/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java b/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
index 0f0f038..c5eac9f 100644
--- a/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
+++ b/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
@@ -51,7 +51,7 @@ public class AsyncChannelWrapperSecure implements AsyncChannelWrapper {
private final Log log =
LogFactory.getLog(AsyncChannelWrapperSecure.class);
private static final StringManager sm =
- StringManager.getManager(Constants.PACKAGE_NAME);
+ StringManager.getManager(AsyncChannelWrapperSecure.class);
private static final ByteBuffer DUMMY = ByteBuffer.allocate(16921);
private final AsynchronousSocketChannel socketChannel;
@@ -268,8 +268,7 @@ public class AsyncChannelWrapperSecure implements AsyncChannelWrapper {
Future<Integer> f = socketChannel.read(socketReadBuffer);
Integer socketRead = f.get();
if (socketRead.intValue() == -1) {
- throw new EOFException(sm.getString(
- "asyncChannelWrapperSecure.eof"));
+ throw new EOFException(sm.getString("asyncChannelWrapperSecure.eof"));
}
}
@@ -277,8 +276,7 @@ public class AsyncChannelWrapperSecure implements AsyncChannelWrapper {
if (socketReadBuffer.hasRemaining()) {
// Decrypt the data in the buffer
- SSLEngineResult r =
- sslEngine.unwrap(socketReadBuffer, dest);
+ SSLEngineResult r = sslEngine.unwrap(socketReadBuffer, dest);
read += r.bytesProduced();
Status s = r.getStatus();
@@ -405,17 +403,15 @@ public class AsyncChannelWrapperSecure implements AsyncChannelWrapper {
handshaking = false;
break;
}
- default: {
- throw new SSLException("TODO");
+ case NOT_HANDSHAKING: {
+ throw new SSLException(
+ sm.getString("asyncChannelWrapperSecure.notHandshaking"));
}
}
}
- } catch (SSLException e) {
- hFuture.fail(e);
- } catch (InterruptedException e) {
- hFuture.fail(e);
- } catch (ExecutionException e) {
+ } catch (Exception e) {
hFuture.fail(e);
+ return;
}
hFuture.complete(null);
@@ -429,13 +425,14 @@ public class AsyncChannelWrapperSecure implements AsyncChannelWrapper {
if (resultStatus != Status.OK &&
(wrap || resultStatus != Status.BUFFER_UNDERFLOW)) {
- throw new SSLException("TODO");
+ throw new SSLException(
+ sm.getString("asyncChannelWrapperSecure.check.notOk", resultStatus));
}
if (wrap && result.bytesConsumed() != 0) {
- throw new SSLException("TODO");
+ throw new SSLException(sm.getString("asyncChannelWrapperSecure.check.wrap"));
}
if (!wrap && result.bytesProduced() != 0) {
- throw new SSLException("TODO");
+ throw new SSLException(sm.getString("asyncChannelWrapperSecure.check.unwrap"));
}
}
}
diff --git a/java/org/apache/tomcat/websocket/BackgroundProcessManager.java b/java/org/apache/tomcat/websocket/BackgroundProcessManager.java
index 8de6a55..53aed20 100644
--- a/java/org/apache/tomcat/websocket/BackgroundProcessManager.java
+++ b/java/org/apache/tomcat/websocket/BackgroundProcessManager.java
@@ -34,7 +34,7 @@ public class BackgroundProcessManager {
private final Log log =
LogFactory.getLog(BackgroundProcessManager.class);
private static final StringManager sm =
- StringManager.getManager(Constants.PACKAGE_NAME);
+ StringManager.getManager(BackgroundProcessManager.class);
private static final BackgroundProcessManager instance;
diff --git a/java/org/apache/tomcat/websocket/Constants.java b/java/org/apache/tomcat/websocket/Constants.java
index 5a292f8..bdadbb6 100644
--- a/java/org/apache/tomcat/websocket/Constants.java
+++ b/java/org/apache/tomcat/websocket/Constants.java
@@ -27,8 +27,12 @@ import javax.websocket.Extension;
*/
public class Constants {
- protected static final String PACKAGE_NAME =
- Constants.class.getPackage().getName();
+ /**
+ * @deprecated. Will be removed in 8.5.x onwards.
+ */
+ @Deprecated
+ protected static final String PACKAGE_NAME = Constants.class.getPackage().getName();
+
// OP Codes
public static final byte OPCODE_CONTINUATION = 0x00;
public static final byte OPCODE_TEXT = 0x01;
@@ -67,10 +71,8 @@ public class Constants {
public static final String WS_VERSION_HEADER_NAME = "Sec-WebSocket-Version";
public static final String WS_VERSION_HEADER_VALUE = "13";
public static final String WS_KEY_HEADER_NAME = "Sec-WebSocket-Key";
- public static final String WS_PROTOCOL_HEADER_NAME =
- "Sec-WebSocket-Protocol";
- public static final String WS_EXTENSIONS_HEADER_NAME =
- "Sec-WebSocket-Extensions";
+ public static final String WS_PROTOCOL_HEADER_NAME = "Sec-WebSocket-Protocol";
+ public static final String WS_EXTENSIONS_HEADER_NAME = "Sec-WebSocket-Extensions";
/// HTTP redirection status codes
public static final int MULTIPLE_CHOICES = 300;
diff --git a/java/org/apache/tomcat/websocket/FutureToSendHandler.java b/java/org/apache/tomcat/websocket/FutureToSendHandler.java
index 62871aa..8c837fb 100644
--- a/java/org/apache/tomcat/websocket/FutureToSendHandler.java
+++ b/java/org/apache/tomcat/websocket/FutureToSendHandler.java
@@ -34,7 +34,7 @@ import org.apache.tomcat.util.res.StringManager;
*/
class FutureToSendHandler implements Future<Void>, SendHandler {
- private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final StringManager sm = StringManager.getManager(FutureToSendHandler.class);
private final CountDownLatch latch = new CountDownLatch(1);
private final WsSession wsSession;
diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 010f711..c4fe1c4 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -418,7 +418,7 @@ public class PerMessageDeflate implements Transformation {
uncompressedIntermediateHandler, uncompressedIntermediateHandler);
}
} else {
- throw new IllegalStateException("Should never happen");
+ throw new IllegalStateException(sm.getString("perMessageDeflate.invalidState"));
}
// Add the newly created compressed part to the set of parts
diff --git a/java/org/apache/tomcat/websocket/Transformation.java b/java/org/apache/tomcat/websocket/Transformation.java
index e5d82de..5186181 100644
--- a/java/org/apache/tomcat/websocket/Transformation.java
+++ b/java/org/apache/tomcat/websocket/Transformation.java
@@ -30,6 +30,7 @@ public interface Transformation {
/**
* Sets the next transformation in the pipeline.
+ * @param t The next transformation
*/
void setNext(Transformation t);
@@ -52,6 +53,9 @@ public interface Transformation {
/**
* Obtain the extension that describes the information to be returned to the
* client.
+ *
+ * @return The extension information that describes the parameters that have
+ * been agreed for this transformation
*/
Extension getExtensionResponse();
@@ -63,6 +67,11 @@ public interface Transformation {
* @param rsv The reserved bits for the frame currently being
* processed
* @param dest The buffer in which the data is to be written
+ *
+ * @return The result of trying to read more data from the transform
+ *
+ * @throws IOException If an I/O error occurs while reading data from the
+ * transform
*/
TransformationResult getMoreData(byte opCode, boolean fin, int rsv, ByteBuffer dest) throws IOException;
diff --git a/java/org/apache/tomcat/websocket/TransformationFactory.java b/java/org/apache/tomcat/websocket/TransformationFactory.java
index fed13f9..643be94 100644
--- a/java/org/apache/tomcat/websocket/TransformationFactory.java
+++ b/java/org/apache/tomcat/websocket/TransformationFactory.java
@@ -24,7 +24,7 @@ import org.apache.tomcat.util.res.StringManager;
public class TransformationFactory {
- private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final StringManager sm = StringManager.getManager(TransformationFactory.class);
private static final TransformationFactory factory = new TransformationFactory();
diff --git a/java/org/apache/tomcat/websocket/Util.java b/java/org/apache/tomcat/websocket/Util.java
index 27ff24a..e935056 100644
--- a/java/org/apache/tomcat/websocket/Util.java
+++ b/java/org/apache/tomcat/websocket/Util.java
@@ -59,8 +59,7 @@ import org.apache.tomcat.websocket.pojo.PojoMessageHandlerWholeText;
*/
public class Util {
- private static final StringManager sm =
- StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final StringManager sm = StringManager.getManager(Util.class);
private static final Queue<SecureRandom> randoms =
new ConcurrentLinkedQueue<SecureRandom>();
diff --git a/java/org/apache/tomcat/websocket/WsFrameBase.java b/java/org/apache/tomcat/websocket/WsFrameBase.java
index ae6f8e8..b3d7261 100644
--- a/java/org/apache/tomcat/websocket/WsFrameBase.java
+++ b/java/org/apache/tomcat/websocket/WsFrameBase.java
@@ -42,8 +42,7 @@ import org.apache.tomcat.util.res.StringManager;
*/
public abstract class WsFrameBase {
- private static final StringManager sm =
- StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final StringManager sm = StringManager.getManager(WsFrameBase.class);
// Connection level attributes
protected final WsSession wsSession;
@@ -79,10 +78,10 @@ public abstract class WsFrameBase {
private final byte[] mask = new byte[4];
private int maskIndex = 0;
private long payloadLength = 0;
- private long payloadWritten = 0;
+ private volatile long payloadWritten = 0;
// Attributes tracking state
- private State state = State.NEW_FRAME;
+ private volatile State state = State.NEW_FRAME;
private volatile boolean open = true;
private int readPos = 0;
protected int writePos = 0;
@@ -152,8 +151,7 @@ public abstract class WsFrameBase {
if (!transformation.validateRsv(rsv, opCode)) {
throw new WsIOException(new CloseReason(
CloseCodes.PROTOCOL_ERROR,
- sm.getString("wsFrame.wrongRsv", Integer.valueOf(rsv),
- Integer.valueOf(opCode))));
+ sm.getString("wsFrame.wrongRsv", Integer.valueOf(rsv), Integer.valueOf(opCode))));
}
if (Util.isControl(opCode)) {
@@ -167,8 +165,7 @@ public abstract class WsFrameBase {
opCode != Constants.OPCODE_CLOSE) {
throw new WsIOException(new CloseReason(
CloseCodes.PROTOCOL_ERROR,
- sm.getString("wsFrame.invalidOpCode",
- Integer.valueOf(opCode))));
+ sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode))));
}
} else {
if (continuationExpected) {
@@ -200,8 +197,7 @@ public abstract class WsFrameBase {
} else {
throw new WsIOException(new CloseReason(
CloseCodes.PROTOCOL_ERROR,
- sm.getString("wsFrame.invalidOpCode",
- Integer.valueOf(opCode))));
+ sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode))));
}
} catch (IllegalStateException ise) {
// Thrown if the session is already closed
@@ -321,7 +317,7 @@ public abstract class WsFrameBase {
int code = CloseCodes.NORMAL_CLOSURE.getCode();
if (controlBufferBinary.remaining() == 1) {
controlBufferBinary.clear();
- // Payload must be zero or greater than 2
+ // Payload must be zero or 2+ bytes long
throw new WsIOException(new CloseReason(
CloseCodes.PROTOCOL_ERROR,
sm.getString("wsFrame.oneByteCloseCode")));
@@ -329,8 +325,8 @@ public abstract class WsFrameBase {
if (controlBufferBinary.remaining() > 1) {
code = controlBufferBinary.getShort();
if (controlBufferBinary.remaining() > 0) {
- CoderResult cr = utf8DecoderControl.decode(
- controlBufferBinary, controlBufferText, true);
+ CoderResult cr = utf8DecoderControl.decode(controlBufferBinary,
+ controlBufferText, true);
if (cr.isError()) {
controlBufferBinary.clear();
controlBufferText.clear();
@@ -351,8 +347,7 @@ public abstract class WsFrameBase {
wsSession.getBasicRemote().sendPong(controlBufferBinary);
}
} else if (opCode == Constants.OPCODE_PONG) {
- MessageHandler.Whole<PongMessage> mhPong =
- wsSession.getPongMessageHandler();
+ MessageHandler.Whole<PongMessage> mhPong = wsSession.getPongMessageHandler();
if (mhPong != null) {
try {
mhPong.onMessage(new WsPongMessage(controlBufferBinary));
@@ -367,8 +362,7 @@ public abstract class WsFrameBase {
controlBufferBinary.clear();
throw new WsIOException(new CloseReason(
CloseCodes.PROTOCOL_ERROR,
- sm.getString("wsFrame.invalidOpCode",
- Integer.valueOf(opCode))));
+ sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode))));
}
controlBufferBinary.clear();
newFrame();
@@ -379,10 +373,8 @@ public abstract class WsFrameBase {
@SuppressWarnings("unchecked")
private void sendMessageText(boolean last) throws WsIOException {
if (textMsgHandler instanceof WrappedMessageHandler) {
- long maxMessageSize =
- ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize();
- if (maxMessageSize > -1 &&
- messageBufferText.remaining() > maxMessageSize) {
+ long maxMessageSize = ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize();
+ if (maxMessageSize > -1 && messageBufferText.remaining() > maxMessageSize) {
throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
sm.getString("wsFrame.messageTooBig",
Long.valueOf(messageBufferText.remaining()),
@@ -392,12 +384,12 @@ public abstract class WsFrameBase {
try {
if (textMsgHandler instanceof MessageHandler.Partial<?>) {
- ((MessageHandler.Partial<String>) textMsgHandler).onMessage(
- messageBufferText.toString(), last);
+ ((MessageHandler.Partial<String>) textMsgHandler)
+ .onMessage(messageBufferText.toString(), last);
} else {
// Caller ensures last == true if this branch is used
- ((MessageHandler.Whole<String>) textMsgHandler).onMessage(
- messageBufferText.toString());
+ ((MessageHandler.Whole<String>) textMsgHandler)
+ .onMessage(messageBufferText.toString());
}
} catch (Throwable t) {
handleThrowableOnSend(t);
@@ -415,8 +407,8 @@ public abstract class WsFrameBase {
// Convert bytes to UTF-8
messageBufferBinary.flip();
while (true) {
- CoderResult cr = utf8DecoderMessage.decode(
- messageBufferBinary, messageBufferText, false);
+ CoderResult cr = utf8DecoderMessage.decode(messageBufferBinary, messageBufferText,
+ false);
if (cr.isError()) {
throw new WsIOException(new CloseReason(
CloseCodes.NOT_CONSISTENT,
@@ -458,8 +450,8 @@ public abstract class WsFrameBase {
// Frame is fully received
// Convert bytes to UTF-8
while (true) {
- CoderResult cr = utf8DecoderMessage.decode(messageBufferBinary,
- messageBufferText, last);
+ CoderResult cr = utf8DecoderMessage.decode(messageBufferBinary, messageBufferText,
+ last);
if (cr.isError()) {
throw new WsIOException(new CloseReason(
CloseCodes.NOT_CONSISTENT,
@@ -520,14 +512,12 @@ public abstract class WsFrameBase {
if (!usePartial()) {
CloseReason cr = new CloseReason(CloseCodes.TOO_BIG,
sm.getString("wsFrame.bufferTooSmall",
- Integer.valueOf(
- messageBufferBinary.capacity()),
+ Integer.valueOf(messageBufferBinary.capacity()),
Long.valueOf(payloadLength)));
throw new WsIOException(cr);
}
messageBufferBinary.flip();
- ByteBuffer copy =
- ByteBuffer.allocate(messageBufferBinary.limit());
+ ByteBuffer copy = ByteBuffer.allocate(messageBufferBinary.limit());
copy.put(messageBufferBinary);
copy.flip();
sendMessageBinary(copy, false);
@@ -542,8 +532,7 @@ public abstract class WsFrameBase {
// - the message is complete
if (usePartial() || !continuationExpected) {
messageBufferBinary.flip();
- ByteBuffer copy =
- ByteBuffer.allocate(messageBufferBinary.limit());
+ ByteBuffer copy = ByteBuffer.allocate(messageBufferBinary.limit());
copy.put(messageBufferBinary);
copy.flip();
sendMessageBinary(copy, !continuationExpected);
@@ -575,8 +564,7 @@ public abstract class WsFrameBase {
private void sendMessageBinary(ByteBuffer msg, boolean last)
throws WsIOException {
if (binaryMsgHandler instanceof WrappedMessageHandler) {
- long maxMessageSize =
- ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize();
+ long maxMessageSize = ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize();
if (maxMessageSize > -1 && msg.remaining() > maxMessageSize) {
throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
sm.getString("wsFrame.messageTooBig",
@@ -591,7 +579,7 @@ public abstract class WsFrameBase {
// Caller ensures last == true if this branch is used
((MessageHandler.Whole<ByteBuffer>) binaryMsgHandler).onMessage(msg);
}
- } catch(Throwable t) {
+ } catch (Throwable t) {
handleThrowableOnSend(t);
}
}
@@ -677,11 +665,9 @@ public abstract class WsFrameBase {
}
- protected static long byteArrayToLong(byte[] b, int start, int len)
- throws IOException {
+ protected static long byteArrayToLong(byte[] b, int start, int len) throws IOException {
if (len > 8) {
- throw new IOException(sm.getString("wsFrame.byteToLongFail",
- Long.valueOf(len)));
+ throw new IOException(sm.getString("wsFrame.byteToLongFail", Long.valueOf(len)));
}
int shift = 0;
long result = 0;
diff --git a/java/org/apache/tomcat/websocket/WsFrameClient.java b/java/org/apache/tomcat/websocket/WsFrameClient.java
index 546810c..ea1c014 100644
--- a/java/org/apache/tomcat/websocket/WsFrameClient.java
+++ b/java/org/apache/tomcat/websocket/WsFrameClient.java
@@ -31,16 +31,15 @@ import org.apache.tomcat.util.res.StringManager;
public class WsFrameClient extends WsFrameBase {
private final Log log = LogFactory.getLog(WsFrameClient.class); // must not be static
- private static final StringManager sm =
- StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final StringManager sm = StringManager.getManager(WsFrameClient.class);
private final AsyncChannelWrapper channel;
- private final CompletionHandler<Integer,Void> handler;
+ private final CompletionHandler<Integer, Void> handler;
// Not final as it may need to be re-sized
- private ByteBuffer response;
+ private volatile ByteBuffer response;
- public WsFrameClient(ByteBuffer response, AsyncChannelWrapper channel,
- WsSession wsSession, Transformation transformation) {
+ public WsFrameClient(ByteBuffer response, AsyncChannelWrapper channel, WsSession wsSession,
+ Transformation transformation) {
super(wsSession, transformation);
this.response = response;
this.channel = channel;
@@ -90,8 +89,7 @@ public class WsFrameClient extends WsFrameBase {
if (t instanceof WsIOException) {
cr = ((WsIOException) t).getCloseReason();
} else {
- cr = new CloseReason(
- CloseCodes.CLOSED_ABNORMALLY, t.getMessage());
+ cr = new CloseReason(CloseCodes.CLOSED_ABNORMALLY, t.getMessage());
}
wsSession.doClose(cr, cr, true);
@@ -110,9 +108,7 @@ public class WsFrameClient extends WsFrameBase {
return log;
}
-
- private class WsFrameClientCompletionHandler
- implements CompletionHandler<Integer,Void> {
+ private class WsFrameClientCompletionHandler implements CompletionHandler<Integer, Void> {
@Override
public void completed(Integer result, Void attachment) {
@@ -146,8 +142,8 @@ public class WsFrameClient extends WsFrameBase {
public void failed(Throwable exc, Void attachment) {
if (exc instanceof ReadBufferOverflowException) {
// response will be empty if this exception is thrown
- response = ByteBuffer.allocate(
- ((ReadBufferOverflowException) exc).getMinBufferSize());
+ response = ByteBuffer
+ .allocate(((ReadBufferOverflowException) exc).getMinBufferSize());
response.flip();
try {
processSocketRead();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org