Search in sources :

Example 1 with InvalidSignatureException

use of org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException in project jetty.project by eclipse.

the class ServerAnnotatedEndpointScanner_InvalidSignaturesTest method testScan_InvalidSignature.

@Test
public void testScan_InvalidSignature() throws DeploymentException {
    WebSocketContainerScope container = new SimpleContainerScope(WebSocketPolicy.newClientPolicy());
    AnnotatedServerEndpointMetadata metadata = new AnnotatedServerEndpointMetadata(container, pojo, null);
    AnnotatedEndpointScanner<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    try {
        scanner.scan();
        Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
    } catch (InvalidSignatureException e) {
        if (LOG.isDebugEnabled())
            LOG.debug("{}:{}", e.getClass(), e.getMessage());
        Assert.assertThat("Message", e.getMessage(), containsString(expectedAnnoClass.getSimpleName()));
    }
}
Also used : InvalidSignatureException(org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) WebSocketContainerScope(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) SimpleContainerScope(org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope) ServerEndpoint(javax.websocket.server.ServerEndpoint) Test(org.junit.Test)

Example 2 with InvalidSignatureException

use of org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException in project jetty.project by eclipse.

the class ClientAnnotatedEndpointScanner_InvalidSignaturesTest method testScan_InvalidSignature.

@Test
public void testScan_InvalidSignature() throws DeploymentException {
    AnnotatedClientEndpointMetadata metadata = new AnnotatedClientEndpointMetadata(container, pojo);
    AnnotatedEndpointScanner<ClientEndpoint, ClientEndpointConfig> scanner = new AnnotatedEndpointScanner<>(metadata);
    try {
        scanner.scan();
        Assert.fail("Expected " + InvalidSignatureException.class + " with message that references " + expectedAnnoClass + " annotation");
    } catch (InvalidSignatureException e) {
        if (LOG.isDebugEnabled())
            LOG.debug("{}:{}", e.getClass(), e.getMessage());
        Assert.assertThat("Message", e.getMessage(), containsString(expectedAnnoClass.getSimpleName()));
    }
}
Also used : InvalidSignatureException(org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException) AnnotatedEndpointScanner(org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientEndpoint(javax.websocket.ClientEndpoint) AnnotatedClientEndpointMetadata(org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata) Test(org.junit.Test)

Example 3 with InvalidSignatureException

use of org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException in project jetty.project by eclipse.

the class AnnotatedEndpointScanner method onMethodAnnotation.

@Override
public void onMethodAnnotation(AnnotatedEndpointMetadata<T, C> metadata, Class<?> pojo, Method method, Annotation annotation) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("onMethodAnnotation({}, {}, {}, {})", metadata, pojo, method, annotation);
    }
    if (isAnnotation(annotation, OnOpen.class)) {
        assertIsPublicNonStatic(method);
        assertIsReturn(method, Void.TYPE);
        assertNotDuplicate(metadata.onOpen, OnOpen.class, pojo, method);
        OnOpenCallable onopen = new OnOpenCallable(pojo, method);
        visitMethod(onopen, pojo, method, paramsOnOpen, OnOpen.class);
        metadata.onOpen = onopen;
        return;
    }
    if (isAnnotation(annotation, OnClose.class)) {
        assertIsPublicNonStatic(method);
        assertIsReturn(method, Void.TYPE);
        assertNotDuplicate(metadata.onClose, OnClose.class, pojo, method);
        OnCloseCallable onclose = new OnCloseCallable(pojo, method);
        visitMethod(onclose, pojo, method, paramsOnClose, OnClose.class);
        metadata.onClose = onclose;
        return;
    }
    if (isAnnotation(annotation, OnError.class)) {
        assertIsPublicNonStatic(method);
        assertIsReturn(method, Void.TYPE);
        assertNotDuplicate(metadata.onError, OnError.class, pojo, method);
        OnErrorCallable onerror = new OnErrorCallable(pojo, method);
        visitMethod(onerror, pojo, method, paramsOnError, OnError.class);
        metadata.onError = onerror;
        return;
    }
    if (isAnnotation(annotation, OnMessage.class)) {
        assertIsPublicNonStatic(method);
        // assertIsReturn(method,Void.TYPE); // no validation, it can be any return type
        OnMessageCallable onmessage = new OnMessageCallable(pojo, method);
        visitMethod(onmessage, pojo, method, paramsOnMessage, OnMessage.class);
        OnMessage messageAnno = (OnMessage) annotation;
        Param param = onmessage.getMessageObjectParam();
        switch(param.role) {
            case MESSAGE_BINARY:
                metadata.onBinary = new OnMessageBinaryCallable(onmessage);
                metadata.setMaxBinaryMessageSize(messageAnno.maxMessageSize());
                break;
            case MESSAGE_BINARY_STREAM:
                metadata.onBinaryStream = new OnMessageBinaryStreamCallable(onmessage);
                metadata.setMaxBinaryMessageSize(messageAnno.maxMessageSize());
                break;
            case MESSAGE_TEXT:
                metadata.onText = new OnMessageTextCallable(onmessage);
                metadata.setMaxTextMessageSize(messageAnno.maxMessageSize());
                break;
            case MESSAGE_TEXT_STREAM:
                metadata.onTextStream = new OnMessageTextStreamCallable(onmessage);
                metadata.setMaxTextMessageSize(messageAnno.maxMessageSize());
                break;
            case MESSAGE_PONG:
                metadata.onPong = new OnMessagePongCallable(onmessage);
                break;
            default:
                StringBuilder err = new StringBuilder();
                err.append("An unrecognized message type <");
                err.append(param.type);
                err.append(">: does not meet specified type categories of [TEXT, BINARY, DECODER, or PONG]");
                throw new InvalidSignatureException(err.toString());
        }
    }
}
Also used : InvalidSignatureException(org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException) OnMessage(javax.websocket.OnMessage)

Aggregations

InvalidSignatureException (org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureException)3 AnnotatedEndpointScanner (org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner)2 Test (org.junit.Test)2 ClientEndpoint (javax.websocket.ClientEndpoint)1 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)1 OnMessage (javax.websocket.OnMessage)1 ServerEndpoint (javax.websocket.server.ServerEndpoint)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 SimpleContainerScope (org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope)1 WebSocketContainerScope (org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope)1 AnnotatedClientEndpointMetadata (org.eclipse.jetty.websocket.jsr356.client.AnnotatedClientEndpointMetadata)1