Java Reference
In-Depth Information
Table 14.1. @OnMessage parameter types
Type
Parameter type
Partial message
Notes
Text
String
No
Text
int, long, float, double, etc.
No
If boolean true, message fin-
ished.
Text
String, boolean
Yes
Decoder.Text must be re-
gistered.
Text
Custom object
No
Binary
byte[]
No
If boolean true, message fin-
ished.
Binary
byte[], boolean
Yes
Binary
ByteBuffer
No
If boolean true, message fin-
ished.
Binary
ByteBuffer, boolean
Yes
Binary
InputStream
Yes
Decover.Binary must be re-
gistered.
Binary
Custom object
No
Pong
PongMessage
No
With the custom object types in table 14.1 , custom decoders must be registered on the
@ServerEndpoint . In addition to the parameters listed in the table, a message annot-
ated with @OnMessage can accept the following parameters:
Session— Session object associated with the client
@PathParam— Maps URI variables to parameters
The parameters may appear in any order—the container will dynamically invoke the meth-
od using reflection.
Unlike the MessageHandler interface you saw earlier, methods decorated with
@OnMessage can return data. If the return type is something other than a String or a
Java primitive, an encoder must be registered on @ServerEndpoint for the type; other-
wise an error will be generated.
Now that you have a theoretical handle on this annotation, let's look at an example of it
from ActionBazaar in the next listing.
 
Search WWH ::




Custom Search