Browse Source
* commit '5a5fe646175659c70797be34d215dd1669386aed': REPORT-98773 fix: 编译失败 REPORT-98773 fix: fine-spring中部分未用到的类修改import包名 REPORT-98773 fix: fine-spring中部分未用到的类修改import包名feature/x
superman
1 year ago
8 changed files with 509 additions and 507 deletions
@ -1,168 +1,168 @@ |
|||||||
/* |
///*
|
||||||
* Copyright 2002-2016 the original author or authors. |
// * Copyright 2002-2016 the original author or authors.
|
||||||
* |
// *
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License. |
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at |
// * You may obtain a copy of the License at
|
||||||
* |
// *
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
// * https://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software |
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and |
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License. |
// * limitations under the License.
|
||||||
*/ |
// */
|
||||||
|
//
|
||||||
package com.fr.third.springframework.http.client; |
//package com.fr.third.springframework.http.client;
|
||||||
|
//
|
||||||
import java.io.IOException; |
//import java.io.IOException;
|
||||||
import java.net.URI; |
//import java.net.URI;
|
||||||
import java.util.concurrent.Future; |
//import java.util.concurrent.Future;
|
||||||
|
//
|
||||||
import org.apache.http.HttpEntity; |
//import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpEntityEnclosingRequest; |
//import org.apache.http.HttpEntityEnclosingRequest;
|
||||||
import org.apache.http.HttpResponse; |
//import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.methods.HttpUriRequest; |
//import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.concurrent.FutureCallback; |
//import org.apache.http.concurrent.FutureCallback;
|
||||||
import org.apache.http.nio.client.HttpAsyncClient; |
//import org.apache.http.nio.client.HttpAsyncClient;
|
||||||
import org.apache.http.nio.entity.NByteArrayEntity; |
//import org.apache.http.nio.entity.NByteArrayEntity;
|
||||||
import org.apache.http.protocol.HttpContext; |
//import org.apache.http.protocol.HttpContext;
|
||||||
|
//
|
||||||
import com.fr.third.springframework.http.HttpHeaders; |
//import com.fr.third.springframework.http.HttpHeaders;
|
||||||
import com.fr.third.springframework.http.HttpMethod; |
//import com.fr.third.springframework.http.HttpMethod;
|
||||||
import com.fr.third.springframework.util.concurrent.FailureCallback; |
//import com.fr.third.springframework.util.concurrent.FailureCallback;
|
||||||
import com.fr.third.springframework.util.concurrent.FutureAdapter; |
//import com.fr.third.springframework.util.concurrent.FutureAdapter;
|
||||||
import com.fr.third.springframework.util.concurrent.ListenableFuture; |
//import com.fr.third.springframework.util.concurrent.ListenableFuture;
|
||||||
import com.fr.third.springframework.util.concurrent.ListenableFutureCallback; |
//import com.fr.third.springframework.util.concurrent.ListenableFutureCallback;
|
||||||
import com.fr.third.springframework.util.concurrent.ListenableFutureCallbackRegistry; |
//import com.fr.third.springframework.util.concurrent.ListenableFutureCallbackRegistry;
|
||||||
import com.fr.third.springframework.util.concurrent.SuccessCallback; |
//import com.fr.third.springframework.util.concurrent.SuccessCallback;
|
||||||
|
//
|
||||||
|
//
|
||||||
/** |
///**
|
||||||
* {@link ClientHttpRequest} implementation based on |
// * {@link ClientHttpRequest} implementation based on
|
||||||
* Apache HttpComponents HttpAsyncClient. |
// * Apache HttpComponents HttpAsyncClient.
|
||||||
* |
// *
|
||||||
* <p>Created via the {@link HttpComponentsClientHttpRequestFactory}. |
// * <p>Created via the {@link HttpComponentsClientHttpRequestFactory}.
|
||||||
* |
// *
|
||||||
* @author Oleg Kalnichevski |
// * @author Oleg Kalnichevski
|
||||||
* @author Arjen Poutsma |
// * @author Arjen Poutsma
|
||||||
* @since 4.0 |
// * @since 4.0
|
||||||
* @see HttpComponentsClientHttpRequestFactory#createRequest |
// * @see HttpComponentsClientHttpRequestFactory#createRequest
|
||||||
*/ |
// */
|
||||||
final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { |
//final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest {
|
||||||
|
//
|
||||||
private final HttpAsyncClient httpClient; |
// private final HttpAsyncClient httpClient;
|
||||||
|
//
|
||||||
private final HttpUriRequest httpRequest; |
// private final HttpUriRequest httpRequest;
|
||||||
|
//
|
||||||
private final HttpContext httpContext; |
// private final HttpContext httpContext;
|
||||||
|
//
|
||||||
|
//
|
||||||
HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) { |
// HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) {
|
||||||
this.httpClient = client; |
// this.httpClient = client;
|
||||||
this.httpRequest = request; |
// this.httpRequest = request;
|
||||||
this.httpContext = context; |
// this.httpContext = context;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public HttpMethod getMethod() { |
// public HttpMethod getMethod() {
|
||||||
return HttpMethod.resolve(this.httpRequest.getMethod()); |
// return HttpMethod.resolve(this.httpRequest.getMethod());
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public URI getURI() { |
// public URI getURI() {
|
||||||
return this.httpRequest.getURI(); |
// return this.httpRequest.getURI();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
HttpContext getHttpContext() { |
// HttpContext getHttpContext() {
|
||||||
return this.httpContext; |
// return this.httpContext;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers, byte[] bufferedOutput) |
// protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers, byte[] bufferedOutput)
|
||||||
throws IOException { |
// throws IOException {
|
||||||
|
//
|
||||||
HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers); |
// HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers);
|
||||||
|
//
|
||||||
if (this.httpRequest instanceof HttpEntityEnclosingRequest) { |
// if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
|
||||||
HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest; |
// HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
|
||||||
HttpEntity requestEntity = new NByteArrayEntity(bufferedOutput); |
// HttpEntity requestEntity = new NByteArrayEntity(bufferedOutput);
|
||||||
entityEnclosingRequest.setEntity(requestEntity); |
// entityEnclosingRequest.setEntity(requestEntity);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
HttpResponseFutureCallback callback = new HttpResponseFutureCallback(this.httpRequest); |
// HttpResponseFutureCallback callback = new HttpResponseFutureCallback(this.httpRequest);
|
||||||
Future<HttpResponse> futureResponse = this.httpClient.execute(this.httpRequest, this.httpContext, callback); |
// Future<HttpResponse> futureResponse = this.httpClient.execute(this.httpRequest, this.httpContext, callback);
|
||||||
return new ClientHttpResponseFuture(futureResponse, callback); |
// return new ClientHttpResponseFuture(futureResponse, callback);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
private static class HttpResponseFutureCallback implements FutureCallback<HttpResponse> { |
// private static class HttpResponseFutureCallback implements FutureCallback<HttpResponse> {
|
||||||
|
//
|
||||||
private final HttpUriRequest request; |
// private final HttpUriRequest request;
|
||||||
|
//
|
||||||
private final ListenableFutureCallbackRegistry<ClientHttpResponse> callbacks = |
// private final ListenableFutureCallbackRegistry<ClientHttpResponse> callbacks =
|
||||||
new ListenableFutureCallbackRegistry<ClientHttpResponse>(); |
// new ListenableFutureCallbackRegistry<ClientHttpResponse>();
|
||||||
|
//
|
||||||
public HttpResponseFutureCallback(HttpUriRequest request) { |
// public HttpResponseFutureCallback(HttpUriRequest request) {
|
||||||
this.request = request; |
// this.request = request;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
public void addCallback(ListenableFutureCallback<? super ClientHttpResponse> callback) { |
// public void addCallback(ListenableFutureCallback<? super ClientHttpResponse> callback) {
|
||||||
this.callbacks.addCallback(callback); |
// this.callbacks.addCallback(callback);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
public void addSuccessCallback(SuccessCallback<? super ClientHttpResponse> callback) { |
// public void addSuccessCallback(SuccessCallback<? super ClientHttpResponse> callback) {
|
||||||
this.callbacks.addSuccessCallback(callback); |
// this.callbacks.addSuccessCallback(callback);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
public void addFailureCallback(FailureCallback callback) { |
// public void addFailureCallback(FailureCallback callback) {
|
||||||
this.callbacks.addFailureCallback(callback); |
// this.callbacks.addFailureCallback(callback);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void completed(HttpResponse result) { |
// public void completed(HttpResponse result) {
|
||||||
this.callbacks.success(new HttpComponentsAsyncClientHttpResponse(result)); |
// this.callbacks.success(new HttpComponentsAsyncClientHttpResponse(result));
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void failed(Exception ex) { |
// public void failed(Exception ex) {
|
||||||
this.callbacks.failure(ex); |
// this.callbacks.failure(ex);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void cancelled() { |
// public void cancelled() {
|
||||||
this.request.abort(); |
// this.request.abort();
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
private static class ClientHttpResponseFuture extends FutureAdapter<ClientHttpResponse, HttpResponse> |
// private static class ClientHttpResponseFuture extends FutureAdapter<ClientHttpResponse, HttpResponse>
|
||||||
implements ListenableFuture<ClientHttpResponse> { |
// implements ListenableFuture<ClientHttpResponse> {
|
||||||
|
//
|
||||||
private final HttpResponseFutureCallback callback; |
// private final HttpResponseFutureCallback callback;
|
||||||
|
//
|
||||||
public ClientHttpResponseFuture(Future<HttpResponse> response, HttpResponseFutureCallback callback) { |
// public ClientHttpResponseFuture(Future<HttpResponse> response, HttpResponseFutureCallback callback) {
|
||||||
super(response); |
// super(response);
|
||||||
this.callback = callback; |
// this.callback = callback;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
protected ClientHttpResponse adapt(HttpResponse response) { |
// protected ClientHttpResponse adapt(HttpResponse response) {
|
||||||
return new HttpComponentsAsyncClientHttpResponse(response); |
// return new HttpComponentsAsyncClientHttpResponse(response);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void addCallback(ListenableFutureCallback<? super ClientHttpResponse> callback) { |
// public void addCallback(ListenableFutureCallback<? super ClientHttpResponse> callback) {
|
||||||
this.callback.addCallback(callback); |
// this.callback.addCallback(callback);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void addCallback(SuccessCallback<? super ClientHttpResponse> successCallback, FailureCallback failureCallback) { |
// public void addCallback(SuccessCallback<? super ClientHttpResponse> successCallback, FailureCallback failureCallback) {
|
||||||
this.callback.addSuccessCallback(successCallback); |
// this.callback.addSuccessCallback(successCallback);
|
||||||
this.callback.addFailureCallback(failureCallback); |
// this.callback.addFailureCallback(failureCallback);
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
@ -1,211 +1,211 @@ |
|||||||
/* |
///*
|
||||||
* Copyright 2002-2017 the original author or authors. |
// * Copyright 2002-2017 the original author or authors.
|
||||||
* |
// *
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License. |
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at |
// * You may obtain a copy of the License at
|
||||||
* |
// *
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
// * https://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software |
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and |
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License. |
// * limitations under the License.
|
||||||
*/ |
// */
|
||||||
|
//
|
||||||
package com.fr.third.springframework.http.client; |
//package com.fr.third.springframework.http.client;
|
||||||
|
//
|
||||||
import java.io.Closeable; |
//import java.io.Closeable;
|
||||||
import java.io.IOException; |
//import java.io.IOException;
|
||||||
import java.net.URI; |
//import java.net.URI;
|
||||||
|
//
|
||||||
import org.apache.http.client.HttpClient; |
//import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.config.RequestConfig; |
//import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.Configurable; |
//import org.apache.http.client.methods.Configurable;
|
||||||
import org.apache.http.client.methods.HttpUriRequest; |
//import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.client.protocol.HttpClientContext; |
//import org.apache.http.client.protocol.HttpClientContext;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient; |
//import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; |
//import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||||
import org.apache.http.impl.nio.client.HttpAsyncClients; |
//import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||||
import org.apache.http.nio.client.HttpAsyncClient; |
//import org.apache.http.nio.client.HttpAsyncClient;
|
||||||
import org.apache.http.protocol.HttpContext; |
//import org.apache.http.protocol.HttpContext;
|
||||||
|
//
|
||||||
import com.fr.third.springframework.beans.factory.InitializingBean; |
//import com.fr.third.springframework.beans.factory.InitializingBean;
|
||||||
import com.fr.third.springframework.http.HttpMethod; |
//import com.fr.third.springframework.http.HttpMethod;
|
||||||
import com.fr.third.springframework.util.Assert; |
//import com.fr.third.springframework.util.Assert;
|
||||||
|
//
|
||||||
/** |
///**
|
||||||
* Asynchronous extension of the {@link HttpComponentsClientHttpRequestFactory}. Uses |
// * Asynchronous extension of the {@link HttpComponentsClientHttpRequestFactory}. Uses
|
||||||
* <a href="https://hc.apache.org/httpcomponents-asyncclient-dev/">Apache HttpComponents |
// * <a href="https://hc.apache.org/httpcomponents-asyncclient-dev/">Apache HttpComponents
|
||||||
* HttpAsyncClient 4.0</a> to create requests. |
// * HttpAsyncClient 4.0</a> to create requests.
|
||||||
* |
// *
|
||||||
* @author Arjen Poutsma |
// * @author Arjen Poutsma
|
||||||
* @author Stephane Nicoll |
// * @author Stephane Nicoll
|
||||||
* @since 4.0 |
// * @since 4.0
|
||||||
* @see HttpAsyncClient |
// * @see HttpAsyncClient
|
||||||
*/ |
// */
|
||||||
public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory |
//public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory
|
||||||
implements AsyncClientHttpRequestFactory, InitializingBean { |
// implements AsyncClientHttpRequestFactory, InitializingBean {
|
||||||
|
//
|
||||||
private HttpAsyncClient asyncClient; |
// private HttpAsyncClient asyncClient;
|
||||||
|
//
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} |
// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
|
||||||
* with a default {@link HttpAsyncClient} and {@link HttpClient}. |
// * with a default {@link HttpAsyncClient} and {@link HttpClient}.
|
||||||
*/ |
// */
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory() { |
// public HttpComponentsAsyncClientHttpRequestFactory() {
|
||||||
super(); |
// super();
|
||||||
this.asyncClient = HttpAsyncClients.createSystem(); |
// this.asyncClient = HttpAsyncClients.createSystem();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} |
// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
|
||||||
* with the given {@link HttpAsyncClient} instance and a default {@link HttpClient}. |
// * with the given {@link HttpAsyncClient} instance and a default {@link HttpClient}.
|
||||||
* @param asyncClient the HttpAsyncClient instance to use for this request factory |
// * @param asyncClient the HttpAsyncClient instance to use for this request factory
|
||||||
* @since 4.3.10 |
// * @since 4.3.10
|
||||||
*/ |
// */
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) { |
// public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
|
||||||
super(); |
// super();
|
||||||
setAsyncClient(asyncClient); |
// setAsyncClient(asyncClient);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} |
// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
|
||||||
* with the given {@link CloseableHttpAsyncClient} instance and a default {@link HttpClient}. |
// * with the given {@link CloseableHttpAsyncClient} instance and a default {@link HttpClient}.
|
||||||
* @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory |
// * @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory
|
||||||
*/ |
// */
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) { |
// public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) {
|
||||||
super(); |
// super();
|
||||||
setAsyncClient(asyncClient); |
// setAsyncClient(asyncClient);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} |
// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
|
||||||
* with the given {@link HttpClient} and {@link HttpAsyncClient} instances. |
// * with the given {@link HttpClient} and {@link HttpAsyncClient} instances.
|
||||||
* @param httpClient the HttpClient instance to use for this request factory |
// * @param httpClient the HttpClient instance to use for this request factory
|
||||||
* @param asyncClient the HttpAsyncClient instance to use for this request factory |
// * @param asyncClient the HttpAsyncClient instance to use for this request factory
|
||||||
* @since 4.3.10 |
// * @since 4.3.10
|
||||||
*/ |
// */
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) { |
// public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
|
||||||
super(httpClient); |
// super(httpClient);
|
||||||
setAsyncClient(asyncClient); |
// setAsyncClient(asyncClient);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} |
// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory}
|
||||||
* with the given {@link CloseableHttpClient} and {@link CloseableHttpAsyncClient} instances. |
// * with the given {@link CloseableHttpClient} and {@link CloseableHttpAsyncClient} instances.
|
||||||
* @param httpClient the CloseableHttpClient instance to use for this request factory |
// * @param httpClient the CloseableHttpClient instance to use for this request factory
|
||||||
* @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory |
// * @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory
|
||||||
*/ |
// */
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory( |
// public HttpComponentsAsyncClientHttpRequestFactory(
|
||||||
CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) { |
// CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) {
|
||||||
|
//
|
||||||
super(httpClient); |
// super(httpClient);
|
||||||
setAsyncClient(asyncClient); |
// setAsyncClient(asyncClient);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Set the {@code HttpAsyncClient} used for |
// * Set the {@code HttpAsyncClient} used for
|
||||||
* {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}. |
// * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
|
||||||
* @since 4.3.10 |
// * @since 4.3.10
|
||||||
* @see #setHttpClient(HttpClient) |
// * @see #setHttpClient(HttpClient)
|
||||||
*/ |
// */
|
||||||
public void setAsyncClient(HttpAsyncClient asyncClient) { |
// public void setAsyncClient(HttpAsyncClient asyncClient) {
|
||||||
Assert.notNull(asyncClient, "HttpAsyncClient must not be null"); |
// Assert.notNull(asyncClient, "HttpAsyncClient must not be null");
|
||||||
this.asyncClient = asyncClient; |
// this.asyncClient = asyncClient;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Return the {@code HttpAsyncClient} used for |
// * Return the {@code HttpAsyncClient} used for
|
||||||
* {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}. |
// * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}.
|
||||||
* @since 4.3.10 |
// * @since 4.3.10
|
||||||
* @see #getHttpClient() |
// * @see #getHttpClient()
|
||||||
*/ |
// */
|
||||||
public HttpAsyncClient getAsyncClient() { |
// public HttpAsyncClient getAsyncClient() {
|
||||||
return this.asyncClient; |
// return this.asyncClient;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Set the {@code CloseableHttpAsyncClient} used for |
// * Set the {@code CloseableHttpAsyncClient} used for
|
||||||
* {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}. |
// * {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}.
|
||||||
* @deprecated as of 4.3.10, in favor of {@link #setAsyncClient(HttpAsyncClient)} |
// * @deprecated as of 4.3.10, in favor of {@link #setAsyncClient(HttpAsyncClient)}
|
||||||
*/ |
// */
|
||||||
@Deprecated |
// @Deprecated
|
||||||
public void setHttpAsyncClient(CloseableHttpAsyncClient asyncClient) { |
// public void setHttpAsyncClient(CloseableHttpAsyncClient asyncClient) {
|
||||||
this.asyncClient = asyncClient; |
// this.asyncClient = asyncClient;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
/** |
// /**
|
||||||
* Return the {@code CloseableHttpAsyncClient} used for |
// * Return the {@code CloseableHttpAsyncClient} used for
|
||||||
* {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}. |
// * {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}.
|
||||||
* @deprecated as of 4.3.10, in favor of {@link #getAsyncClient()} |
// * @deprecated as of 4.3.10, in favor of {@link #getAsyncClient()}
|
||||||
*/ |
// */
|
||||||
@Deprecated |
// @Deprecated
|
||||||
public CloseableHttpAsyncClient getHttpAsyncClient() { |
// public CloseableHttpAsyncClient getHttpAsyncClient() {
|
||||||
Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient, |
// Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient,
|
||||||
"No CloseableHttpAsyncClient - use getAsyncClient() instead"); |
// "No CloseableHttpAsyncClient - use getAsyncClient() instead");
|
||||||
return (CloseableHttpAsyncClient) this.asyncClient; |
// return (CloseableHttpAsyncClient) this.asyncClient;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void afterPropertiesSet() { |
// public void afterPropertiesSet() {
|
||||||
startAsyncClient(); |
// startAsyncClient();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
private void startAsyncClient() { |
// private void startAsyncClient() {
|
||||||
HttpAsyncClient asyncClient = getAsyncClient(); |
// HttpAsyncClient asyncClient = getAsyncClient();
|
||||||
if (asyncClient instanceof CloseableHttpAsyncClient) { |
// if (asyncClient instanceof CloseableHttpAsyncClient) {
|
||||||
CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) asyncClient; |
// CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) asyncClient;
|
||||||
if (!closeableAsyncClient.isRunning()) { |
// if (!closeableAsyncClient.isRunning()) {
|
||||||
closeableAsyncClient.start(); |
// closeableAsyncClient.start();
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { |
// public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||||
startAsyncClient(); |
// startAsyncClient();
|
||||||
|
//
|
||||||
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); |
// HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
|
||||||
postProcessHttpRequest(httpRequest); |
// postProcessHttpRequest(httpRequest);
|
||||||
HttpContext context = createHttpContext(httpMethod, uri); |
// HttpContext context = createHttpContext(httpMethod, uri);
|
||||||
if (context == null) { |
// if (context == null) {
|
||||||
context = HttpClientContext.create(); |
// context = HttpClientContext.create();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
// Request configuration not set in the context
|
// // Request configuration not set in the context
|
||||||
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { |
// if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
|
||||||
// Use request configuration given by the user, when available
|
// // Use request configuration given by the user, when available
|
||||||
RequestConfig config = null; |
// RequestConfig config = null;
|
||||||
if (httpRequest instanceof Configurable) { |
// if (httpRequest instanceof Configurable) {
|
||||||
config = ((Configurable) httpRequest).getConfig(); |
// config = ((Configurable) httpRequest).getConfig();
|
||||||
} |
// }
|
||||||
if (config == null) { |
// if (config == null) {
|
||||||
config = createRequestConfig(getAsyncClient()); |
// config = createRequestConfig(getAsyncClient());
|
||||||
} |
// }
|
||||||
if (config != null) { |
// if (config != null) {
|
||||||
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); |
// context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
return new HttpComponentsAsyncClientHttpRequest(getAsyncClient(), httpRequest, context); |
// return new HttpComponentsAsyncClientHttpRequest(getAsyncClient(), httpRequest, context);
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void destroy() throws Exception { |
// public void destroy() throws Exception {
|
||||||
try { |
// try {
|
||||||
super.destroy(); |
// super.destroy();
|
||||||
} |
// }
|
||||||
finally { |
// finally {
|
||||||
HttpAsyncClient asyncClient = getAsyncClient(); |
// HttpAsyncClient asyncClient = getAsyncClient();
|
||||||
if (asyncClient instanceof Closeable) { |
// if (asyncClient instanceof Closeable) {
|
||||||
((Closeable) asyncClient).close(); |
// ((Closeable) asyncClient).close();
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
@ -1,85 +1,85 @@ |
|||||||
/* |
///*
|
||||||
* Copyright 2002-2016 the original author or authors. |
// * Copyright 2002-2016 the original author or authors.
|
||||||
* |
// *
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License. |
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at |
// * You may obtain a copy of the License at
|
||||||
* |
// *
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
// * https://www.apache.org/licenses/LICENSE-2.0
|
||||||
* |
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software |
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and |
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License. |
// * limitations under the License.
|
||||||
*/ |
// */
|
||||||
|
//
|
||||||
package com.fr.third.springframework.http.client; |
//package com.fr.third.springframework.http.client;
|
||||||
|
//
|
||||||
import java.io.IOException; |
//import java.io.IOException;
|
||||||
import java.io.InputStream; |
//import java.io.InputStream;
|
||||||
|
//
|
||||||
import org.apache.http.Header; |
//import org.apache.http.Header;
|
||||||
import org.apache.http.HttpEntity; |
//import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse; |
//import org.apache.http.HttpResponse;
|
||||||
|
//
|
||||||
import com.fr.third.springframework.http.HttpHeaders; |
//import com.fr.third.springframework.http.HttpHeaders;
|
||||||
import com.fr.third.springframework.util.StreamUtils; |
//import com.fr.third.springframework.util.StreamUtils;
|
||||||
|
//
|
||||||
/** |
///**
|
||||||
* {@link ClientHttpResponse} implementation based on |
// * {@link ClientHttpResponse} implementation based on
|
||||||
* Apache HttpComponents HttpAsyncClient. |
// * Apache HttpComponents HttpAsyncClient.
|
||||||
* |
// *
|
||||||
* <p>Created via the {@link HttpComponentsAsyncClientHttpRequest}. |
// * <p>Created via the {@link HttpComponentsAsyncClientHttpRequest}.
|
||||||
* |
// *
|
||||||
* @author Oleg Kalnichevski |
// * @author Oleg Kalnichevski
|
||||||
* @author Arjen Poutsma |
// * @author Arjen Poutsma
|
||||||
* @since 4.0 |
// * @since 4.0
|
||||||
* @see HttpComponentsAsyncClientHttpRequest#executeAsync() |
// * @see HttpComponentsAsyncClientHttpRequest#executeAsync()
|
||||||
*/ |
// */
|
||||||
final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResponse { |
//final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResponse {
|
||||||
|
//
|
||||||
private final HttpResponse httpResponse; |
// private final HttpResponse httpResponse;
|
||||||
|
//
|
||||||
private HttpHeaders headers; |
// private HttpHeaders headers;
|
||||||
|
//
|
||||||
|
//
|
||||||
HttpComponentsAsyncClientHttpResponse(HttpResponse httpResponse) { |
// HttpComponentsAsyncClientHttpResponse(HttpResponse httpResponse) {
|
||||||
this.httpResponse = httpResponse; |
// this.httpResponse = httpResponse;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public int getRawStatusCode() throws IOException { |
// public int getRawStatusCode() throws IOException {
|
||||||
return this.httpResponse.getStatusLine().getStatusCode(); |
// return this.httpResponse.getStatusLine().getStatusCode();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public String getStatusText() throws IOException { |
// public String getStatusText() throws IOException {
|
||||||
return this.httpResponse.getStatusLine().getReasonPhrase(); |
// return this.httpResponse.getStatusLine().getReasonPhrase();
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public HttpHeaders getHeaders() { |
// public HttpHeaders getHeaders() {
|
||||||
if (this.headers == null) { |
// if (this.headers == null) {
|
||||||
this.headers = new HttpHeaders(); |
// this.headers = new HttpHeaders();
|
||||||
for (Header header : this.httpResponse.getAllHeaders()) { |
// for (Header header : this.httpResponse.getAllHeaders()) {
|
||||||
this.headers.add(header.getName(), header.getValue()); |
// this.headers.add(header.getName(), header.getValue());
|
||||||
} |
// }
|
||||||
} |
// }
|
||||||
return this.headers; |
// return this.headers;
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public InputStream getBody() throws IOException { |
// public InputStream getBody() throws IOException {
|
||||||
HttpEntity entity = this.httpResponse.getEntity(); |
// HttpEntity entity = this.httpResponse.getEntity();
|
||||||
return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); |
// return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
|
||||||
} |
// }
|
||||||
|
//
|
||||||
@Override |
// @Override
|
||||||
public void close() { |
// public void close() {
|
||||||
// HTTP responses returned by async HTTP client are not bound to an
|
// // HTTP responses returned by async HTTP client are not bound to an
|
||||||
// active connection and do not have to deallocate any resources...
|
// // active connection and do not have to deallocate any resources...
|
||||||
} |
// }
|
||||||
|
//
|
||||||
} |
//}
|
||||||
|
Loading…
Reference in new issue