this.grizzlyClient = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(asyncClientConfig), asyncClientConfig);
@SuppressWarnings({"unchecked"}) void execute(final HttpTransactionContext transactionCtx) throws IOException { try { transactionCtx.getConnection().write(transactionCtx, createWriteCompletionHandler(transactionCtx.future)); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else if (e instanceof IOException) { throw (IOException) e; } if (LOGGER.isWarnEnabled()) { LOGGER.warn(e.toString(), e); } } }
@Override public void completed(final Connection c) { try { final HttpTransactionContext tx = HttpTransactionContext.startTransaction(c, GrizzlyAsyncHttpProvider.this, request, future); if (future.setHttpTransactionCtx(tx)) { execute(tx); } else { // GrizzlyResponseFuture has been already completed (canceled?) tx.closeConnection(); } } catch (Exception e) { if (e instanceof RuntimeException) { failed(e); } else if (e instanceof IOException) { failed(e); } if (LOGGER.isWarnEnabled()) { LOGGER.warn(e.toString(), e); } } }
} else { final ConnectionManager m = provider.getConnectionManager(); c = m.openSync(nextRequest); provider.execute(newContext); } catch (IOException ioe) { newContext.abort(ioe);
provider.getClientConfig().getResponseFilters(); final GrizzlyResponseHeaders responseHeaders = new GrizzlyResponseHeaders((HttpResponsePacket) httpHeader); try { final GrizzlyResponseFuture responseFuture = context.future; final ConnectionManager m = context.provider.getConnectionManager(); final Connection c = m.openSync(newRequest); provider.execute(newContext); } catch (IOException ioe) { newContext.abort(ioe); WebSocketHolder.set(ctx.getConnection(), context.protocolHandler, ws); ((WebSocketUpgradeHandler) context.getAsyncHandler()).onSuccess(context.webSocket); final int wsTimeout = provider.getClientConfig().getWebSocketTimeout(); IdleTimeoutFilter.setCustomTimeout(ctx.getConnection(), (wsTimeout <= 0) ? IdleTimeoutFilter.FOREVER : wsTimeout,
void touchConnection() { provider.touchConnection(connection, ahcRequest); }
private static boolean configSendFileSupport() { return !((System.getProperty("os.name").equalsIgnoreCase("linux") && !linuxSendFileSupported()) || System.getProperty("os.name").equalsIgnoreCase("HP-UX")); }
public void onTimeout(Connection connection) { timeout(connection); } });
public GrizzlyAsyncHttpProvider(final AsyncHttpClientConfig clientConfig) { this.clientConfig = clientConfig; this.providerConfig = clientConfig.getAsyncHttpProviderConfig() instanceof GrizzlyAsyncHttpProviderConfig ? (GrizzlyAsyncHttpProviderConfig) clientConfig.getAsyncHttpProviderConfig() : new GrizzlyAsyncHttpProviderConfig(); final TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance(); clientTransport = builder.build(); initializeTransport(clientConfig); connectionManager = new ConnectionManager(this, clientTransport, providerConfig); try { clientTransport.start(); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
customizer.customize(clientTransport, fcb); } else { doDefaultTransportConfig();
} else { final ConnectionManager m = provider.getConnectionManager(); c = m.openSync(req); provider.execute(newContext); } catch (IOException ioe) { newContext.abort(ioe);
provider.getClientConfig().getResponseFilters(); final GrizzlyResponseHeaders responseHeaders = new GrizzlyResponseHeaders((HttpResponsePacket) httpHeader); try { final GrizzlyResponseFuture responseFuture = context.future; final ConnectionManager m = context.provider.getConnectionManager(); final Connection c = m.openSync(newRequest); provider.execute(newContext); } catch (IOException ioe) { newContext.abort(ioe); WebSocketHolder.set(ctx.getConnection(), context.protocolHandler, ws); ((WebSocketUpgradeHandler) context.getAsyncHandler()).onSuccess(context.webSocket); final int wsTimeout = provider.getClientConfig().getWebSocketTimeout(); IdleTimeoutFilter.setCustomTimeout(ctx.getConnection(), (wsTimeout <= 0) ? IdleTimeoutFilter.FOREVER : wsTimeout,
void touchConnection() { provider.touchConnection(connection, ahcRequest); }
private static boolean configSendFileSupport() { return !((System.getProperty("os.name").equalsIgnoreCase("linux") && !linuxSendFileSupported()) || System.getProperty("os.name").equalsIgnoreCase("HP-UX")); }
public void onTimeout(Connection connection) { timeout(connection); } });
public GrizzlyAsyncHttpProvider(final AsyncHttpClientConfig clientConfig) { this.clientConfig = clientConfig; this.providerConfig = clientConfig.getAsyncHttpProviderConfig() instanceof GrizzlyAsyncHttpProviderConfig ? (GrizzlyAsyncHttpProviderConfig) clientConfig.getAsyncHttpProviderConfig() : new GrizzlyAsyncHttpProviderConfig(); final TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance(); clientTransport = builder.build(); initializeTransport(clientConfig); connectionManager = new ConnectionManager(this, clientTransport, providerConfig); try { clientTransport.start(); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
customizer.customize(clientTransport, fcb); } else { doDefaultTransportConfig();
public static void main(String[] args) { SecureRandom secureRandom = new SecureRandom(); SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, null, secureRandom); } catch (Exception e) { e.printStackTrace(); } AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder() .setConnectTimeout(5000) .setSSLContext(sslContext).build(); AsyncHttpClient client = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config); long start = System.currentTimeMillis(); try { client.executeRequest(client.prepareGet("http://www.google.com").build()).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } LOGGER.debug("COMPLETE: " + (System.currentTimeMillis() - start) + "ms"); } }
} else { final ConnectionManager m = provider.getConnectionManager(); c = m.openSync(req); provider.execute(newContext); } catch (IOException ioe) { newContext.abort(ioe);
provider.getClientConfig().getResponseFilters(); final GrizzlyResponseHeaders responseHeaders = new GrizzlyResponseHeaders((HttpResponsePacket) httpHeader); try { final GrizzlyResponseFuture responseFuture = context.future; final ConnectionManager m = context.provider.getConnectionManager(); final Connection c = m.openSync(newRequest); provider.execute(newContext); } catch (IOException ioe) { newContext.abort(ioe); WebSocketHolder.set(ctx.getConnection(), context.protocolHandler, ws); ((WebSocketUpgradeHandler) context.getAsyncHandler()).onSuccess(context.webSocket); final int wsTimeout = provider.getClientConfig().getWebSocketTimeout(); IdleTimeoutFilter.setCustomTimeout(ctx.getConnection(), (wsTimeout <= 0) ? IdleTimeoutFilter.FOREVER : wsTimeout,