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

The following examples show how to use org.eclipse.jetty.client.HttpClient#setRequestBufferSize() . 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: 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 3
Source File: HttpClientModule.java    From EDDI with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
public HttpClient provideHttpClient(ExecutorService executorService,
                                    @Named("httpClient.maxConnectionsQueued") Integer maxConnectionsQueued,
                                    @Named("httpClient.maxConnectionPerRoute") Integer maxConnectionPerRoute,
                                    @Named("httpClient.requestBufferSize") Integer requestBufferSize,
                                    @Named("httpClient.responseBufferSize") Integer responseBufferSize,
                                    @Named("httpClient.maxRedirects") Integer maxRedirects,
                                    @Named("httpClient.trustAllCertificates") Boolean trustAllCertificates) {

    try {
        SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
        sslContextFactory.setTrustAll(trustAllCertificates);
        HttpClient httpClient = new HttpClient(sslContextFactory);
        httpClient.setExecutor(executorService);
        httpClient.setMaxConnectionsPerDestination(maxConnectionsQueued);
        httpClient.setMaxRequestsQueuedPerDestination(maxConnectionPerRoute);
        httpClient.setRequestBufferSize(requestBufferSize);
        httpClient.setResponseBufferSize(responseBufferSize);
        httpClient.setMaxRedirects(maxRedirects);
        httpClient.start();

        registerHttpClientShutdownHook(httpClient);

        return httpClient;
    } catch (Exception e) {
        System.out.println(Arrays.toString(e.getStackTrace()));
        throw new RuntimeException(e.getLocalizedMessage(), e);
    }
}