Java Code Examples for org.apache.http.client.config.RequestConfig#copy()

The following examples show how to use org.apache.http.client.config.RequestConfig#copy() . These examples are extracted from open source projects. 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
private RequestConfig mergeRequestConfig(RequestConfig defaultRequestConfig) {
	if (this.requestConfig == null) {  // nothing to merge
		return defaultRequestConfig;
	}

	RequestConfig.Builder builder = RequestConfig.copy(defaultRequestConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 2
/**
 * Merge the given {@link HttpClient}-level {@link RequestConfig} with
 * the factory-level {@link RequestConfig}, if necessary.
 * @param clientConfig the config held by the current
 * @return the merged request config
 * @since 4.2
 */
protected RequestConfig mergeRequestConfig(RequestConfig clientConfig) {
	if (this.requestConfig == null) {  // nothing to merge
		return clientConfig;
	}

	RequestConfig.Builder builder = RequestConfig.copy(clientConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 3
private RequestConfig mergeRequestConfig(RequestConfig defaultRequestConfig) {
	if (this.requestConfig == null) {  // nothing to merge
		return defaultRequestConfig;
	}

	RequestConfig.Builder builder = RequestConfig.copy(defaultRequestConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 4
/**
 * Merge the given {@link HttpClient}-level {@link RequestConfig} with
 * the factory-level {@link RequestConfig}, if necessary.
 * @param clientConfig the config held by the current
 * @return the merged request config
 * @since 4.2
 */
protected RequestConfig mergeRequestConfig(RequestConfig clientConfig) {
	if (this.requestConfig == null) {  // nothing to merge
		return clientConfig;
	}

	RequestConfig.Builder builder = RequestConfig.copy(clientConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 5
/**
 * Merge the given {@link HttpClient}-level {@link RequestConfig} with
 * the factory-level {@link RequestConfig}, if necessary.
 * @param clientConfig the config held by the current
 * @return the merged request config
 * @since 4.2
 */
protected RequestConfig mergeRequestConfig(RequestConfig clientConfig) {
	if (this.requestConfig == null) {  // nothing to merge
		return clientConfig;
	}

	RequestConfig.Builder builder = RequestConfig.copy(clientConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 6
private RequestConfig mergeRequestConfig(RequestConfig defaultRequestConfig) {
	if (this.requestConfig == null) { // nothing to merge
		return defaultRequestConfig;
	}
	RequestConfig.Builder builder = RequestConfig.copy(defaultRequestConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 7
/**
 * Merge the given {@link HttpClient}-level {@link RequestConfig} with
 * the factory-level {@link RequestConfig}, if necessary.
 * @param clientConfig the config held by the current
 * @return the merged request config
 * (may be {@code null} if the given client config is {@code null})
 * @since 4.2
 */
protected RequestConfig mergeRequestConfig(RequestConfig clientConfig) {
	if (this.requestConfig == null) {  // nothing to merge
		return clientConfig;
	}

	RequestConfig.Builder builder = RequestConfig.copy(clientConfig);
	int connectTimeout = this.requestConfig.getConnectTimeout();
	if (connectTimeout >= 0) {
		builder.setConnectTimeout(connectTimeout);
	}
	int connectionRequestTimeout = this.requestConfig.getConnectionRequestTimeout();
	if (connectionRequestTimeout >= 0) {
		builder.setConnectionRequestTimeout(connectionRequestTimeout);
	}
	int socketTimeout = this.requestConfig.getSocketTimeout();
	if (socketTimeout >= 0) {
		builder.setSocketTimeout(socketTimeout);
	}
	return builder.build();
}
 
Example 8
Source Project: utils   File: HttpClient.java    License: Apache License 2.0 6 votes vote down vote up
private HttpResponse sendRequest(org.apache.http.client.HttpClient httpClient, HttpRequestBase request) {
    HttpResponse response = null;

    RequestConfig.Builder build = RequestConfig.copy(config);
    if (0 != soTimeout) {
        build.setSocketTimeout(soTimeout);
    }
    if (0 != connectTimeout) {
        build.setConnectTimeout(connectTimeout);
    }
    if (!CollectionUtils.isBlank(proxies)) {
        build.setProxy(RandomUtils.random(proxies));
    }
    request.setConfig(build.build());

    try {
        response = httpClient.execute(request);
    } catch (Exception e) {
        return response;
    }

    return response;
}
 
Example 9
Source Project: beam-client-java   File: MixerHttpClient.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a {@link org.apache.http.HttpRequest} given a type, path, and optional content.
 *
 * @param requestType The type of HTTP/1.1 request to make (see {@link RequestType}
 *                    for more details.
 * @param uri The URI to request content from.
 * @param args The content of the request.  This parameter is optional and considered to be nullable.
 *
 * @return A request built from the specification above.
 */
private HttpUriRequest makeRequest(RequestType requestType, URI uri, Object... args) {
    RequestConfig.Builder config = RequestConfig.copy(RequestConfig.DEFAULT);
    config.setCookieSpec(CookieSpecs.BEST_MATCH);

    RequestBuilder requestBuilder = RequestBuilder.create(requestType.name())
                         .setUri(uri)
                         .setConfig(config.build())
                         .setEntity(this.makeEntity(args))
                         .setHeader("User-Agent", this.getUserAgent());

    if (this.oauthToken != null) {
        requestBuilder.addHeader("Authorization", "Bearer " + this.oauthToken);
    }
    if (this.jwt != null) {
        requestBuilder.addHeader("Authorization", "JWT " + this.jwtString);
    }

    if (this.oauthToken == null && this.jwt == null) {
        requestBuilder.addHeader("Client-Id", clientId);
    }
    if (this.csrfToken != null) {
        requestBuilder.addHeader(CSRF_TOKEN_HEADER, this.csrfToken);
    }

    return requestBuilder.build();
}
 
Example 10
public HttpClientPlan() {
  this.client = HttpClientBuilder.create();
  this.connection = ConnectionConfig.copy(ConnectionConfig.DEFAULT);
  this.socket = SocketConfig.copy(SocketConfig.DEFAULT);
  this.request = RequestConfig.copy(RequestConfig.DEFAULT);
  this.headers = new HashMap<>();
  this.attributes = new HashMap<>();
}
 
Example 11
Source Project: joynr   File: LongPollChannel.java    License: Apache License 2.0 5 votes vote down vote up
public void setChannelUrl(String channelUrl) {
    this.httpget = httpRequestFactory.createHttpGet(URI.create(channelUrl));
    Builder requestConfigBuilder = RequestConfig.copy(defaultRequestConfig);
    httpget.setConfig(requestConfigBuilder.build());
    httpget.setHeader(httpConstants.getHEADER_X_ATMOSPHERE_TRACKING_ID(), receiverId);
    if (channelUrl.length() > 15) {
        this.id = "..." + channelUrl.substring(channelUrl.length() - 15);
    } else {
        this.id = channelUrl;
    }

}
 
Example 12
Source Project: vespa   File: ConfigServerApiImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static Optional<RequestConfig> getRequestConfigOverride(Params paramsOrNull) {
    if (paramsOrNull == null) return Optional.empty();

    RequestConfig.Builder builder = RequestConfig.copy(DEFAULT_REQUEST_CONFIG);

    paramsOrNull.getConnectionTimeout().ifPresent(connectionTimeout -> {
        builder.setConnectTimeout((int) connectionTimeout.toMillis());
        builder.setSocketTimeout((int) connectionTimeout.toMillis());
    });

    return Optional.of(builder.build());
}
 
Example 13
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 14
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 15
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 16
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 17
/**
 * Return a builder for modifying the factory-level {@link RequestConfig}.
 * @since 4.2
 */
private RequestConfig.Builder requestConfigBuilder() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 18
/**
 * Return a builder for modifying the factory-level {@link RequestConfig}.
 * @since 4.2
 */
private RequestConfig.Builder requestConfigBuilder() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 19
/**
 * Return a builder for modifying the factory-level {@link RequestConfig}.
 * @since 4.2
 */
private RequestConfig.Builder requestConfigBuilder() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 20
/**
 * Return a builder for modifying the factory-level {@link RequestConfig}.
 * @since 4.2
 */
private RequestConfig.Builder requestConfigBuilder() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}