Search in sources :

Example 1 with DecoderMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata in project jetty.project by eclipse.

the class JsrParamIdDecoderTest method testMatchDateDecoder.

@Test
public void testMatchDateDecoder() {
    DecoderMetadata metadata = new DecoderMetadata(DateDecoder.class, Date.class, MessageType.TEXT, false);
    JsrParamIdDecoder paramId = new JsrParamIdDecoder(metadata);
    JsrCallable callable = getOnMessageCallableFrom(DateTextSocket.class, "onMessage");
    Param param = new Param(0, Date.class, null);
    Assert.assertThat("Match for Decoder", paramId.process(param, callable), is(true));
}
Also used : DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata) Test(org.junit.Test)

Example 2 with DecoderMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata in project jetty.project by eclipse.

the class PrimitiveDecoderMetadataSetTest method assertDecoderType.

private void assertDecoderType(Class<? extends Decoder> expectedDecoder, MessageType expectedMsgType, Class<?> type) {
    PrimitiveDecoderMetadataSet primitives = new PrimitiveDecoderMetadataSet();
    DecoderMetadata metadata = primitives.getMetadataByType(type);
    String prefix = String.format("Metadata By Type [%s]", type.getName());
    Assert.assertThat(prefix, metadata, notNullValue());
    assertClassEquals(prefix + ".coderClass", metadata.getCoderClass(), expectedDecoder);
    Assert.assertThat(prefix + ".messageType", metadata.getMessageType(), is(expectedMsgType));
}
Also used : DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata)

Example 3 with DecoderMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata in project jetty.project by eclipse.

the class MessageHandlerFactoryTest method testStringPartial.

@Test
public void testStringPartial() throws DeploymentException {
    List<MessageHandlerMetadata> metadatas = factory.getMetadata(StringPartialHandler.class);
    Assert.assertThat("Metadata.list.size", metadatas.size(), is(1));
    MessageHandlerMetadata handlerMetadata = metadatas.get(0);
    DecoderMetadata decoderMetadata = decoders.getMetadataFor(handlerMetadata.getMessageClass());
    Assert.assertThat("Message Type", decoderMetadata.getMessageType(), is(MessageType.TEXT));
    Assert.assertThat("Message Class", handlerMetadata.getMessageClass(), is((Type) String.class));
}
Also used : Type(java.lang.reflect.Type) MessageHandlerMetadata(org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata) DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata) Test(org.junit.Test)

Example 4 with DecoderMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata in project jetty.project by eclipse.

the class MessageHandlerFactoryTest method testByteArrayPartial.

@Test
public void testByteArrayPartial() throws DeploymentException {
    List<MessageHandlerMetadata> metadatas = factory.getMetadata(ByteArrayPartialHandler.class);
    Assert.assertThat("Metadata.list.size", metadatas.size(), is(1));
    MessageHandlerMetadata handlerMetadata = metadatas.get(0);
    DecoderMetadata decoderMetadata = decoders.getMetadataFor(handlerMetadata.getMessageClass());
    Assert.assertThat("Message Type", decoderMetadata.getMessageType(), is(MessageType.BINARY));
    Assert.assertThat("Message Class", handlerMetadata.getMessageClass(), is((Type) byte[].class));
}
Also used : Type(java.lang.reflect.Type) MessageHandlerMetadata(org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata) DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata) Test(org.junit.Test)

Example 5 with DecoderMetadata

use of org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata in project jetty.project by eclipse.

the class DecoderFactory method init.

@Override
public void init(EndpointConfig config) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("init({})", config);
    }
    if (!containerScope.isRunning()) {
        throw new RuntimeException(containerScope.getClass().getName() + " is not running yet");
    }
    // Instantiate all declared decoders
    for (DecoderMetadata metadata : metadatas) {
        Wrapper wrapper = newWrapper(metadata);
        activeWrappers.put(metadata.getObjectType(), wrapper);
    }
    // Initialize all decoders
    for (Wrapper wrapper : activeWrappers.values()) {
        wrapper.decoder.init(config);
    }
}
Also used : DecoderMetadata(org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata)

Aggregations

DecoderMetadata (org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadata)8 MessageHandlerMetadata (org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata)3 Test (org.junit.Test)3 Type (java.lang.reflect.Type)2