From the course: WebSocket Programming with Java EE

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Annotation methodology

Annotation methodology

From the course: WebSocket Programming with Java EE

Start my 1-month free trial

Annotation methodology

- [Instructor] Annotations are used to define endpoints and lifecycle methods, and are arguably the easiest way to construct WebSocket endpoints. Okay, let's dive into the annotation way of defining WebSocket endpoints. All configurations are made in the same class, and it's the same class that defines the lifecycle methods. Configuration is done by passing metadata to the annotations, and this, as you'll see later on, is quite different to it's implementation of the programmatic method. So, the specify that a class represents an endpoint, we annotate the class at server endpoint, and pass it the URI of it's endpoint location. In this case, the endpoint location is chat, and we annotate four methods that will handle the WebSocket lifecycle on open, on message, on close, and on error. Each of the four lifecycle methods accepts at least the session as a parameter, and the OnMessage method accepts a message object that contains the message received. Remember that we touched on the…

Contents