JDK-8159053 : Improve onPing/onClose behavior
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-06-08
  • Updated: 2017-05-17
  • Resolved: 2016-12-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Fixed
Related Reports
Relates :  
Description
onPing/onClose should be more robust and friendly while fully-compliant with the protocol

(see the originating discussion here:  http://mail.openjdk.java.net/pipermail/net-dev/2016-June/009875.html)

1. Change `sendClose(CloseCode, CharSequence)` to `sendClose(int, CharSequence)`
2. Remove `CloseCode`
3. Make both `sendClose` methods idempotent
4. Change `default void onClose(WebSocket webSocket, Optional<CloseCode> code, String reason) { }` to
`default CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String reason) { return null; }`
5. Change `default CompletionStage<?> onPing(WebSocket webSocket, ByteBuffer message) {
            return webSocket.sendPong(message).thenRun(() -> webSocket.request(1));
        }
` to `default CompletionStage<?> onPing(WebSocket webSocket, ByteBuffer message) {
            return null;
        }`
6. Specify one of the (onClose|onError) is always invoked. e.g. onClose(1006)
Comments
Fixed in: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/3b25414eb6af
09-12-2016