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()));
}
}
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()));
}
}
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());
}
}
}
Aggregations