Search in sources :

Example 26 with Session

use of javax.websocket.Session in project jetty.project by eclipse.

the class MessageReceivingTest method testPartialTextMessage.

/**
     * Method tests receiving of text messages by parts.
     *
     * @throws Exception on exception occur
     */
@Test
public void testPartialTextMessage() throws Exception {
    final TestEndpoint echoer = new TestEndpoint(new PartialStringCaptureHandler());
    Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
    // Issue connect using instance of class that extends Endpoint
    final Session session = container.connectToServer(echoer, serverUri);
    if (LOG.isDebugEnabled())
        LOG.debug("Client Connected: {}", session);
    session.getBasicRemote().sendText("");
    session.getBasicRemote().sendText("Echo");
    if (LOG.isDebugEnabled())
        LOG.debug("Client Message Sent");
    echoer.handler.getMessageQueue().awaitMessages(2, 1000, TimeUnit.MILLISECONDS);
}
Also used : Endpoint(javax.websocket.Endpoint) Session(javax.websocket.Session) Test(org.junit.Test)

Example 27 with Session

use of javax.websocket.Session in project jetty.project by eclipse.

the class ExampleClient method run.

private void run() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    System.out.printf("WebSocketContainer Impl: %s%n", container.getClass().getName());
    ExampleSocket socket = new ExampleSocket();
    URI uri = new URI("ws://echo.websocket.org/");
    Session session = container.connectToServer(socket, uri);
    RemoteEndpoint.Basic remote = session.getBasicRemote();
    String msg = "Hello world";
    System.out.printf("Sending: %s%n", Objects.toString(msg));
    remote.sendText(msg);
    // give remote 1 second to respond
    socket.messageLatch.await(1, TimeUnit.SECONDS);
    session.close();
    // give remote 1 second to acknowledge response
    socket.closeLatch.await(1, TimeUnit.SECONDS);
    System.out.println("Socket is closed");
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) RemoteEndpoint(javax.websocket.RemoteEndpoint) URI(java.net.URI) Session(javax.websocket.Session)

Example 28 with Session

use of javax.websocket.Session in project jetty.project by eclipse.

the class EndpointEchoTest method testAbstractEchoClassref.

@Test
public void testAbstractEchoClassref() throws Exception {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    // Issue connect using class reference (class that extends abstract that extends Endpoint)
    Session session = container.connectToServer(EchoStringEndpoint.class, serverUri);
    if (LOG.isDebugEnabled())
        LOG.debug("Client Connected: {}", session);
    session.getBasicRemote().sendText("Echo");
    if (LOG.isDebugEnabled())
        LOG.debug("Client Message Sent");
// TODO: figure out echo verification.
// echoer.messageQueue.awaitMessages(1,1000,TimeUnit.MILLISECONDS);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) Session(javax.websocket.Session) Test(org.junit.Test)

Example 29 with Session

use of javax.websocket.Session in project jetty.project by eclipse.

the class EndpointEchoTest method testBasicEchoInstance.

@Test
public void testBasicEchoInstance() throws Exception {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    EndpointEchoClient echoer = new EndpointEchoClient();
    Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
    // Issue connect using instance of class 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.textCapture.messageQueue.awaitMessages(1, 1000, TimeUnit.MILLISECONDS);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) EchoStringEndpoint(org.eclipse.jetty.websocket.jsr356.samples.EchoStringEndpoint) Session(javax.websocket.Session) Test(org.junit.Test)

Example 30 with Session

use of javax.websocket.Session in project javaee7-samples by javaee-samples.

the class MyEndpointTest method testEndpointInputStream.

/**
     * The basic test method for the class {
     *
     * @MyEndpointInputStream }
     *
     * @throws DeploymentException
     * @throws IOException
     * @throws URISyntaxException
     */
@Test
public void testEndpointInputStream() throws DeploymentException, IOException, URISyntaxException, InterruptedException {
    MyEndpointClient.latch = new CountDownLatch(1);
    Session session = connectToServer("inputstream");
    assertNotNull(session);
    assertTrue(MyEndpointClient.latch.await(2, TimeUnit.SECONDS));
    assertNotNull(MyEndpointClient.response);
    assertArrayEquals(RESPONSE.getBytes(), MyEndpointClient.response);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Aggregations

Session (javax.websocket.Session)115 Test (org.junit.Test)92 URI (java.net.URI)73 WebSocketContainer (javax.websocket.WebSocketContainer)42 Endpoint (javax.websocket.Endpoint)39 CountDownLatch (java.util.concurrent.CountDownLatch)34 Context (org.apache.catalina.Context)31 DefaultServlet (org.apache.catalina.servlets.DefaultServlet)31 Tomcat (org.apache.catalina.startup.Tomcat)31 EndpointConfig (javax.websocket.EndpointConfig)29 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)27 UndertowSession (io.undertow.websockets.jsr.UndertowSession)25 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)23 ServerEndpoint (javax.websocket.server.ServerEndpoint)20 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)16 IOException (java.io.IOException)16 AnnotatedClientEndpoint (io.undertow.websockets.jsr.test.annotated.AnnotatedClientEndpoint)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 FrameChecker (io.undertow.websockets.utils.FrameChecker)14