Search in sources :

Example 1 with UpgradeListener

use of org.eclipse.jetty.websocket.client.io.UpgradeListener in project jetty.project by eclipse.

the class ClientContainer method connect.

private Session connect(EndpointInstance instance, URI path) throws IOException {
    Objects.requireNonNull(instance, "EndpointInstance cannot be null");
    Objects.requireNonNull(path, "Path cannot be null");
    ClientEndpointConfig config = (ClientEndpointConfig) instance.getConfig();
    ClientUpgradeRequest req = new ClientUpgradeRequest();
    UpgradeListener upgradeListener = null;
    for (Extension ext : config.getExtensions()) {
        req.addExtensions(new JsrExtensionConfig(ext));
    }
    if (config.getPreferredSubprotocols().size() > 0) {
        req.setSubProtocols(config.getPreferredSubprotocols());
    }
    if (config.getConfigurator() != null) {
        upgradeListener = new JsrUpgradeListener(config.getConfigurator());
    }
    Future<org.eclipse.jetty.websocket.api.Session> futSess = client.connect(instance, path, req, upgradeListener);
    try {
        return (JsrSession) futSess.get();
    } catch (InterruptedException e) {
        throw new IOException("Connect failure", e);
    } catch (ExecutionException e) {
        // Unwrap Actual Cause
        Throwable cause = e.getCause();
        if (cause instanceof IOException) {
            // Just rethrow
            throw (IOException) cause;
        } else {
            throw new IOException("Connect failure", cause);
        }
    }
}
Also used : IOException(java.io.IOException) Extension(javax.websocket.Extension) UpgradeListener(org.eclipse.jetty.websocket.client.io.UpgradeListener) EmptyClientEndpointConfig(org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig) ClientEndpointConfig(javax.websocket.ClientEndpointConfig) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) ExecutionException(java.util.concurrent.ExecutionException) WebSocketSession(org.eclipse.jetty.websocket.common.WebSocketSession) Session(javax.websocket.Session)

Aggregations

IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)1 Extension (javax.websocket.Extension)1 Session (javax.websocket.Session)1 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)1 UpgradeListener (org.eclipse.jetty.websocket.client.io.UpgradeListener)1 WebSocketSession (org.eclipse.jetty.websocket.common.WebSocketSession)1 EmptyClientEndpointConfig (org.eclipse.jetty.websocket.jsr356.client.EmptyClientEndpointConfig)1