Search in sources :

Example 86 with Session

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

the class EndpointEchoTest method testBasicEchoClassref.

@Test
public void testBasicEchoClassref() throws Exception {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    // Issue connect using class reference (class extends Endpoint)
    Session session = container.connectToServer(EndpointEchoClient.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.textCapture.messageQueue.awaitMessages(1,1000,TimeUnit.MILLISECONDS);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) Session(javax.websocket.Session) Test(org.junit.Test)

Example 87 with Session

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

the class MessageReceivingTest method testWholeBinaryMessage.

/**
     * Method tests receiving of binary messages at once.
     *
     * @throws Exception on exception occur
     */
@Test
public void testWholeBinaryMessage() throws Exception {
    final TestEndpoint echoer = new TestEndpoint(new WholeByteBufferCaptureHandler());
    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);
    sendBinary(session, "");
    sendBinary(session, "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 88 with Session

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

the class MessageReceivingTest method testPartialBinaryMessage.

/**
     * Method tests receiving of binary messages by parts.
     *
     * @throws Exception on exception occur
     */
@Test
public void testPartialBinaryMessage() throws Exception {
    final TestEndpoint echoer = new TestEndpoint(new PartialByteBufferCaptureHandler());
    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);
    sendBinary(session, "");
    sendBinary(session, "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 89 with Session

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

the class MyEndpointTest method testTextEndpoint.

@Test
public void testTextEndpoint() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
    MyEndpointTextClient.latch = new CountDownLatch(1);
    final String TEXT = "Hello World!";
    Session session = connectToServer(MyEndpointTextClient.class);
    assertNotNull(session);
    session.addMessageHandler(new MessageHandler.Whole<String>() {

        @Override
        public void onMessage(String text) {
            assertEquals(TEXT, text);
        }
    });
    assertTrue(MyEndpointTextClient.latch.await(2, TimeUnit.SECONDS));
}
Also used : MessageHandler(javax.websocket.MessageHandler) CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.websocket.Session) Test(org.junit.Test)

Example 90 with Session

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

the class GoogleDocClient method start.

@Override
public void start(Stage stage) throws Exception {
    final Session session = connectToServer();
    System.out.println("Connected to server: " + session.getId());
    stage.setTitle("Google Docs Emulator using WebSocket");
    textarea = new TextArea();
    textarea.textProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            System.out.println("New value: " + newValue);
            try {
                session.getBasicRemote().sendText(newValue);
            } catch (IOException ex) {
                Logger.getLogger(GoogleDocClient.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    textarea.setPrefSize(500, 300);
    textarea.setWrapText(true);
    Scene scene = new Scene(textarea);
    stage.setScene(scene);
    stage.show();
}
Also used : TextArea(javafx.scene.control.TextArea) IOException(java.io.IOException) Scene(javafx.scene.Scene) Session(javax.websocket.Session)

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