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 2023/06/20 12:46:38 UTC
[tomcat] branch main updated (e0320d4894 -> 1b1685b377)
This is an automated email from the ASF dual-hosted git repository.
markt pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
from e0320d4894 Remove unnecessary test.
new ab801f8a4f Fix IDE warning
new 46578dc3e7 Update WebSocket API to align with latest proposals
new 1b1685b377 Add getSession() to SendResult
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
java/jakarta/websocket/SendResult.java | 50 +++++++++++++++++++++-
.../tomcat/websocket/WsRemoteEndpointImplBase.java | 24 ++++++-----
.../websocket/WsRemoteEndpointImplClient.java | 7 +--
java/org/apache/tomcat/websocket/WsSession.java | 4 +-
.../server/WsRemoteEndpointImplServer.java | 29 +++++++------
.../apache/tomcat/jdbc/pool/ConnectionPool.java | 2 +-
webapps/docs/changelog.xml | 6 +++
7 files changed, 91 insertions(+), 31 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 02/03: Update WebSocket API to align with latest proposals
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 46578dc3e7cc98ca907a2711ca48ecfc07042b9b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jun 20 10:19:10 2023 +0100
Update WebSocket API to align with latest proposals
---
java/jakarta/websocket/SendResult.java | 50 ++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/java/jakarta/websocket/SendResult.java b/java/jakarta/websocket/SendResult.java
index 47f5021aac..f506c881af 100644
--- a/java/jakarta/websocket/SendResult.java
+++ b/java/jakarta/websocket/SendResult.java
@@ -17,16 +17,53 @@
package jakarta.websocket;
public final class SendResult {
+ private final Session session;
private final Throwable exception;
private final boolean ok;
- public SendResult(Throwable exception) {
+ /**
+ * Create an instance for an unsuccessful message.
+ *
+ * @param session the WebSocket session in which the message was sent
+ * @param exception The exception describing the failure when trying to send the message.
+ */
+ public SendResult(Session session, Throwable exception) {
+ this.session = session;
this.exception = exception;
this.ok = (exception == null);
}
+ /**
+ * Create an instance for a successful message.
+ *
+ * @param session the WebSocket session in which the message was sent
+ */
+ public SendResult(Session session) {
+ this(session, null);
+ }
+
+ /**
+ * Create an instance for an unsuccessful message.
+ *
+ * @param exception The exception describing the failure when trying to send the message.
+ *
+ * @deprecated Deprecated in WebSocket 2.2 and will be removed in a future version. Use
+ * {@link #SendResult(Session, Throwable)} as a replacement.
+ */
+ @Deprecated
+ public SendResult(Throwable exception) {
+ this(null, exception);
+ }
+
+ /**
+ * Create an instance for a successful message.
+ *
+ * @deprecated Deprecated in WebSocket 2.2 and will be removed in a future version. Use
+ * {@link #SendResult(Session, Throwable)} as a replacement.
+ */
+ @Deprecated
public SendResult() {
- this(null);
+ this(null, null);
}
public Throwable getException() {
@@ -36,4 +73,13 @@ public final class SendResult {
public boolean isOK() {
return ok;
}
+
+ /**
+ * The WebSocket session in which the session was sent.
+ *
+ * @return the WebSocket session in which the session was sent or {@code null} if not known.
+ */
+ public Session getSession() {
+ return session;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 03/03: Add getSession() to SendResult
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 1b1685b377f547bbece829dfcbf7f93d56624274
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jun 20 13:46:31 2023 +0100
Add getSession() to SendResult
This aligns Tomcat 11.0.x with the latest proposals for Jakarta
WebSocket 2.2 from the Jakarta WebSocket project.
---
.../tomcat/websocket/WsRemoteEndpointImplBase.java | 24 ++++++++++--------
.../websocket/WsRemoteEndpointImplClient.java | 7 +++---
java/org/apache/tomcat/websocket/WsSession.java | 4 +--
.../server/WsRemoteEndpointImplServer.java | 29 ++++++++++++----------
webapps/docs/changelog.xml | 6 +++++
5 files changed, 42 insertions(+), 28 deletions(-)
diff --git a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
index 5dc9298b6e..5717a7bfca 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
@@ -58,8 +58,6 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
protected static final StringManager sm = StringManager.getManager(WsRemoteEndpointImplBase.class);
- protected static final SendResult SENDRESULT_OK = new SendResult();
-
private final Log log = LogFactory.getLog(WsRemoteEndpointImplBase.class); // must not be static
private final StateMachine stateMachine = new StateMachine();
@@ -104,6 +102,11 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
}
+ protected WsSession getSession() {
+ return wsSession;
+ }
+
+
@Override
public void setBatchingAllowed(boolean batchingAllowed) throws IOException {
boolean oldValue = this.batchingAllowed.getAndSet(batchingAllowed);
@@ -362,7 +365,7 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
try {
messageParts = transformation.sendMessagePart(messageParts);
} catch (IOException ioe) {
- handler.onResult(new SendResult(ioe));
+ handler.onResult(new SendResult(getSession(), ioe));
return;
}
@@ -370,7 +373,7 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
// that no message parts will be returned. If this is the case the
// trigger the supplied SendHandler
if (messageParts.size() == 0) {
- handler.onResult(new SendResult());
+ handler.onResult(new SendResult(getSession()));
return;
}
@@ -671,7 +674,7 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
try (Writer w = getSendWriter()) {
((Encoder.TextStream) encoder).encode(obj, w);
}
- completion.onResult(new SendResult());
+ completion.onResult(new SendResult(getSession()));
} else if (encoder instanceof Encoder.Binary) {
ByteBuffer msg = ((Encoder.Binary) encoder).encode(obj);
sendBytesByCompletion(msg, completion);
@@ -679,12 +682,12 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
try (OutputStream os = getSendStream()) {
((Encoder.BinaryStream) encoder).encode(obj, os);
}
- completion.onResult(new SendResult());
+ completion.onResult(new SendResult(getSession()));
} else {
throw new EncodeException(obj, sm.getString("wsRemoteEndpoint.noEncoder", obj.getClass()));
}
} catch (Exception e) {
- SendResult sr = new SendResult(e);
+ SendResult sr = new SendResult(getSession(), e);
completion.onResult(sr);
}
}
@@ -848,7 +851,8 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
} else if (!result.isOK()) {
handler.onResult(result);
} else if (closed) {
- SendResult sr = new SendResult(new IOException(sm.getString("wsRemoteEndpoint.closedDuringMessage")));
+ SendResult sr = new SendResult(getSession(),
+ new IOException(sm.getString("wsRemoteEndpoint.closedDuringMessage")));
handler.onResult(sr);
} else {
write();
@@ -933,12 +937,12 @@ public abstract class WsRemoteEndpointImplBase implements RemoteEndpoint {
if (flushRequired) {
outputBuffer.flip();
if (outputBuffer.remaining() == 0) {
- handler.onResult(SENDRESULT_OK);
+ handler.onResult(new SendResult(endpoint.getSession()));
} else {
endpoint.doWrite(this, blockingWriteTimeoutExpiry, outputBuffer);
}
} else {
- handler.onResult(SENDRESULT_OK);
+ handler.onResult(new SendResult(endpoint.getSession()));
}
}
diff --git a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
index 5f0cc67fc3..7b0386224d 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
@@ -54,7 +54,8 @@ public class WsRemoteEndpointImplClient extends WsRemoteEndpointImplBase {
} else {
timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis();
if (timeout < 0) {
- SendResult sr = new SendResult(new IOException(sm.getString("wsRemoteEndpoint.writeTimeout")));
+ SendResult sr = new SendResult(getSession(),
+ new IOException(sm.getString("wsRemoteEndpoint.writeTimeout")));
handler.onResult(sr);
}
}
@@ -62,11 +63,11 @@ public class WsRemoteEndpointImplClient extends WsRemoteEndpointImplBase {
try {
channel.write(byteBuffer).get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
- handler.onResult(new SendResult(e));
+ handler.onResult(new SendResult(getSession(), e));
return;
}
}
- handler.onResult(SENDRESULT_OK);
+ handler.onResult(new SendResult(getSession()));
}
diff --git a/java/org/apache/tomcat/websocket/WsSession.java b/java/org/apache/tomcat/websocket/WsSession.java
index 0c75f92184..41cc389eae 100644
--- a/java/org/apache/tomcat/websocket/WsSession.java
+++ b/java/org/apache/tomcat/websocket/WsSession.java
@@ -598,7 +598,7 @@ public class WsSession implements Session {
// Fail any uncompleted messages.
IOException ioe = new IOException(sm.getString("wsSession.messageFailed"));
- SendResult sr = new SendResult(ioe);
+ SendResult sr = new SendResult(this, ioe);
for (FutureToSendHandler f2sh : futures.keySet()) {
f2sh.onResult(sr);
}
@@ -825,7 +825,7 @@ public class WsSession implements Session {
// second and subsequent attempts are ignored.
IOException ioe = new IOException(sm.getString("wsSession.messageFailed"));
- SendResult sr = new SendResult(ioe);
+ SendResult sr = new SendResult(this, ioe);
f2sh.onResult(sr);
}
diff --git a/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java b/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
index 31779aa32a..396de502e3 100644
--- a/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
+++ b/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
@@ -38,6 +38,7 @@ import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.websocket.Constants;
import org.apache.tomcat.websocket.Transformation;
import org.apache.tomcat.websocket.WsRemoteEndpointImplBase;
+import org.apache.tomcat.websocket.WsSession;
/**
* This is the server side {@link jakarta.websocket.RemoteEndpoint} implementation - i.e. what the server uses to send
@@ -144,7 +145,7 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
if (block) {
timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis();
if (timeout <= 0) {
- SendResult sr = new SendResult(new SocketTimeoutException());
+ SendResult sr = new SendResult(getSession(), new SocketTimeoutException());
handler.onResult(sr);
return;
}
@@ -166,7 +167,7 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
if (timeout <= 0) {
failed(new SocketTimeoutException(), null);
} else {
- handler.onResult(SENDRESULT_OK);
+ handler.onResult(new SendResult(getSession()));
}
} else {
wsWriteTimeout.unregister(WsRemoteEndpointImplServer.this);
@@ -177,7 +178,7 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
@Override
public void failed(Throwable exc, Void attachment) {
if (block) {
- SendResult sr = new SendResult(exc);
+ SendResult sr = new SendResult(getSession(), exc);
handler.onResult(sr);
} else {
wsWriteTimeout.unregister(WsRemoteEndpointImplServer.this);
@@ -199,7 +200,7 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
for (ByteBuffer buffer : buffers) {
long timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis();
if (timeout <= 0) {
- SendResult sr = new SendResult(new SocketTimeoutException());
+ SendResult sr = new SendResult(getSession(), new SocketTimeoutException());
handler.onResult(sr);
return;
}
@@ -208,15 +209,15 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
}
long timeout = blockingWriteTimeoutExpiry - System.currentTimeMillis();
if (timeout <= 0) {
- SendResult sr = new SendResult(new SocketTimeoutException());
+ SendResult sr = new SendResult(getSession(), new SocketTimeoutException());
handler.onResult(sr);
return;
}
socketWrapper.setWriteTimeout(timeout);
socketWrapper.flush(true);
- handler.onResult(SENDRESULT_OK);
+ handler.onResult(new SendResult(getSession()));
} catch (IOException e) {
- SendResult sr = new SendResult(e);
+ SendResult sr = new SendResult(getSession(), e);
handler.onResult(sr);
}
}
@@ -341,7 +342,7 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
buffers = null;
if (sh != null) {
if (useDispatch) {
- OnResultRunnable r = new OnResultRunnable(sh, t);
+ OnResultRunnable r = new OnResultRunnable(getSession(), sh, t);
try {
socketWrapper.execute(r);
} catch (RejectedExecutionException ree) {
@@ -356,9 +357,9 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
}
} else {
if (t == null) {
- sh.onResult(new SendResult());
+ sh.onResult(new SendResult(getSession()));
} else {
- sh.onResult(new SendResult(t));
+ sh.onResult(new SendResult(getSession(), t));
}
}
}
@@ -373,10 +374,12 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
private static class OnResultRunnable implements Runnable {
+ private final WsSession session;
private final SendHandler sh;
private final Throwable t;
- private OnResultRunnable(SendHandler sh, Throwable t) {
+ private OnResultRunnable(WsSession session, SendHandler sh, Throwable t) {
+ this.session = session;
this.sh = sh;
this.t = t;
}
@@ -384,9 +387,9 @@ public class WsRemoteEndpointImplServer extends WsRemoteEndpointImplBase {
@Override
public void run() {
if (t == null) {
- sh.onResult(new SendResult());
+ sh.onResult(new SendResult(session));
} else {
- sh.onResult(new SendResult(t));
+ sh.onResult(new SendResult(session, t));
}
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 880e0fc70d..17da9051e3 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -146,6 +146,12 @@
WebSocket session could return false for <code>onOpen()</code> before
the <code>onClose()</code> event had been completed. (markt)
</fix>
+ <add>
+ Update the WebSocket API provided by Tomcat to align with the latest
+ proposals from the Jakarta WebSocket project and make the WebSocket
+ <code>Session</code> instance available via <code>SendResult</code>.
+ (markt)
+ </add>
</changelog>
</subsection>
<subsection name="Web applications">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[tomcat] 01/03: Fix IDE warning
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit ab801f8a4f44b6baa5c5b13b80a43946e8ba738a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jun 20 10:18:29 2023 +0100
Fix IDE warning
---
.../src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
index b20bb55084..702589fad5 100644
--- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
+++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
@@ -111,7 +111,7 @@ public class ConnectionPool {
/**
* Executor service used to cancel Futures
*/
- private ThreadPoolExecutor cancellator = new ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());
+ private ThreadPoolExecutor cancellator = new ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue<>());
/**
* reference to the JMX mbean
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org