Skip to content

Commit

Permalink
Fix #185 - expose the WebSocket session via SendResult
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Jun 29, 2023
1 parent f270605 commit 6bf7ac1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
45 changes: 44 additions & 1 deletion api/client/src/main/java/jakarta/websocket/SendResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019 Oracle and/or its affiliates and others.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -25,23 +25,57 @@
*/
final public class SendResult {

private final Session session;
private final Throwable exception;
private final boolean isOK;

/**
* Construct a SendResult carrying an exception.
*
* @param session the WebSocket session in which the message was sent
* @param exception the exception causing a send failure.
*/
public SendResult(Session session, Throwable exception) {
this.session = session;
this.exception = exception;
this.isOK = false;
}

/**
* Construct a SendResult signifying a successful send carrying no exception.
*
* @param session the WebSocket session in which the message was sent
*/
public SendResult(Session session) {
this.session = session;
this.exception = null;
this.isOK = true;
}

/**
* Construct a SendResult carrying an exception.
*
* @param exception the exception causing a send failure.
*
* @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.session = null;
this.exception = exception;
this.isOK = false;
}

/**
* Construct a SendResult signifying a successful send carrying no exception.
*
* @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.session = null;
this.exception = null;
this.isOK = true;
}
Expand All @@ -63,4 +97,13 @@ public Throwable getException() {
public boolean isOK() {
return this.isOK;
}

/**
* 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;
}
}
3 changes: 3 additions & 0 deletions spec/src/main/asciidoc/WebSocket.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,9 @@ This appendix is non-normative.
* https://github.com/jakartaee/websocket/issues/176[Issue 176]
Clarify the responsibilities for sending ping messages.

* https://github.com/jakartaee/websocket/issues/185[Issue 185]
Add the `getSession()` method to `SendResult`.

=== Changes Between 2.1 and 2.0

* https://github.com/eclipse-ee4j/websocket-api/issues/190[Issue 190] and
Expand Down

0 comments on commit 6bf7ac1

Please sign in to comment.