io.undertow.client.ClientCallback Java Examples

The following examples show how to use io.undertow.client.ClientCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: lams   Author: lamsfoundation   File: AjpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: AjpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress,final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
Example #3
Source Project: lams   Author: lamsfoundation   File: HttpClientConnection.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) {
    if(http2Delegate != null) {
        http2Delegate.sendRequest(request, clientCallback);
        return;
    }
    if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) {
        clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
        return;
    }
    final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this);
    boolean ssl = this.connection instanceof SslConnection;
    if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {
        //this is the first request, as we want to try a HTTP2 upgrade
        request.getRequestHeaders().put(new HttpString("HTTP2-Settings"), Http2ClearClientProvider.createSettingsFrame(options, bufferPool));
        request.getRequestHeaders().put(Headers.UPGRADE, Http2Channel.CLEARTEXT_UPGRADE_STRING);
        request.getRequestHeaders().put(Headers.CONNECTION, "Upgrade, HTTP2-Settings");
        http2Tried = true;
    }

    if (currentRequest == null) {
        initiateRequest(httpClientExchange);
    } else {
        pendingQueue.add(httpClientExchange);
    }
}
 
Example #4
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals("https")) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #5
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioIoThread ioThread, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals("https")) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #6
Source Project: light-4j   Author: networknt   File: Light4jHttpClientProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals(HTTPS)) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #7
Source Project: light-4j   Author: networknt   File: Light4jHttpClientProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioIoThread ioThread, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals(HTTPS)) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #8
Source Project: spring-analysis-note   Author: Vip-Augus   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap);
}
 
Example #9
Source Project: java-technology-stack   Author: codeEngraver   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap);
}
 
Example #10
Source Project: lams   Author: lamsfoundation   File: AjpClientConnection.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) {
    if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) {
        clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
        return;
    }
    final AjpClientExchange AjpClientExchange = new AjpClientExchange(clientCallback, request, this);
    if (currentRequest == null) {
        initiateRequest(AjpClientExchange);
    } else {
        pendingQueue.add(AjpClientExchange);
    }
}
 
Example #11
Source Project: lams   Author: lamsfoundation   File: AjpClientExchange.java    License: GNU General Public License v2.0 5 votes vote down vote up
AjpClientExchange(ClientCallback<ClientExchange> readyCallback, ClientRequest request, AjpClientConnection clientConnection) {
    this.readyCallback = readyCallback;
    this.request = request;
    this.clientConnection = clientConnection;
    boolean reqContinue = false;
    if (request.getRequestHeaders().contains(Headers.EXPECT)) {
        for (String header : request.getRequestHeaders().get(Headers.EXPECT)) {
            if (header.equals("100-continue")) {
                reqContinue = true;
            }
        }
    }
    this.requiresContinue = reqContinue;
}
 
Example #12
Source Project: lams   Author: lamsfoundation   File: AjpClientExchange.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setResponseListener(ClientCallback<ClientExchange> listener) {
    this.responseCallback = listener;
    if (listener != null) {
        if (failedReason != null) {
            listener.failed(failedReason);
        } else if (response != null) {
            listener.completed(this);
        }
    }
}
 
Example #13
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {

    if (bindAddress == null) {
        worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), options).addNotifier(createNotifier(listener), null);
    } else {
        worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), null, options).addNotifier(createNotifier(listener), null);
    }}
 
Example #14
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, final InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {

    if (bindAddress == null) {
        ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), options).addNotifier(createNotifier(listener), null);
    } else {
        ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), null, options).addNotifier(createNotifier(listener), null);
    }
}
 
Example #15
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final String defaultHost) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, defaultHost);
        }
    };
}
 
Example #17
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    if (ssl == null) {
        listener.failed(UndertowMessages.MESSAGES.sslWasNull());
        return;
    }
    OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
    if(bindAddress == null) {
        ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), tlsOptions).addNotifier(createNotifier(listener), null);
    } else {
        ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), tlsOptions).addNotifier(createNotifier(listener), null);
    }

}
 
Example #18
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    if (ssl == null) {
        listener.failed(UndertowMessages.MESSAGES.sslWasNull());
        return;
    }
    if(bindAddress == null) {
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), options).addNotifier(createNotifier(listener), null);
    } else {
        ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, options), options).addNotifier(createNotifier(listener), null);
    }

}
 
Example #19
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #20
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final URI uri, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, bufferPool, options);
        }
    };
}
 
Example #21
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ALPNClientSelector.ALPNProtocol alpnProtocol(final ClientCallback<ClientConnection> listener, URI uri, ByteBufferPool bufferPool, OptionMap options) {
    return new ALPNClientSelector.ALPNProtocol(new ChannelListener<SslConnection>() {
        @Override
        public void handleEvent(SslConnection connection) {
            listener.completed(createHttp2Channel(connection, bufferPool, options, uri.getHost()));
        }
    }, HTTP2);
}
 
Example #22
Source Project: lams   Author: lamsfoundation   File: Http2ClientExchange.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setResponseListener(ClientCallback<ClientExchange> responseListener) {
    this.responseListener = responseListener;
    if(failedReason != null) {
        responseListener.failed(failedReason);
    }
}
 
Example #23
Source Project: lams   Author: lamsfoundation   File: Http2ClientConnection.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Http2ClientConnection(Http2Channel http2Channel, ClientCallback<ClientExchange> upgradeReadyCallback, ClientRequest clientRequest, String defaultHost, ClientStatistics clientStatistics, boolean secure) {

        this.http2Channel = http2Channel;
        this.defaultHost = defaultHost;
        this.clientStatistics = clientStatistics;
        this.secure = secure;
        http2Channel.getReceiveSetter().set(new Http2ReceiveListener());
        http2Channel.resumeReceives();
        http2Channel.addCloseTask(closeTask);
        this.initialUpgradeRequest = false;

        Http2ClientExchange exchange = new Http2ClientExchange(this, null, clientRequest);
        exchange.setResponseListener(upgradeReadyCallback);
        currentExchanges.put(1, exchange);
    }
 
Example #24
Source Project: lams   Author: lamsfoundation   File: HttpClientExchange.java    License: GNU General Public License v2.0 5 votes vote down vote up
HttpClientExchange(ClientCallback<ClientExchange> readyCallback, ClientRequest request, HttpClientConnection clientConnection) {
    this.readyCallback = readyCallback;
    this.request = request;
    this.clientConnection = clientConnection;
    boolean reqContinue = false;
    if (request.getRequestHeaders().contains(Headers.EXPECT)) {
        for (String header : request.getRequestHeaders().get(Headers.EXPECT)) {
            if (header.equals("100-continue")) {
                reqContinue = true;
            }
        }
    }
    this.requiresContinue = reqContinue;
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: HttpClientExchange.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setResponseListener(ClientCallback<ClientExchange> listener) {
    this.responseCallback = listener;
    if (listener != null) {
        if (failedReason != null) {
            listener.failed(failedReason);
        } else if (response != null) {
            listener.completed(this);
        }
    }
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #27
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final URI uri) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, uri);
        }
    };
}
 
Example #28
Source Project: lams   Author: lamsfoundation   File: ProxyConnectionPool.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void openConnection(final HttpServerExchange exchange, final ProxyCallback<ProxyConnection> callback, final HostThreadData data, final boolean exclusive) {
    if (!exclusive) {
        data.connections++;
    }
    client.connect(new ClientCallback<ClientConnection>() {
        @Override
        public void completed(final ClientConnection result) {
            openConnections.incrementAndGet();
            final ConnectionHolder connectionHolder = new ConnectionHolder(result);
            if (!exclusive) {
                result.getCloseSetter().set(new ChannelListener<ClientConnection>() {
                    @Override
                    public void handleEvent(ClientConnection channel) {
                        handleClosedConnection(data, connectionHolder);
                    }
                });
            }
            connectionReady(connectionHolder, callback, exchange, exclusive);
        }

        @Override
        public void failed(IOException e) {
            if (!exclusive) {
                data.connections--;
            }
            UndertowLogger.REQUEST_LOGGER.debug("Failed to connect", e);
            if (!connectionPoolManager.handleError()) {
                redistributeQueued(getData());
                scheduleFailedHostRetry(exchange);
            }
            callback.failed(exchange);
        }
    }, bindAddress, getUri(), exchange.getIoThread(), ssl, exchange.getConnection().getByteBufferPool(), options);
}
 
Example #29
Source Project: light-4j   Author: networknt   File: Light4jHttpClientProvider.java    License: Apache License 2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #30
Source Project: light-4j   Author: networknt   File: Light4jHttpClientProvider.java    License: Apache License 2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final URI uri) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, uri);
        }
    };
}