Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #4772 - support partial messages for Jetty WS API annotations #6357

Merged
merged 4 commits into from Jun 10, 2021

Conversation

lachlan-roberts
Copy link
Contributor

Closes #4772.

Adds support for partial messages to the Jetty WebSocket API @OnWebSocketMessage annotation.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@sbordet sbordet added this to In progress in Jetty 10.0.5/11.0.5 FROZEN via automation Jun 4, 2021
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
* for the {@link java.nio.ByteBuffer} type as no copying needs to occur to get the data into this format.</p>
* <ol>
* <li><code>public void methodName(ByteBuffer payload, boolean last)</code></li>
* <li><code>public void methodName(byte payload, boolean last)</code></li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this byte[] in the signature?
Frankly, I would not offer a byte[] variant.

Also, what do you do with the ByteBuffer version if it is retained by the application, but not consumed? I think the signature needs a Callback to signal when the ByteBuffer can be released, no?

If you choose for no Callback, then you have to remove from the javadocs above "as no copying needs to occur to get the data", and specify precisely that applications must consume the buffer before returning from the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what do you do with the ByteBuffer version if it is retained by the application, but not consumed? I think the signature needs a Callback to signal when the ByteBuffer can be released, no?

The websocket-core API has this feature but for the Jetty and Javax APIs they don't take callbacks, so you only own the ByteBuffer only until the method returns. If you wish to retain the ByteBuffer you must copy it.

If you choose for no Callback, then you have to remove from the javadocs above "as no copying needs to occur to get the data"

By this I meant that ByteBuffer can be passed into the method directly and doesn't need to be copied by the implementation, but this is not the case for byte[] or String and there will be some copying involved to get it into that format. I didn't mean that you can retain the ByteBuffer indefinitely without copying it.

and specify precisely that applications must consume the buffer before returning from the method.

They don't have to consume the buffer, if they want to ignore the rest of the message they don't need to consume it. And this is no different to the whole message signatures.

I have removed the byte[] option and this part of the Javadoc so it is less confusing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By this I meant that ByteBuffer can be passed into the method directly and doesn't need to be copied by the implementation, but this is not the case for byte[] or String and there will be some copying involved to get it into that format. I didn't mean that you can retain the ByteBuffer indefinitely without copying it.

This is the javadoc for users -- the implementation details should be left out.
As a user, though, I must know if I have to copy the buffer (assuming interest in the content) before returning from the method.

Jetty 10.0.5/11.0.5 FROZEN automation moved this from In progress to Review in progress Jun 7, 2021
…ages.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
* </ol>
* <p>Note: Similar to the signatures above these can all be used with an optional first {@link Session} parameter.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add a note about split UTF-8 characters... I'm guessing the payload always contains full UTF-8 sequences and you keep split UTF-8 bytes around for the next call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what happens if the message becomes bad during a partial message delivery.
Eg: first 2 calls to methodName(String, boolean) are fine, but the 3rd call cannot be made as the ws-core found the message to be in violation of the websocket messaging rules.

InvalidDoubleTextListener doubleTextListener = new InvalidDoubleTextListener();
assertThrows(InvalidWebSocketException.class, () -> client.connect(doubleTextListener, serverUri));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add one more test for split UTF-8 bytes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and late bad message / utf-8 as well.

  1. good partial sequence
  2. good partial sequence
  3. bad partial utf-8 sequence

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@sbordet sbordet self-requested a review June 10, 2021 13:20
Jetty 10.0.5/11.0.5 FROZEN automation moved this from Review in progress to Reviewer approved Jun 10, 2021
@sbordet sbordet merged commit 6dea025 into jetty-10.0.x Jun 10, 2021
Jetty 10.0.5/11.0.5 FROZEN automation moved this from Reviewer approved to Done Jun 10, 2021
@sbordet sbordet deleted the jetty-10.0.x-4772-Annotation-WS-PartialMessage branch June 10, 2021 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Jetty WebSocket API onMessage annotation does not support partial messages.
3 participants