1Z0-900 · Question #27
: 27 Given: Which client-side Java method will send the employee object to the WebSocket Server Endpoint?
The correct answer is A. session.post(employee). Note: The marked "Correct Answer: A" appears to contain an error. session.post(employee) does not exist in the Java WebSocket API (JSR 356). The actual correct answer is remote.sendObject(employee) (the last option). In JSR 356, a Session object exposes getBasicRemote() or…
Question
: 27 Given:
Which client-side Java method will send the employee object to the WebSocket Server Endpoint?
Exhibit
Options
- Asession.post(employee);
- Bcontainer.send(employee);С. session.send(employee);
- Cremote.sendObject(employee);
How the community answered
(50 responses)- A90% (45)
- B8% (4)
- C2% (1)
Explanation
Note: The marked "Correct Answer: A" appears to contain an error. session.post(employee) does not exist in the Java WebSocket API (JSR 356). The actual correct answer is remote.sendObject(employee) (the last option).
In JSR 356, a Session object exposes getBasicRemote() or getAsyncRemote(), both of which return a RemoteEndpoint. That endpoint exposes sendObject(Object data), which serializes and transmits the object to the server - making remote.sendObject(employee) the only valid call.
Why the distractors are wrong:
session.post(employee)-Sessionhas nopost()method; this conflates WebSocket with HTTP/JAX-RS idioms.container.send(employee)-WebSocketContainermanages connections but has nosend()method.session.send(employee)-Sessionhas no directsend()method; sending is delegated to itsRemoteEndpoint.
Memory tip: Think of it as a two-hop call - Session → getBasicRemote() → sendObject(). The remote variable holds the RemoteEndpoint, and sendObject is what does the actual transmission. If you see a method claiming Session can send directly without going through a RemoteEndpoint, it's wrong.
Topics
Community Discussion
No community discussion yet for this question.
