Search in sources :

Example 1 with StringWholeHandler

use of org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler 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);
}
Also used : StringWholeHandler(org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler) ByteArrayWholeHandler(org.eclipse.jetty.websocket.jsr356.handlers.ByteArrayWholeHandler) Test(org.junit.Test)

Example 2 with StringWholeHandler

use of org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler 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);
}
Also used : StringWholeHandler(org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler) LongMessageHandler(org.eclipse.jetty.websocket.jsr356.handlers.LongMessageHandler) MessageHandler(javax.websocket.MessageHandler) ByteArrayWholeHandler(org.eclipse.jetty.websocket.jsr356.handlers.ByteArrayWholeHandler) LongMessageHandler(org.eclipse.jetty.websocket.jsr356.handlers.LongMessageHandler) Test(org.junit.Test)

Example 3 with StringWholeHandler

use of org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler 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);
}
Also used : StringWholeHandler(org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler) Test(org.junit.Test)

Aggregations

StringWholeHandler (org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler)3 Test (org.junit.Test)3 ByteArrayWholeHandler (org.eclipse.jetty.websocket.jsr356.handlers.ByteArrayWholeHandler)2 MessageHandler (javax.websocket.MessageHandler)1 LongMessageHandler (org.eclipse.jetty.websocket.jsr356.handlers.LongMessageHandler)1