Skip to content

Commit 336eeac

Browse files
authored
Fixes #13915 - You can not have both Frame and Text handler in 12.1.x Jetty websocket. (#13917)
* Updated migration guide. * Updated annotation javadocs. Signed-off-by: Simone Bordet <[email protected]>
1 parent e4acc49 commit 336eeac

File tree

8 files changed

+40
-35
lines changed

8 files changed

+40
-35
lines changed

documentation/jetty/modules/programming-guide/pages/migration/12.0-to-12.1.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,13 @@ If the generation of the server response overflows `HttpConfiguration.responseHe
132132
If the generation overflows also `HttpConfiguration.maxResponseHeaderSize`, a `500` error response is generated.
133133

134134
In Jetty 12.1.x and HTTP/2 `HttpConfiguration.maxResponseHeaderSize` is used for the link:https://datatracker.ietf.org/doc/html/rfc9113#SETTINGS_MAX_HEADER_LIST_SIZE[`MAX_HEADER_LIST_SIZE`] setting, while in HTTP/3 is used for the link:https://datatracker.ietf.org/doc/html/rfc9114#SETTINGS_MAX_FIELD_SECTION_SIZE[`MAX_FIELD_SECTION_SIZE`] setting.
135+
136+
[[api-changes-websocket]]
137+
=== `WebSocket`
138+
139+
In Jetty 12.0.x, it was possible to use the Jetty WebSocket annotations to have, in the same WebSocket EndPoint, a method annotated with `@OnWebSocketFrame` and one annotated with `@OnWebSocketMessage`, `@OnWebSocketPing` or `@OnWebSocketPong`.
140+
However, this was causing issues, discussed in link:https://github.com/jetty/jetty.project/pull/12342[#12342].
141+
142+
In Jetty 12.1.x if the annotation `@OnWebSocketFrame` is present, then there cannot be methods annotated with `@OnWebSocketMessage`, `@OnWebSocketPing` or `@OnWebSocketPong`.
143+
144+
Furthermore, in Jetty 12.1.x the signature of methods annotated with `@OnWebSocketFrame` now requires a `Callback` parameter.

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketClose.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121

2222
/**
2323
* <p>Annotation for methods to receive WebSocket close events.</p>
24-
* <p>Acceptable method patterns:</p>
24+
* <p>Acceptable method signatures:</p>
2525
* <ol>
26-
* <li>{@code public void <methodName>(int statusCode, String reason)}</li>
27-
* <li>{@code public void <methodName>(Session session, int statusCode, String reason)}</li>
28-
* <li>{@code public void <methodName>(int statusCode, String reason, Callback callback)}</li>
2926
* <li>{@code public void <methodName>(Session session, int statusCode, String reason, Callback callback)}</li>
3027
* </ol>
28+
* <p>None of the parameters are mandatory, and you can specify any combination of parameters.</p>
3129
*/
3230
@Documented
3331
@Retention(RetentionPolicy.RUNTIME)

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketError.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
/**
2323
* <p>Annotation for methods to receive WebSocket errors.</p>
24-
* <p>Acceptable method patterns:</p>
24+
* <p>Acceptable method signatures:</p>
2525
* <ol>
26-
* <li>{@code public void <methodName>(Throwable cause)}</li>
27-
* <li>{@code public void <methodName>(Session session, Throwable cause)}</li>
26+
* <li>{@code public void <methodName>(Session session, *Throwable cause)}</li>
2827
* </ol>
28+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
2929
*/
3030
@Documented
3131
@Retention(RetentionPolicy.RUNTIME)

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketFrame.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323

2424
/**
2525
* <p>Annotation for methods to receive WebSocket frame events.</p>
26-
* <p>Acceptable method patterns:</p>
26+
* <p>Acceptable method signatures:</p>
2727
* <ol>
28-
* <li>{@code public void <methodName>(Frame frame)}</li>
29-
* <li>{@code public void <methodName>(Session session, Frame frame)}</li>
28+
* <li>{@code public void <methodName>(Session session, *Frame frame, *Callback callback)}</li>
3029
* </ol>
30+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
3131
*
3232
* @see Frame
3333
*/

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,38 @@
2323

2424
/**
2525
* <p>Annotation for methods to receive BINARY or TEXT WebSocket events.</p>
26-
* <p>Acceptable method patterns:</p>
27-
* <u>Text Message Versions</u>
26+
* <p>Acceptable method signatures for text messages:</p>
2827
* <ol>
29-
* <li>{@code public void methodName(String text)}</li>
30-
* <li>{@code public void methodName(Session session, String text)}</li>
31-
* <li>{@code public void methodName(Reader reader)}</li>
32-
* <li>{@code public void methodName(Session session, Reader reader)}</li>
28+
* <li>{@code public void methodName(Session session, *String text)}</li>
29+
* <li>{@code public void methodName(Session session, *Reader reader)}</li>
3330
* </ol>
31+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
3432
* <p>NOTE</p>
3533
* <p>Method that takes a {@link Reader} must have
3634
* {@link WebSocket#autoDemand()} set to {@code true}.</p>
3735
* <p>NOTE</p>
3836
* <p>The {@link Reader} argument will always use the UTF-8 charset,
3937
* (as dictated by RFC 6455). If you need to use a different charset,
4038
* you must use BINARY messages.</p>
41-
* <u>Binary Message Versions</u>
39+
* <p>Acceptable method signatures for binary messages:</p>
4240
* <ol>
43-
* <li>{@code public void methodName(ByteBuffer message, Callback callback)}</li>
44-
* <li>{@code public void methodName(Session session, ByteBuffer message, Callback callback)}</li>
45-
* <li>{@code public void methodName(InputStream stream)}</li>
46-
* <li>{@code public void methodName(Session session, InputStream stream)}</li>
41+
* <li>{@code public void methodName(Session session, *ByteBuffer message, *Callback callback)}</li>
42+
* <li>{@code public void methodName(Session session, *InputStream stream)}</li>
4743
* </ol>
44+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
4845
* <p>NOTE</p>
4946
* <p>Method that takes a {@link InputStream} must have
5047
* {@link WebSocket#autoDemand()} set to {@code true}.</p>
51-
* <u>Partial Message Variations</u>
52-
* <p>These are used to receive individual frames (and therefore partial
48+
* <p>Partial messages are used to receive individual frames (and therefore partial
5349
* messages) without aggregating the frames into a complete WebSocket message.
5450
* A {@code boolean} parameter is supplied to indicate whether the frame is
5551
* the last segment of data of the message.</p>
52+
* <p>Acceptable method signatures for partial messages:</p>
5653
* <ol>
57-
* <li>{@code public void methodName(ByteBuffer payload, boolean last, Callback callback)}</li>
58-
* <li>{@code public void methodName(Session session, ByteBuffer payload, boolean last, Callback callback)}</li>
59-
* <li>{@code public void methodName(String payload, boolean last)}</li>
60-
* <li>{@code public void methodName(Session session, String payload, boolean last)}</li>
54+
* <li>{@code public void methodName(Session session, *String payload, *boolean last)}</li>
55+
* <li>{@code public void methodName(Session session, *ByteBuffer payload, *boolean last, *Callback callback)}</li>
6156
* </ol>
57+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
6258
*/
6359
@Documented
6460
@Retention(RetentionPolicy.RUNTIME)

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketOpen.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121

2222
/**
2323
* <p>Annotation for methods to receive WebSocket connect events.</p>
24-
* <p>Acceptable method patterns:</p>
24+
* <p>Acceptable method signatures:</p>
2525
* <ol>
26-
* <li>{@code public void <methodName>(Session session)}</li>
26+
* <li>{@code public void <methodName>(*Session session)}</li>
2727
* </ol>
28+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
2829
*/
2930
@Documented
3031
@Retention(RetentionPolicy.RUNTIME)

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketPing.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
/**
2323
* <p>Annotation for methods to receive WebSocket PING events.</p>
24-
* <p>Acceptable method patterns:</p>
24+
* <p>Acceptable method signatures:</p>
2525
* <ol>
26-
* <li>{@code public void <methodName>(ByteBuffer payload)}</li>
27-
* <li>{@code public void <methodName>(Session session, ByteBuffer payload)}</li>
26+
* <li>{@code public void <methodName>(Session session, *ByteBuffer payload)}</li>
2827
* </ol>
28+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
2929
*/
3030
@Documented
3131
@Retention(RetentionPolicy.RUNTIME)

jetty-core/jetty-websocket/jetty-websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketPong.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
/**
2323
* <p>Annotation for methods to receive WebSocket PONG events.</p>
24-
* <p>Acceptable method patterns:</p>
24+
* <p>Acceptable method signatures:</p>
2525
* <ol>
26-
* <li>{@code public void <methodName>(ByteBuffer payload)}</li>
27-
* <li>{@code public void <methodName>(Session session, ByteBuffer payload)}</li>
26+
* <li>{@code public void <methodName>(Session session, *ByteBuffer payload)}</li>
2827
* </ol>
28+
* <p>The {@code *} before the parameter type means that the parameter is mandatory.</p>
2929
*/
3030
@Documented
3131
@Retention(RetentionPolicy.RUNTIME)

0 commit comments

Comments
 (0)