mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-03 12:29:31 +00:00
Issue #4903 - check endpoint class is default constructable
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
28a588b8bd
commit
add00c9dd8
@ -18,7 +18,6 @@
|
||||
|
||||
package org.eclipse.jetty.websocket.jsr356.server;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
@ -35,6 +34,7 @@ import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
|
||||
import org.eclipse.jetty.websocket.common.util.ReflectUtils;
|
||||
import org.eclipse.jetty.websocket.jsr356.ClientContainer;
|
||||
import org.eclipse.jetty.websocket.jsr356.JsrSessionFactory;
|
||||
import org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointScanner;
|
||||
@ -138,8 +138,8 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
||||
|
||||
private void addEndpoint(ServerEndpointMetadata metadata) throws DeploymentException
|
||||
{
|
||||
if (!Modifier.isPublic(metadata.getEndpointClass().getModifiers()))
|
||||
throw new DeploymentException("Class modifier must be public");
|
||||
if (!ReflectUtils.isDefaultConstructable(metadata.getEndpointClass()))
|
||||
throw new DeploymentException("Cannot access default constructor for the Endpoint class");
|
||||
|
||||
JsrCreator creator = new JsrCreator(this, metadata, this.configuration.getFactory().getExtensionFactory());
|
||||
this.configuration.addMapping("uri-template|" + metadata.getPath(), creator);
|
||||
|
@ -94,6 +94,21 @@ public class PrivateEndpointTest
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("InnerClassMayBeStatic")
|
||||
public class ServerSocketNonStatic extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
@Override
|
||||
public void onOpen(Session session, EndpointConfig config)
|
||||
{
|
||||
session.addMessageHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@ServerEndpoint("/annotated")
|
||||
private static class AnnotatedServerSocket
|
||||
{
|
||||
@ -120,7 +135,18 @@ public class PrivateEndpointTest
|
||||
|
||||
assertThat(error.getCause(), instanceOf(DeploymentException.class));
|
||||
DeploymentException deploymentException = (DeploymentException)error.getCause();
|
||||
assertThat(deploymentException.getMessage(), containsString("Class modifier must be public"));
|
||||
assertThat(deploymentException.getMessage(), containsString("Cannot access default constructor for the Endpoint class"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerEndpoint()
|
||||
{
|
||||
RuntimeException error = assertThrows(RuntimeException.class, () ->
|
||||
start(container -> container.addEndpoint(ServerEndpointConfig.Builder.create(ServerSocketNonStatic.class, "/").build())));
|
||||
|
||||
assertThat(error.getCause(), instanceOf(DeploymentException.class));
|
||||
DeploymentException deploymentException = (DeploymentException)error.getCause();
|
||||
assertThat(deploymentException.getMessage(), containsString("Cannot access default constructor for the Endpoint class"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -131,7 +157,7 @@ public class PrivateEndpointTest
|
||||
|
||||
assertThat(error.getCause(), instanceOf(DeploymentException.class));
|
||||
DeploymentException deploymentException = (DeploymentException)error.getCause();
|
||||
assertThat(deploymentException.getMessage(), containsString("Class modifier must be public"));
|
||||
assertThat(deploymentException.getMessage(), containsString("Cannot access default constructor for the Endpoint class"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user