Search in sources :

Example 26 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-programmatic");
    return container.connectToServer(endpoint, uri);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI)

Example 27 with WebSocketContainer

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

the class EncoderEndpointTest 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(Class<?> endpoint) throws DeploymentException, IOException, URISyntaxException {
    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    URI uri = new URI("ws://" + base.getHost() + ":" + base.getPort() + base.getPath() + "encoder");
    return container.connectToServer(endpoint, uri);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI)

Example 28 with WebSocketContainer

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

the class MyEndpointTest 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() + "websocket");
    System.out.println("Connecting to: " + uri);
    return container.connectToServer(endpoint, uri);
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI)

Example 29 with WebSocketContainer

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

the class MyEndpointTest method connectToServer.

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

Example 30 with WebSocketContainer

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

the class Client method main.

public static void main(String[] args) {
    try {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://echo.websocket.org:80/";
        System.out.println("Connecting to " + uri);
        container.connectToServer(MyClientEndpoint.class, URI.create(uri));
        messageLatch.await(100, TimeUnit.SECONDS);
    } catch (DeploymentException | InterruptedException | IOException ex) {
        Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) DeploymentException(javax.websocket.DeploymentException) IOException(java.io.IOException)

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