Search in sources :

Example 31 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 32 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 33 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 34 with WebSocketContainer

use of javax.websocket.WebSocketContainer in project wildfly by wildfly.

the class WebSocketTestCase method assertWebSocket.

private void assertWebSocket(URL webapp) throws InterruptedException, IOException, DeploymentException, URISyntaxException {
    AnnotatedClient endpoint = new AnnotatedClient();
    WebSocketContainer serverContainer = ContainerProvider.getWebSocketContainer();
    try (Session session = serverContainer.connectToServer(endpoint, new URI("ws", "", TestSuiteEnvironment.getServerAddress(), TestSuiteEnvironment.getHttpPort(), webapp.getPath() + "websocket/Stuart", "", ""))) {
        Assert.assertEquals("Hello Stuart", endpoint.getMessage());
    }
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) URI(java.net.URI) Session(javax.websocket.Session)

Example 35 with WebSocketContainer

use of javax.websocket.WebSocketContainer in project undertow by undertow-io.

the class UndertowContainerProvider method getContainer.

@Override
protected WebSocketContainer getContainer() {
    ClassLoader tccl;
    if (System.getSecurityManager() == null) {
        tccl = Thread.currentThread().getContextClassLoader();
    } else {
        tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

            @Override
            public ClassLoader run() {
                return Thread.currentThread().getContextClassLoader();
            }
        });
    }
    WebSocketContainer webSocketContainer = webSocketContainers.get(tccl);
    if (webSocketContainer == null) {
        return getDefaultContainer();
    }
    return webSocketContainer;
}
Also used : WebSocketContainer(javax.websocket.WebSocketContainer) PrivilegedAction(java.security.PrivilegedAction)

Aggregations

WebSocketContainer (javax.websocket.WebSocketContainer)68 URI (java.net.URI)47 Session (javax.websocket.Session)43 Test (org.junit.Test)40 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 CountDownLatch (java.util.concurrent.CountDownLatch)13 ServerEndpoint (javax.websocket.server.ServerEndpoint)13 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