httpClient.setMaxConnectionsPerDestination(config.getNumConnections()); httpClient.setMaxRequestsQueuedPerDestination(config.getNumRequestsQueued()); httpClient.setConnectTimeout(CLIENT_CONNECT_TIMEOUT_MILLIS); httpClient.setRequestBufferSize(config.getRequestBuffersize()); final QueuedThreadPool pool = new QueuedThreadPool(config.getNumMaxThreads());
client.setConnectTimeout((Integer) connectTimeout);
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; log.info("Starting Jetty HttpClient..."); client = new HttpClient(); // Jetty client needs threads for its internal expiration routines, which we don't need but // can't disable, so let's abuse the request executor service for this client.setThreadPool( new ExecutorThreadPool(getConfiguration().getRequestExecutorService()) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } } ); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking client.setTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setConnectTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setMaxRetries(configuration.getRequestRetryCount()); try { client.start(); } catch (Exception ex) { throw new InitializationException( "Could not start Jetty HTTP client: " + ex, ex ); } }
@Provides public HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.setFollowRedirects(false); client.setMaxConnectionsPerDestination(32); client.setConnectTimeout(100); client.setAddressResolutionTimeout(100); //You can set more restrictive timeouts per request, but not less, so // we set the maximum timeout of 1 hour here. client.setIdleTimeout(60 * 60 * 1000); try { client.start(); } catch (Exception e) { logger.error("Error building http client", e); } return client; }
private HttpClient createHttpClient() { //Allow ssl by default SslContextFactory sslContextFactory = new SslContextFactory(); //Don't exclude RSA because Sixt needs them, dammit! sslContextFactory.setExcludeCipherSuites(""); HttpClient client = new HttpClient(sslContextFactory); client.setFollowRedirects(false); client.setMaxConnectionsPerDestination(16); client.setRequestBufferSize(65536); client.setConnectTimeout(FeatureFlags.getHttpConnectTimeout(serviceProperties)); client.setAddressResolutionTimeout(FeatureFlags.getHttpAddressResolutionTimeout(serviceProperties)); //You can set more restrictive timeouts per request, but not less, so // we set the maximum timeout of 1 hour here. client.setIdleTimeout(60 * 60 * 1000); try { client.start(); } catch (Exception e) { logger.error("Error building http client", e); } return client; }
/** * Set the timeout for connecting to the remote server. * @param ms the timeout in millisecondspool * @deprecated Use {@link HttpClient#setConnectTimeout(long)} * on the instance passed to {@link #WebSocketClient(HttpClient)} */ public void setConnectTimeout(long ms) { this.httpClient.setConnectTimeout(ms); }
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; log.info("Starting Jetty HttpClient..."); client = new HttpClient(); // Jetty client needs threads for its internal expiration routines, which we don't need but // can't disable, so let's abuse the request executor service for this client.setThreadPool( new ExecutorThreadPool(getConfiguration().getRequestExecutorService()) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } } ); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking client.setTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setConnectTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setMaxRetries(configuration.getRequestRetryCount()); try { client.start(); } catch (Exception ex) { throw new InitializationException( "Could not start Jetty HTTP client: " + ex, ex ); } }
/** * Set the connect timeout value for the default HTTP client * * @deprecated set your own HTTP client using {@link #setHttpClient(HttpClient client)} */ @Deprecated public static void setHTTPClientConnectTimeout(long timeout) { _httpClient.setConnectTimeout(timeout); }
@Override public org.eclipse.jetty.client.HttpClient createAndStart() { org.eclipse.jetty.client.HttpClient client = new org.eclipse.jetty.client.HttpClient(new SslContextFactory()); client.setConnectTimeout(task.getConnectTimeoutMills()); try { client.start(); return client; } catch (Exception e) { throw Throwables.propagate(e); } } });
private static HttpClient httpClient() throws Exception { if (_httpClient == null ) { _httpClient = new HttpClient(new SslContextFactory()); _httpClient.setConnectTimeout(TIMEOUT_CONNECT); _httpClient.setFollowRedirects(false); _httpClient.setCookieStore(new HttpCookieStore.Empty()); _httpClient.start(); _ourClient = true; } return _httpClient; }
private HttpClient createClient() throws Exception { int selectors = Math.max(1, Runtime.getRuntime().availableProcessors() / 2); HttpClient client = new HttpClient(new HttpClientTransportOverHTTP(selectors), new SslContextFactory(true)); client.setFollowRedirects(false); client.setCookieStore(new HttpCookieStore.Empty()); client.setMaxConnectionsPerDestination(256); client.setAddressResolutionTimeout(15000); client.setConnectTimeout(15000); client.setIdleTimeout(idleTimeout); client.setUserAgentField(null); client.start(); client.getContentDecoderFactories().clear(); return client; }
@Override public Builder<T> options(ReactiveOptions options) { if (options.getConnectTimeoutMillis() != null) { httpClient.setConnectTimeout(options.getConnectTimeoutMillis()); } if (options.getReadTimeoutMillis() != null) { setHttpClient(httpClient, jsonFactory, objectMapper); } this.options = options; return this; }
private BayeuxClient makeClient() throws Exception { HttpClient httpClient = new HttpClient(); httpClient.setConnectTimeout(CONNECTION_TIMEOUT); httpClient.setTimeout(READ_TIMEOUT); httpClient.start(); if (sfdcSession == null) { logger.error("Invalid session !"); return null; } logger.info("Login successful!\nServer URL: " + sfdcSession.getEndPoint() + "\nSession ID=" + sfdcSession.getSessionId()); Map<String, Object> options = new HashMap<String, Object>(); options.put(ClientTransport.TIMEOUT_OPTION, READ_TIMEOUT); LongPollingTransport transport = new LongPollingTransport( options, httpClient) { @Override protected void customize(ContentExchange exchange) { super.customize(exchange); exchange.addRequestHeader("Authorization", "OAuth " + sfdcSession.getSessionId()); } }; BayeuxClient client = new BayeuxClient(getSalesforceStreamingEndpoint( sfdcSession.getEndPoint()), transport); return client; }
protected void setHttpClient(Function<Boolean, HttpClient> httpClientFactory){ this.httpClientFactory = httpClientFactory; boolean useHttp2 = ReactiveOptions.useHttp2(options); HttpClient httpClient = httpClientFactory.apply(useHttp2); if(useHttp2 && !(httpClient.getTransport() instanceof HttpClientTransportOverHTTP2)){ throw new IllegalArgumentException("HttpClient should use HttpClientTransportOverHTTP2"); } if (this.options != null && this.options.getConnectTimeoutMillis() != null) { httpClient.setConnectTimeout(options.getConnectTimeoutMillis()); } clientFactory(methodMetadata -> { JettyReactiveHttpClient jettyClient = JettyReactiveHttpClient.jettyClient(methodMetadata, httpClient, jsonFactory, objectMapper); if (options != null && options.getRequestTimeoutMillis() != null) { jettyClient = jettyClient.setRequestTimeout(options.getRequestTimeoutMillis()); } if (options != null && options.isTryUseCompression() != null) { jettyClient = jettyClient.setTryUseCompression(options.isTryUseCompression()); } return jettyClient; }); } }
@Override protected void configureClient() { boolean addSslSupport = StringUtils.isNotEmpty(metadata.getKeyStorePath()) && StringUtils.isNotEmpty(metadata.getKeyStorePassword()); if(addSslSupport){ SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(metadata.getKeyStorePath()); sslContextFactory.setKeyStorePassword(metadata.getKeyStorePassword()); boolean addTrustSupport = StringUtils.isNotEmpty(metadata.getTrustStorePath()) && StringUtils.isNotEmpty(metadata.getTrustStorePassword()); if(addTrustSupport){ sslContextFactory.setTrustStorePath(metadata.getTrustStorePath()); sslContextFactory.setTrustStorePassword(metadata.getTrustStorePassword()); }else{ sslContextFactory.setTrustAll(true); } httpClient = new HttpClient(sslContextFactory); } httpClient.setConnectTimeout(metadata.getConnectTimeout()); httpClient.setIdleTimeout(metadata.getIdleTimeout()); httpClient.setMaxConnectionsPerDestination(metadata.getMaxConnectionsPerAddress()); httpClient.setMaxRequestsQueuedPerDestination(metadata.getMaxQueueSizePerAddress()); httpClient.setFollowRedirects(followRedirects); try { httpClient.start(); } catch (Exception e) { throw new ClientException("failed to start jetty http client: " + e, e); } }
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; log.info("Starting Jetty HttpClient..."); client = new HttpClient(); // Jetty client needs threads for its internal expiration routines, which we don't need but // can't disable, so let's abuse the request executor service for this client.setThreadPool( new ExecutorThreadPool(getConfiguration().getRequestExecutorService()) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } } ); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking client.setTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setConnectTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setMaxRetries(configuration.getRequestRetryCount()); try { client.start(); } catch (Exception ex) { throw new InitializationException( "Could not start Jetty HTTP client: " + ex, ex ); } }
this.httpClient = new HttpClient(sslContextFactory); this.httpClient.setFollowRedirects(options.followRedirects); this.httpClient.setConnectTimeout(options.connectionTimeoutMillis); this.httpClient.setMaxConnectionsPerDestination(options.maxConnectionsPerDestination); this.httpClient.setCookieStore(new HttpCookieStore.Empty());
public org.eclipse.jetty.client.HttpClient createNewJettyClient() throws Exception { org.eclipse.jetty.client.HttpClient tempClient = new org.eclipse.jetty.client.HttpClient(); QueuedThreadPool btp = new QueuedThreadPool(); btp.setMaxThreads(getConfiguration().getJettyClientThreadPoolSize()); tempClient.setThreadPool(btp); tempClient.setConnectorType(org.eclipse.jetty.client.HttpClient.CONNECTOR_SELECT_CHANNEL); tempClient.setTimeout(getConfiguration().getProviderExpirationTime()); tempClient.setConnectTimeout(getConfiguration().getClientConnectTimeout()); tempClient.setMaxConnectionsPerAddress(getConfiguration().getMaxConnectionsPerAddress()); tempClient.start(); return tempClient; }
@BeforeClass public static void setupEnvironment() throws Exception { wireMockServer = new WireMockServer(ENDPOINT_PORT); wireMockServer.start(); client = new HttpClient(); client.setCookieStore(new HttpCookieStore.Empty()); client.setConnectTimeout(1000); client.setIdleTimeout(1000); client.start(); }
public HttpClient buildHttpClient() { HttpClient client = new HttpClient(); //client.setConnectBlocking(false); client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); client.setConnectTimeout(getConnectTimeoutMillis()); client.setTimeout(getReadTimeoutMillis()); client.setMaxConnectionsPerAddress(getPoolMaximumSize()); client.setThreadPool(new QueuedThreadPool(getPoolMaximumSize())); //client.setIdleTimeout(config.get???); if (getFollowRedirects()) { client.setMaxRedirects(10); } if (getAuthentication() != null) { Realm realm = new SimpleRealm("whatever", getAuthentication().getUsername(), getAuthentication().getPassword()); client.setRealmResolver(new SimpleRealmResolver(realm)); } return client; }