1Z0-900 · Question #26
You need to exchange large binary messages using chunks in a WebSocket application. Identify two ways in which you can receive partial messages. (Choose two.)
C and D are the correct answers. In the Java WebSocket API (JSR 356), partial binary messages can be received in exactly two ways. First, MessageHandler.Partial<ByteBuffer> (C) is an interface you register on a Session object; its onMessage(ByteBuffer data, boolean last) method…
Question
You need to exchange large binary messages using chunks in a WebSocket application. Identify two ways in which you can receive partial messages. (Choose two.)
Options
- ADefine an @OnMessage method with a single MimePart parameter.
- BUse a ChunkListener interface implementation.
- CUse a MessageHandler.Partial<ByteBuffer> interface implementation.
- DDefine an @OnMessage method with byte [] as the first parameter and a boolean as the second
Explanation
C and D are the correct answers.
In the Java WebSocket API (JSR 356), partial binary messages can be received in exactly two ways. First, MessageHandler.Partial<ByteBuffer> (C) is an interface you register on a Session object; its onMessage(ByteBuffer data, boolean last) method is invoked for each arriving chunk, with last signaling the final piece. Second, an @OnMessage method (D) supports partial delivery when its signature is void onMessage(byte[] data, boolean last) - the same boolean flag indicates whether the current chunk is the final one.
Why the distractors are wrong:
- A is wrong because
MimePartbelongs to MIME/multipart HTTP processing (JAX-RS), not the WebSocket API - there is no such parameter type in@OnMessagefor chunked binary handling. - B is wrong because
ChunkListenerdoes not exist in the Java WebSocket API; it is a fabricated distractor with no corresponding interface in JSR 356.
Memory tip: Think "Partial = Parameter boolean OR Partial interface." Any legitimate partial-message mechanism in the WebSocket API involves a boolean last flag - either as a method parameter in @OnMessage or inside MessageHandler.Partial<T>. If an answer choice lacks that boolean concept, it's a distractor.
Topics
Community Discussion
No community discussion yet for this question.