Annotation Type WebSocketMapping
Marks a com.codename1.backend.WebSocket as the endpoint for a path.
@WebSocketMapping("/chat")
public class ChatEndpoint implements WebSocket {
public void onOpen(WebSocketSession session) { }
public void onText(WebSocketSession session, String message) { }
public void onBinary(WebSocketSession session, byte[] m, int off, int len) { }
}
The build finds these and registers them in the generated entry point, so a
websocket endpoint needs no more start-up code than a @RestController does.
Why this is on the TYPE and the HTTP mappings are on methods
A @GetMapping marks a call: one request in, one response out, and the method
signature is the whole contract. A websocket is a CONNECTION, and its contract
is seven callbacks that share per-connection state -- which is an object, not a
method. Putting the annotation on a method would mean either that the method
runs per connection (a factory pretending to be a handler) or that it runs once
and the annotation is on the wrong element.
What it keeps from @GetMapping is everything that matters to a reader: the
path is relative to a class-level @RequestMapping if there is one, a
constructor taking a DataSource or an EntityManager is injected the same
way, and two endpoints claiming one path is a build error rather than a
race decided by registration order.
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
-