use of org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper in project jetty.project by eclipse.
the class JsrEndpointEventDriver method onPongMessage.
private void onPongMessage(ByteBuffer buffer) {
final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.PONG);
if (wrapper == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No PONG MessageHandler declared");
}
return;
}
ByteBuffer pongBuf = null;
if (BufferUtil.isEmpty(buffer)) {
pongBuf = BufferUtil.EMPTY_BUFFER;
} else {
pongBuf = ByteBuffer.allocate(buffer.remaining());
BufferUtil.put(buffer, pongBuf);
BufferUtil.flipToFlush(pongBuf, 0);
}
@SuppressWarnings("unchecked") Whole<PongMessage> pongHandler = (Whole<PongMessage>) wrapper.getHandler();
pongHandler.onMessage(new JsrPongMessage(pongBuf));
}
use of org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper in project jetty.project by eclipse.
the class JsrSessionTest method testMessageHandlerReplaceTextHandler.
@Test
public void testMessageHandlerReplaceTextHandler() throws DeploymentException {
MessageHandler oldText = new StringWholeHandler();
// add a TEXT handler
session.addMessageHandler(oldText);
// add BINARY handler
session.addMessageHandler(new ByteArrayWholeHandler());
// remove original TEXT handler
session.removeMessageHandler(oldText);
// add new TEXT handler
session.addMessageHandler(new LongMessageHandler());
MessageHandlerWrapper wrapper = session.getMessageHandlerWrapper(MessageType.BINARY);
Assert.assertThat("Binary Handler", wrapper.getHandler(), instanceOf(ByteArrayWholeHandler.class));
Assert.assertEquals("Message Class", wrapper.getMetadata().getMessageClass(), byte[].class);
wrapper = session.getMessageHandlerWrapper(MessageType.TEXT);
Assert.assertThat("Text Handler", wrapper.getHandler(), instanceOf(LongMessageHandler.class));
Assert.assertEquals("Message Class", wrapper.getMetadata().getMessageClass(), Long.class);
}
use of org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper in project jetty.project by eclipse.
the class JsrSessionTest method testMessageHandlerText.
@Test
public void testMessageHandlerText() throws DeploymentException {
session.addMessageHandler(new StringWholeHandler());
MessageHandlerWrapper wrapper = session.getMessageHandlerWrapper(MessageType.TEXT);
Assert.assertThat("Text Handler", wrapper.getHandler(), instanceOf(StringWholeHandler.class));
Assert.assertEquals("Message Class", wrapper.getMetadata().getMessageClass(), String.class);
}
Aggregations