Java Reference
In-Depth Information
Listing 14.14.
BulletinService
endpoint configuration
In this listing the
BulletinService
class is annotated with
@ServerEndpoint
and
will thus be exposed as a WebSocket endpoint . The
value
parameter specifies the
URI for the server . Assuming the web application is deployed under the
chapter 14
context, the full path to the service will be
http://<address>:<port>/chapter14/admin/bul-
BulletinMessadeEncoder
. A decoder is also specified that will decode incom-
ing messages . Although multiple encoders and decoders can be specified, only the first
decoder will be used.
@PathParam
The
@PathParam
annotation serves the same functional purpose as the
javax.ws.rs
.PathParam
annotation you saw earlier when we covered RESTful web services in
with
@OnMessage
,
@OnError
,
@OnOpen
, and
@OnClose.
This enables parameters to
be passed in using the URL and can help to reduce the complexity of application messages
exchanged via WebSockets. The annotation is defined as follows:
@Target(value = {ElementType.PARAMETER,
ElementType.METHOD, ElementType.FIELD})
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
public @interface PathParam {
public String value();
}
As you can see from this definition, there's only one parameter to the
@PathParam
an-
notation and that's the variable, which should also appear in the URI specified by the
@ServerEndpoint
annotation. The WebSocket implementation will attempt to convert