Search in sources :

Example 21 with WebSocketContainer

use of javax.websocket.WebSocketContainer 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 22 with WebSocketContainer

use of javax.websocket.WebSocketContainer 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 23 with WebSocketContainer

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

the class MyEndpointTest method connectToServer.

/**
     * Method used to supply connection to the server by passing the naming of
     * the websocket endpoint
     *
     * @param endpoint
     * @return
     * @throws DeploymentException
     * @throws IOException
     * @throws URISyntaxException
     */
public Session connectToServer(String endpoint) throws DeploymentException, IOException, URISyntaxException {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    URI uri = new URI("ws://" + base.getHost() + ":" + base.getPort() + "/" + base.getPath() + "/" + endpoint);
    System.out.println("Connecting to: " + uri);
    return container.connectToServer(MyEndpointClient.class, uri);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI)

Example 24 with WebSocketContainer

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

the class ChatTest method connectToServer.

public Session connectToServer(Class<?> endpoint) throws DeploymentException, IOException, URISyntaxException {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    URI uri = new URI("ws://" + base.getHost() + ":" + base.getPort() + base.getPath() + "chat");
    return container.connectToServer(endpoint, uri);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI)

Example 25 with WebSocketContainer

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

the class MyClientTest method connectToServer.

public Session connectToServer(Class endpoint) throws DeploymentException, IOException, URISyntaxException {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    assertNotNull(container);
    assertNotNull(base);
    URI uri = new URI("ws://" + base.getHost() + ":" + base.getPort() + base.getPath() + "encoder-client");
    return container.connectToServer(endpoint, uri);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI)

Aggregations

WebSocketContainer (javax.websocket.WebSocketContainer)67 URI (java.net.URI)46 Session (javax.websocket.Session)42 Test (org.junit.Test)39 Context (org.apache.catalina.Context)32 Tomcat (org.apache.catalina.startup.Tomcat)32 DefaultServlet (org.apache.catalina.servlets.DefaultServlet)30 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)20 Endpoint (javax.websocket.Endpoint)14 ServerEndpoint (javax.websocket.server.ServerEndpoint)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 EndpointConfig (javax.websocket.EndpointConfig)11 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)10 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)9 BasicText (org.apache.tomcat.websocket.TesterMessageCountClient.BasicText)9 TesterProgrammaticEndpoint (org.apache.tomcat.websocket.TesterMessageCountClient.TesterProgrammaticEndpoint)9 ClientEndpoint (javax.websocket.ClientEndpoint)8 DeploymentException (javax.websocket.DeploymentException)8 TesterEndpoint (org.apache.tomcat.websocket.TesterMessageCountClient.TesterEndpoint)7 ServerConfigListener (org.apache.tomcat.websocket.pojo.TesterUtil.ServerConfigListener)7