Search in sources :

Example 6 with MessageHandlerWrapper

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));
}
Also used : MessageHandlerWrapper(org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper) PongMessage(javax.websocket.PongMessage) JsrPongMessage(org.eclipse.jetty.websocket.jsr356.JsrPongMessage) ByteBuffer(java.nio.ByteBuffer) Whole(javax.websocket.MessageHandler.Whole) JsrPongMessage(org.eclipse.jetty.websocket.jsr356.JsrPongMessage)

Example 7 with MessageHandlerWrapper

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);
}
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 8 with MessageHandlerWrapper

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

Aggregations

Test (org.junit.Test)4 MessageHandler (javax.websocket.MessageHandler)3 Whole (javax.websocket.MessageHandler.Whole)3 MessageHandlerWrapper (org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper)3 StringWholeHandler (org.eclipse.jetty.websocket.jsr356.handlers.StringWholeHandler)3 MessageInputStream (org.eclipse.jetty.websocket.common.message.MessageInputStream)2 ByteArrayWholeHandler (org.eclipse.jetty.websocket.jsr356.handlers.ByteArrayWholeHandler)2 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 ByteBuffer (java.nio.ByteBuffer)1 PongMessage (javax.websocket.PongMessage)1 MessageReader (org.eclipse.jetty.websocket.common.message.MessageReader)1 JsrPongMessage (org.eclipse.jetty.websocket.jsr356.JsrPongMessage)1 ByteBufferPartialHandler (org.eclipse.jetty.websocket.jsr356.handlers.ByteBufferPartialHandler)1 LongMessageHandler (org.eclipse.jetty.websocket.jsr356.handlers.LongMessageHandler)1 BinaryPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage)1 BinaryWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryWholeMessage)1 TextPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.TextPartialMessage)1 TextWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.TextWholeMessage)1 MessageHandlerMetadata (org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata)1