@Override public void setResponseListener(ClientCallback<ClientExchange> responseListener) { this.responseListener = responseListener; if(failedReason != null) { responseListener.failed(failedReason); } }
void invokeReadReadyCallback(final ClientExchange result) { if(readyCallback != null) { readyCallback.completed(result); readyCallback = null; } } }
void failed(final IOException e) { failedReason = e; if(responseListener != null) { responseListener.failed(e); } }
void setResponse(ClientResponse response) { this.response = response; if (responseCallback != null) { this.responseCallback.completed(this); } }
void invokeReadReadyCallback() { if(readyCallback != null) { readyCallback.completed(this); readyCallback = null; } } }
private void handleConnected(final StreamConnection connection, final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, URI uri) { boolean h2 = options.get(UndertowOptions.ENABLE_HTTP2, false); if(connection instanceof SslConnection && (h2)) { List<ALPNClientSelector.ALPNProtocol> protocolList = new ArrayList<>(); if(h2) { protocolList.add(Http2ClientProvider.alpnProtocol(listener, uri, bufferPool, options)); } ALPNClientSelector.runAlpn((SslConnection) connection, new ChannelListener<SslConnection>() { @Override public void handleEvent(SslConnection connection) { listener.completed(new HttpClientConnection(connection, options, bufferPool)); } }, listener, protocolList.toArray(new ALPNClientSelector.ALPNProtocol[protocolList.size()])); } else { if(connection instanceof SslConnection) { try { ((SslConnection) connection).startHandshake(); } catch (Throwable t) { listener.failed((t instanceof IOException) ? (IOException) t : new IOException(t)); } } listener.completed(new HttpClientConnection(connection, options, bufferPool)); } } }
void setResponse(ClientResponse response) { this.response = response; if (responseCallback != null) { this.responseCallback.completed(this); } }
return; listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false)); } catch (Throwable t) { IOException e = t instanceof IOException ? (IOException) t : new IOException(t); listener.failed(e);
@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) { final URI upgradeUri; try { upgradeUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { listener.failed(new IOException(e)); return; } Map<String, String> headers = createHeaders(options, bufferPool, uri); HttpUpgrade.performUpgrade(worker, bindAddress, upgradeUri, headers, new Http2ClearOpenListener(bufferPool, options, listener, uri.getHost()), null, options, null).addNotifier(new FailedNotifier(listener), null); }
void responseReady(Http2StreamSourceChannel result) { this.response = result; ClientResponse clientResponse = createResponse(result); this.clientResponse = clientResponse; if (responseListener != null) { responseListener.completed(this); } }
@Override public void sendRequest(ClientRequest request, ClientCallback<ClientExchange> clientCallback) { if(!http2Channel.isOpen()) { clientCallback.failed(new ClosedChannelException()); return; } catch (Throwable t) { IOException e = t instanceof IOException ? (IOException) t : new IOException(t); clientCallback.failed(e); return; clientCallback.completed(exchange);
@Override public void notify(IoFuture<? extends StreamConnection> ioFuture, Object attachment) { if (ioFuture.getStatus() == IoFuture.Status.FAILED) { listener.failed(ioFuture.getException()); } } }
@Override public void handleEvent(StreamConnection channel) { final ClientStatisticsImpl clientStatistics; //first we set up statistics, if required if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) { clientStatistics = new ClientStatisticsImpl(); channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), new ByteActivityCallback() { @Override public void activity(long bytes) { clientStatistics.written += bytes; } })); channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), new ByteActivityCallback() { @Override public void activity(long bytes) { clientStatistics.read += bytes; } })); } else { clientStatistics = null; } Http2Channel http2Channel = new Http2Channel(channel, null, bufferPool, null, true, true, options); Http2ClientConnection http2ClientConnection = new Http2ClientConnection(http2Channel, true, defaultHost, clientStatistics, false); listener.completed(http2ClientConnection); } }
@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); } }
private void handleConnected(StreamConnection connection, ClientCallback<ClientConnection> listener, URI uri, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) { final ClientStatisticsImpl clientStatistics; //first we set up statistics, if required if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) { clientStatistics = new ClientStatisticsImpl(); connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() { @Override public void activity(long bytes) { clientStatistics.written += bytes; } })); connection.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(connection.getSourceChannel().getConduit(), new ByteActivityCallback() { @Override public void activity(long bytes) { clientStatistics.read += bytes; } })); } else { clientStatistics = null; } listener.completed(new AjpClientConnection(new AjpClientChannel(connection, bufferPool, options), options, bufferPool, clientStatistics)); }