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() . 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: HttpComponentsHttpInvokerRequestExecutor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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
Source File: HttpClient.java    From utils with 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 3
Source File: HttpComponentsClientHttpRequestFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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 4
Source File: HttpComponentsClientHttpRequestFactory.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: HttpComponentsHttpInvokerRequestExecutor.java    From java-technology-stack with MIT License 6 votes vote down vote up
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 6
Source File: HttpComponentsHttpInvokerRequestExecutor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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
Source File: HttpComponentsClientHttpRequestFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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 8
Source File: HttpComponentsClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 9
Source File: ConfigServerApiImpl.java    From vespa with 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 10
Source File: LongPollChannel.java    From joynr with 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 11
Source File: HttpClientPlan.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
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 12
Source File: MixerHttpClient.java    From beam-client-java with 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 13
Source File: HttpComponentsHttpInvokerRequestExecutor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 14
Source File: HttpComponentsHttpInvokerRequestExecutor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 15
Source File: HttpComponentsHttpInvokerRequestExecutor.java    From java-technology-stack with MIT License 4 votes vote down vote up
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 16
Source File: HttpComponentsHttpInvokerRequestExecutor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private RequestConfig.Builder cloneRequestConfig() {
	return (this.requestConfig != null ? RequestConfig.copy(this.requestConfig) : RequestConfig.custom());
}
 
Example 17
Source File: HttpComponentsClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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
Source File: HttpComponentsClientHttpRequestFactory.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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
Source File: HttpComponentsClientHttpRequestFactory.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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
Source File: HttpComponentsClientHttpRequestFactory.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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());
}