use of javax.websocket.WebSocketContainer in project jetty.project by eclipse.
the class SessionInfoIT method testSessionInfo.
@Test
public void testSessionInfo() throws Exception {
URI serverURI = new URI("ws://localhost:58080/cdi-webapp/");
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
ClientSessionInfoSocket socket = new ClientSessionInfoSocket();
container.connectToServer(socket, serverURI.resolve("sessioninfo"));
assertThat("Await open", socket.openLatch.await(1, TimeUnit.SECONDS), is(true));
socket.session.getBasicRemote().sendText("info");
socket.messages.awaitEventCount(1, 2, TimeUnit.SECONDS);
System.out.printf("socket.messages.size = %s%n", socket.messages.size());
String msg = socket.messages.poll();
System.out.printf("Message is [%s]%n", msg);
assertThat("Message", msg, containsString("HttpSession = HttpSession"));
socket.session.getBasicRemote().sendText("close");
assertThat("Await close", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
}
use of javax.websocket.WebSocketContainer in project jetty.project by eclipse.
the class AnnotatedEchoTest method testEcho.
@Test
public void testEcho() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
AnnotatedEchoClient echoer = new AnnotatedEchoClient();
Session session = container.connectToServer(echoer, serverUri);
session.getBasicRemote().sendText("Echo");
echoer.messageQueue.awaitMessages(1, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.WebSocketContainer in project jetty.project by eclipse.
the class AnnotatedEndpointConfigTest method startEnv.
@BeforeClass
public static void startEnv() throws Exception {
// Server
server = new Server();
ServerConnector connector = new ServerConnector(server);
server.addConnector(connector);
handler = new EchoHandler();
ContextHandler context = new ContextHandler();
context.setContextPath("/");
context.setHandler(handler);
server.setHandler(context);
// Start Server
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
serverUri = new URI(String.format("ws://%s:%d/", host, port));
// Connect client
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
socket = new AnnotatedEndpointClient();
session = container.connectToServer(socket, serverUri);
Assert.assertThat("Session", session, notNullValue());
config = socket.config;
Assert.assertThat("EndpointConfig", config, notNullValue());
Assert.assertThat("EndpointConfig", config, instanceOf(ClientEndpointConfig.class));
ceconfig = (ClientEndpointConfig) config;
Assert.assertThat("EndpointConfig", ceconfig, notNullValue());
}
use of javax.websocket.WebSocketContainer in project jetty.project by eclipse.
the class MisbehavingClassTest method testEndpointRuntimeOnOpen.
@SuppressWarnings("Duplicates")
@Test
public void testEndpointRuntimeOnOpen() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
EndpointRuntimeOnOpen socket = new EndpointRuntimeOnOpen();
try (StacklessLogging logging = new StacklessLogging(EndpointRuntimeOnOpen.class, WebSocketSession.class)) {
// expecting IOException during onOpen
expectedException.expect(IOException.class);
expectedException.expectCause(instanceOf(RuntimeException.class));
container.connectToServer(socket, serverUri);
expectedException.reportMissingExceptionWithMessage("Should have failed .connectToServer()");
assertThat("Close should have occurred", socket.closeLatch.await(1, TimeUnit.SECONDS), is(true));
Throwable cause = socket.errors.pop();
assertThat("Error", cause, instanceOf(RuntimeException.class));
}
}
use of javax.websocket.WebSocketContainer in project jetty.project by eclipse.
the class EndpointEchoTest method testAbstractEchoInstance.
@Test
public void testAbstractEchoInstance() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
EchoStringEndpoint echoer = new EchoStringEndpoint();
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
// Issue connect using instance of class that extends abstract that extends Endpoint
Session session = container.connectToServer(echoer, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
echoer.messageQueue.awaitMessages(1, 1000, TimeUnit.MILLISECONDS);
}
Aggregations