org.apache.http.nio.client.HttpAsyncClient Java Examples

The following examples show how to use org.apache.http.nio.client.HttpAsyncClient. 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: HttpComponentsAsyncClientHttpRequestFactory.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	HttpAsyncClient asyncClient = getHttpAsyncClient();
	startAsyncClient();
	HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
	postProcessHttpRequest(httpRequest);
       HttpContext context = createHttpContext(httpMethod, uri);
       if (context == null) {
           context = HttpClientContext.create();
       }
	// Request configuration not set in the context
	if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
		// Use request configuration given by the user, when available
		RequestConfig config = null;
		if (httpRequest instanceof Configurable) {
			config = ((Configurable) httpRequest).getConfig();
		}
		if (config == null) {
			config = createRequestConfig(asyncClient);
		}
		if (config != null) {
			context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
		}
	}
	return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context);
}
 
Example #2
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void destroy() throws Exception {
	try {
		super.destroy();
	}
	finally {
		HttpAsyncClient asyncClient = getAsyncClient();
		if (asyncClient instanceof Closeable) {
			((Closeable) asyncClient).close();
		}
	}
}
 
Example #3
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	HttpAsyncClient client = startAsyncClient();

	HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
	postProcessHttpRequest(httpRequest);
	HttpContext context = createHttpContext(httpMethod, uri);
	if (context == null) {
		context = HttpClientContext.create();
	}

	// Request configuration not set in the context
	if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
		// Use request configuration given by the user, when available
		RequestConfig config = null;
		if (httpRequest instanceof Configurable) {
			config = ((Configurable) httpRequest).getConfig();
		}
		if (config == null) {
			config = createRequestConfig(client);
		}
		if (config != null) {
			context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
		}
	}

	return new HttpComponentsAsyncClientHttpRequest(client, httpRequest, context);
}
 
Example #4
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private HttpAsyncClient startAsyncClient() {
	HttpAsyncClient client = getAsyncClient();
	if (client instanceof CloseableHttpAsyncClient) {
		CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client;
		if (!closeableAsyncClient.isRunning()) {
			closeableAsyncClient.start();
		}
	}
	return client;
}
 
Example #5
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	HttpAsyncClient client = startAsyncClient();

	HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
	postProcessHttpRequest(httpRequest);
	HttpContext context = createHttpContext(httpMethod, uri);
	if (context == null) {
		context = HttpClientContext.create();
	}

	// Request configuration not set in the context
	if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
		// Use request configuration given by the user, when available
		RequestConfig config = null;
		if (httpRequest instanceof Configurable) {
			config = ((Configurable) httpRequest).getConfig();
		}
		if (config == null) {
			config = createRequestConfig(client);
		}
		if (config != null) {
			context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
		}
	}

	return new HttpComponentsAsyncClientHttpRequest(client, httpRequest, context);
}
 
Example #6
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void destroy() throws Exception {
	try {
		super.destroy();
	}
	finally {
		HttpAsyncClient asyncClient = getAsyncClient();
		if (asyncClient instanceof Closeable) {
			((Closeable) asyncClient).close();
		}
	}
}
 
Example #7
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
private HttpAsyncClient startAsyncClient() {
	HttpAsyncClient client = getAsyncClient();
	if (client instanceof CloseableHttpAsyncClient) {
		CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client;
		if (!closeableAsyncClient.isRunning()) {
			closeableAsyncClient.start();
		}
	}
	return client;
}
 
Example #8
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void destroy() throws Exception {
	try {
		super.destroy();
	}
	finally {
		HttpAsyncClient asyncClient = getAsyncClient();
		if (asyncClient instanceof Closeable) {
			((Closeable) asyncClient).close();
		}
	}
}
 
Example #9
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void startAsyncClient() {
       HttpAsyncClient asyncClient = getAsyncClient();
	if (asyncClient instanceof CloseableHttpAsyncClient) {
		CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) asyncClient;
		if (!closeableAsyncClient.isRunning()) {
			closeableAsyncClient.start();
		}
	}
}
 
Example #10
Source File: HttpComponentsAsyncClientHttpRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) {
	this.httpClient = client;
	this.httpRequest = request;
	this.httpContext = context;
}
 
Example #11
Source File: HttpComponentsAsyncClientHttpRequest.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) {
	this.httpClient = client;
	this.httpRequest = request;
	this.httpContext = context;
}
 
Example #12
Source File: HttpComponentsAsyncClientHttpRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) {
	this.httpClient = client;
	this.httpRequest = request;
	this.httpContext = context;
}
 
Example #13
Source File: YunpianClient.java    From yunpian-java-sdk with MIT License 4 votes vote down vote up
public HttpAsyncClient http() {
    return clnt;
}
 
Example #14
Source File: HttpComponentsAsyncClientHttpRequest.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
HttpComponentsAsyncClientHttpRequest(HttpAsyncClient httpClient, HttpUriRequest httpRequest, HttpContext httpContext) {
	this.httpClient = httpClient;
	this.httpRequest = httpRequest;
	this.httpContext = httpContext;
}
 
Example #15
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the {@code HttpAsyncClient} used for
 * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
 * @since 4.3.10
 * @see #getHttpClient()
 */
public HttpAsyncClient getAsyncClient() {
	return this.asyncClient;
}
 
Example #16
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the {@code HttpAsyncClient} used for
 * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
 * @since 4.3.10
 * @see #setHttpClient(HttpClient)
 */
public void setAsyncClient(HttpAsyncClient asyncClient) {
	Assert.notNull(asyncClient, "HttpAsyncClient must not be null");
	this.asyncClient = asyncClient;
}
 
Example #17
Source File: HttpAsyncClientImpl.java    From salt-netapi-client with MIT License 2 votes vote down vote up
/**
 * Init a connection to a given Salt API endpoint.
 *
 * @param httpClientIn the HTTP client
 */
public HttpAsyncClientImpl(HttpAsyncClient httpClientIn) {
    httpClient = httpClientIn;
}
 
Example #18
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
 * with the given {@link HttpClient} and {@link HttpAsyncClient} instances.
 * @param httpClient the HttpClient instance to use for this request factory
 * @param asyncClient the HttpAsyncClient instance to use for this request factory
 * @since 4.3.10
 */
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
	super(httpClient);
	setAsyncClient(asyncClient);
}
 
Example #19
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
 * with the given {@link HttpAsyncClient} instance and a default {@link HttpClient}.
 * @param asyncClient the HttpAsyncClient instance to use for this request factory
 * @since 4.3.10
 */
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
	super();
	setAsyncClient(asyncClient);
}
 
Example #20
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Return the {@code HttpAsyncClient} used for
 * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
 * @since 4.3.10
 * @see #getHttpClient()
 */
public HttpAsyncClient getAsyncClient() {
	return this.asyncClient;
}
 
Example #21
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Set the {@code HttpAsyncClient} used for
 * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
 * @since 4.3.10
 * @see #setHttpClient(HttpClient)
 */
public void setAsyncClient(HttpAsyncClient asyncClient) {
	Assert.notNull(asyncClient, "HttpAsyncClient must not be null");
	this.asyncClient = asyncClient;
}
 
Example #22
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
 * with the given {@link HttpClient} and {@link HttpAsyncClient} instances.
 * @param httpClient the HttpClient instance to use for this request factory
 * @param asyncClient the HttpAsyncClient instance to use for this request factory
 * @since 4.3.10
 */
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
	super(httpClient);
	this.asyncClient = asyncClient;
}
 
Example #23
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
 * with the given {@link HttpAsyncClient} instance and a default {@link HttpClient}.
 * @param asyncClient the HttpAsyncClient instance to use for this request factory
 * @since 4.3.10
 */
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
	super();
	this.asyncClient = asyncClient;
}
 
Example #24
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return the {@code HttpAsyncClient} used for
 * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
 * @since 4.3.10
 * @see #getHttpClient()
 */
public HttpAsyncClient getAsyncClient() {
	return this.asyncClient;
}
 
Example #25
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set the {@code HttpAsyncClient} used for
 * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
 * @since 4.3.10
 * @see #setHttpClient(HttpClient)
 */
public void setAsyncClient(HttpAsyncClient asyncClient) {
	Assert.notNull(asyncClient, "HttpAsyncClient must not be null");
	this.asyncClient = asyncClient;
}
 
Example #26
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
 * with the given {@link HttpClient} and {@link HttpAsyncClient} instances.
 * @param httpClient the HttpClient instance to use for this request factory
 * @param asyncClient the HttpAsyncClient instance to use for this request factory
 * @since 4.3.10
 */
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
	super(httpClient);
	this.asyncClient = asyncClient;
}
 
Example #27
Source File: HttpComponentsAsyncClientHttpRequestFactory.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
 * with the given {@link HttpAsyncClient} instance and a default {@link HttpClient}.
 * @param asyncClient the HttpAsyncClient instance to use for this request factory
 * @since 4.3.10
 */
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
	super();
	this.asyncClient = asyncClient;
}