Java Code Examples for org.eclipse.jetty.client.HttpClient#setIdleTimeout()

The following examples show how to use org.eclipse.jetty.client.HttpClient#setIdleTimeout() . 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 File: InjectionModule.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ServiceImpersonatorLoadBalancer.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
private HttpClient createHttpClient() {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setExcludeCipherSuites("");
    HttpClient client = new HttpClient(sslContextFactory);
    client.setFollowRedirects(false);
    client.setMaxConnectionsPerDestination(2);
    //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;
}
 
Example 3
Source File: TestInjectionModule.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source File: HttpRpcEndpoint.java    From nutzcloud with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    client = new HttpClient(new SslContextFactory(true));
    client.setFollowRedirects(false);
    client.setCookieStore(new HttpCookieStore.Empty());

    executor = new QueuedThreadPool(conf.getInt(PRE + ".maxThreads", 256));
    client.setExecutor(executor);
    client.setMaxConnectionsPerDestination(conf.getInt(PRE + ".maxConnections", 256));
    client.setIdleTimeout(conf.getLong(PRE + ".idleTimeout", 30000));

    client.setConnectTimeout(conf.getLong(PRE + ".connectTime", 1000));

    if (conf.has(PRE + "requestBufferSize"))
        client.setRequestBufferSize(conf.getInt(PRE + "requestBufferSize"));

    if (conf.has(PRE + "responseBufferSize"))
        client.setResponseBufferSize(conf.getInt(PRE + "responseBufferSize"));

    client.start();

    // Content must not be decoded, otherwise the client gets confused.
    client.getContentDecoderFactories().clear();

    // Pass traffic to the client, only intercept what's necessary.
    ProtocolHandlers protocolHandlers = client.getProtocolHandlers();
    protocolHandlers.clear();
}
 
Example 5
Source File: RestBufferManager.java    From incubator-retired-htrace with Apache License 2.0 5 votes vote down vote up
/**
 * Create an HttpClient instance.
 *
 * @param connTimeout         The timeout to use for connecting.
 * @param idleTimeout         The idle timeout to use.
 */
static HttpClient createHttpClient(long connTimeout, long idleTimeout) {
  HttpClient httpClient = new HttpClient();
  httpClient.setUserAgentField(
      new HttpField(HttpHeader.USER_AGENT, "HTracedSpanReceiver"));
  httpClient.setConnectTimeout(connTimeout);
  httpClient.setIdleTimeout(idleTimeout);
  return httpClient;
}
 
Example 6
Source File: ForceStreamConsumer.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private BayeuxClient makeClient() throws Exception {
  httpClient = new HttpClient(ForceUtils.makeSslContextFactory(conf));
  httpClient.setConnectTimeout(CONNECTION_TIMEOUT);
  httpClient.setIdleTimeout(READ_TIMEOUT);
  if (conf.useProxy) {
    ForceUtils.setProxy(httpClient, conf);
  }
  httpClient.start();

  final String sessionid = connection.getConfig().getSessionId();
  String soapEndpoint = connection.getConfig().getServiceEndpoint();
  String endpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("/services/Soap/"));
  LOG.info("Server URL: {} ", endpoint);
  LOG.info("Session ID: {}", sessionid);

  Map<String, Object> options = new HashMap<>();
  options.put(ClientTransport.MAX_NETWORK_DELAY_OPTION, READ_TIMEOUT);
  options.put(LongPollingTransport.MAX_BUFFER_SIZE_OPTION, conf.streamingBufferSize);
  LongPollingTransport transport = new LongPollingTransport(options, httpClient) {

    @Override
    protected void customize(Request request) {
      super.customize(request);
      request.header(HttpHeader.AUTHORIZATION, "OAuth " + sessionid);
    }
  };

  String streamingEndpoint = salesforceStreamingEndpoint(endpoint);

  LOG.info("Streaming Endpoint: {}", streamingEndpoint);

  return new BayeuxClient(streamingEndpoint, transport);
}