@Retention(value=RUNTIME) @Target(value=METHOD) public @interface OnMessage
The allowed parameters are:
String
to receive the whole messageReader
to receive the whole message as a blocking streamDecoder.Text
or
Decoder.TextStream
).ByteBuffer
to receive the whole messageByteBuffer
and boolean pair to receive the message in partsInputStream
to receive the whole message as a blocking streamDecoder.Binary
or
Decoder.BinaryStream
).PongMessage
for handling pong messagesPathParam
annotation for server endpoints.Session
parameterThe method may have a non-void return type, in which case the web socket runtime must interpret this as a web socket message to return to the peer. The allowed data types for this return type, other than void, are String, ByteBuffer, byte[], any Java primitive or class equivalent, and anything for which there is an encoder. If the method uses a Java primitive as a return value, the implementation must construct the text message to send using the standard Java string representation of the Java primitive unless there developer provided encoder for the type configured for this endpoint, in which case that encoder must be used. If the method uses a class equivalent of a Java primitive as a return value, the implementation must construct the text message from the Java primitive equivalent as described above.
Developers should note that if developer closes the session during the invocation of a method with a return type, the method will complete but the return value will not be delivered to the remote endpoint. The send failure will be passed back into the endpoint's error handling method.
For example:
@OnMessage
public void processGreeting(String message, Session session) {
System.out.println("Greeting received:" + message);
}
For example:
@OnMessage
public void processUpload(byte[] b, boolean last, Session session) {
// process partial data here, which check on last to see if these is more on the way
}
Developers should not continue to reference message objects of type Reader
, ByteBuffer
or InputStream
after the annotated method has completed, since they
may be recycled by the implementation.Modifier and Type | Optional Element and Description |
---|---|
long |
maxMessageSize
Specifies the maximum size of message in bytes that the method
this annotates will be able to process, or -1 to indicate
that there is no maximum.
|
public abstract long maxMessageSize
Copyright © 1996-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.