use of org.eclipse.jetty.websocket.jsr356.handlers.ByteArrayWholeHandler in project jetty.project by eclipse.
the class JsrSessionTest method testMessageHandlerBoth.
@Test
public void testMessageHandlerBoth() throws DeploymentException {
session.addMessageHandler(new StringWholeHandler());
session.addMessageHandler(new ByteArrayWholeHandler());
MessageHandlerWrapper wrapper = session.getMessageHandlerWrapper(MessageType.TEXT);
Assert.assertThat("Text Handler", wrapper.getHandler(), instanceOf(StringWholeHandler.class));
Assert.assertEquals("Message Class", wrapper.getMetadata().getMessageClass(), String.class);
wrapper = session.getMessageHandlerWrapper(MessageType.BINARY);
Assert.assertThat("Binary Handler", wrapper.getHandler(), instanceOf(ByteArrayWholeHandler.class));
Assert.assertEquals("Message Class", wrapper.getMetadata().getMessageClass(), byte[].class);
}
use of org.eclipse.jetty.websocket.jsr356.handlers.ByteArrayWholeHandler 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);
}
Aggregations