diff --git a/fine-spring/readme.md b/fine-spring/readme.md index 4e69f76db..31b9858ac 100644 --- a/fine-spring/readme.md +++ b/fine-spring/readme.md @@ -2,4 +2,6 @@ 2 fine-spring内容见https://kms.fineres.com/pages/viewpage.action?pageId=152798513
3 定制内容处均有"// 定制"注释
4 去除对jackson的ObjectMapper的支持:DEC-17331
-5、删除com.fr.third.springframework.remoting.caucho ;com.fr.third.springframework.remoting.httpinvoker; com.fr.third.springframework.remoting.rmi.*
\ No newline at end of file +5 删除com.fr.third.springframework.remoting.caucho ;com.fr.third.springframework.remoting.httpinvoker; com.fr.third.springframework.remoting.rmi.*
+6 HttpComponentsClientHttpRequestFactory里对httpclient的引用也需要修改包名,FDL用到了 +7 HttpComponentsAsyncClientHttpRequest等附近3个类用到了httpasyncclient这个库(这个库后来合入了http-components 5.0),但因为这几个类没有地方用,所以httpasyncclient我们也暂时没有引入 diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java index 730df1863..58c0ead74 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java @@ -1,168 +1,168 @@ -/* - * Copyright 2002-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.fr.third.springframework.http.client; - -import java.io.IOException; -import java.net.URI; -import java.util.concurrent.Future; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpEntityEnclosingRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.concurrent.FutureCallback; -import org.apache.http.nio.client.HttpAsyncClient; -import org.apache.http.nio.entity.NByteArrayEntity; -import org.apache.http.protocol.HttpContext; - -import com.fr.third.springframework.http.HttpHeaders; -import com.fr.third.springframework.http.HttpMethod; -import com.fr.third.springframework.util.concurrent.FailureCallback; -import com.fr.third.springframework.util.concurrent.FutureAdapter; -import com.fr.third.springframework.util.concurrent.ListenableFuture; -import com.fr.third.springframework.util.concurrent.ListenableFutureCallback; -import com.fr.third.springframework.util.concurrent.ListenableFutureCallbackRegistry; -import com.fr.third.springframework.util.concurrent.SuccessCallback; - - -/** - * {@link ClientHttpRequest} implementation based on - * Apache HttpComponents HttpAsyncClient. - * - *

Created via the {@link HttpComponentsClientHttpRequestFactory}. - * - * @author Oleg Kalnichevski - * @author Arjen Poutsma - * @since 4.0 - * @see HttpComponentsClientHttpRequestFactory#createRequest - */ -final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { - - private final HttpAsyncClient httpClient; - - private final HttpUriRequest httpRequest; - - private final HttpContext httpContext; - - - HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) { - this.httpClient = client; - this.httpRequest = request; - this.httpContext = context; - } - - - @Override - public HttpMethod getMethod() { - return HttpMethod.resolve(this.httpRequest.getMethod()); - } - - @Override - public URI getURI() { - return this.httpRequest.getURI(); - } - - HttpContext getHttpContext() { - return this.httpContext; - } - - @Override - protected ListenableFuture executeInternal(HttpHeaders headers, byte[] bufferedOutput) - throws IOException { - - HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers); - - if (this.httpRequest instanceof HttpEntityEnclosingRequest) { - HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest; - HttpEntity requestEntity = new NByteArrayEntity(bufferedOutput); - entityEnclosingRequest.setEntity(requestEntity); - } - - HttpResponseFutureCallback callback = new HttpResponseFutureCallback(this.httpRequest); - Future futureResponse = this.httpClient.execute(this.httpRequest, this.httpContext, callback); - return new ClientHttpResponseFuture(futureResponse, callback); - } - - - private static class HttpResponseFutureCallback implements FutureCallback { - - private final HttpUriRequest request; - - private final ListenableFutureCallbackRegistry callbacks = - new ListenableFutureCallbackRegistry(); - - public HttpResponseFutureCallback(HttpUriRequest request) { - this.request = request; - } - - public void addCallback(ListenableFutureCallback callback) { - this.callbacks.addCallback(callback); - } - - public void addSuccessCallback(SuccessCallback callback) { - this.callbacks.addSuccessCallback(callback); - } - - public void addFailureCallback(FailureCallback callback) { - this.callbacks.addFailureCallback(callback); - } - - @Override - public void completed(HttpResponse result) { - this.callbacks.success(new HttpComponentsAsyncClientHttpResponse(result)); - } - - @Override - public void failed(Exception ex) { - this.callbacks.failure(ex); - } - - @Override - public void cancelled() { - this.request.abort(); - } - } - - - private static class ClientHttpResponseFuture extends FutureAdapter - implements ListenableFuture { - - private final HttpResponseFutureCallback callback; - - public ClientHttpResponseFuture(Future response, HttpResponseFutureCallback callback) { - super(response); - this.callback = callback; - } - - @Override - protected ClientHttpResponse adapt(HttpResponse response) { - return new HttpComponentsAsyncClientHttpResponse(response); - } - - @Override - public void addCallback(ListenableFutureCallback callback) { - this.callback.addCallback(callback); - } - - @Override - public void addCallback(SuccessCallback successCallback, FailureCallback failureCallback) { - this.callback.addSuccessCallback(successCallback); - this.callback.addFailureCallback(failureCallback); - } - } - -} +///* +// * Copyright 2002-2016 the original author or authors. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +// +//package com.fr.third.springframework.http.client; +// +//import java.io.IOException; +//import java.net.URI; +//import java.util.concurrent.Future; +// +//import org.apache.http.HttpEntity; +//import org.apache.http.HttpEntityEnclosingRequest; +//import org.apache.http.HttpResponse; +//import org.apache.http.client.methods.HttpUriRequest; +//import org.apache.http.concurrent.FutureCallback; +//import org.apache.http.nio.client.HttpAsyncClient; +//import org.apache.http.nio.entity.NByteArrayEntity; +//import org.apache.http.protocol.HttpContext; +// +//import com.fr.third.springframework.http.HttpHeaders; +//import com.fr.third.springframework.http.HttpMethod; +//import com.fr.third.springframework.util.concurrent.FailureCallback; +//import com.fr.third.springframework.util.concurrent.FutureAdapter; +//import com.fr.third.springframework.util.concurrent.ListenableFuture; +//import com.fr.third.springframework.util.concurrent.ListenableFutureCallback; +//import com.fr.third.springframework.util.concurrent.ListenableFutureCallbackRegistry; +//import com.fr.third.springframework.util.concurrent.SuccessCallback; +// +// +///** +// * {@link ClientHttpRequest} implementation based on +// * Apache HttpComponents HttpAsyncClient. +// * +// *

Created via the {@link HttpComponentsClientHttpRequestFactory}. +// * +// * @author Oleg Kalnichevski +// * @author Arjen Poutsma +// * @since 4.0 +// * @see HttpComponentsClientHttpRequestFactory#createRequest +// */ +//final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { +// +// private final HttpAsyncClient httpClient; +// +// private final HttpUriRequest httpRequest; +// +// private final HttpContext httpContext; +// +// +// HttpComponentsAsyncClientHttpRequest(HttpAsyncClient client, HttpUriRequest request, HttpContext context) { +// this.httpClient = client; +// this.httpRequest = request; +// this.httpContext = context; +// } +// +// +// @Override +// public HttpMethod getMethod() { +// return HttpMethod.resolve(this.httpRequest.getMethod()); +// } +// +// @Override +// public URI getURI() { +// return this.httpRequest.getURI(); +// } +// +// HttpContext getHttpContext() { +// return this.httpContext; +// } +// +// @Override +// protected ListenableFuture executeInternal(HttpHeaders headers, byte[] bufferedOutput) +// throws IOException { +// +// HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers); +// +// if (this.httpRequest instanceof HttpEntityEnclosingRequest) { +// HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest; +// HttpEntity requestEntity = new NByteArrayEntity(bufferedOutput); +// entityEnclosingRequest.setEntity(requestEntity); +// } +// +// HttpResponseFutureCallback callback = new HttpResponseFutureCallback(this.httpRequest); +// Future futureResponse = this.httpClient.execute(this.httpRequest, this.httpContext, callback); +// return new ClientHttpResponseFuture(futureResponse, callback); +// } +// +// +// private static class HttpResponseFutureCallback implements FutureCallback { +// +// private final HttpUriRequest request; +// +// private final ListenableFutureCallbackRegistry callbacks = +// new ListenableFutureCallbackRegistry(); +// +// public HttpResponseFutureCallback(HttpUriRequest request) { +// this.request = request; +// } +// +// public void addCallback(ListenableFutureCallback callback) { +// this.callbacks.addCallback(callback); +// } +// +// public void addSuccessCallback(SuccessCallback callback) { +// this.callbacks.addSuccessCallback(callback); +// } +// +// public void addFailureCallback(FailureCallback callback) { +// this.callbacks.addFailureCallback(callback); +// } +// +// @Override +// public void completed(HttpResponse result) { +// this.callbacks.success(new HttpComponentsAsyncClientHttpResponse(result)); +// } +// +// @Override +// public void failed(Exception ex) { +// this.callbacks.failure(ex); +// } +// +// @Override +// public void cancelled() { +// this.request.abort(); +// } +// } +// +// +// private static class ClientHttpResponseFuture extends FutureAdapter +// implements ListenableFuture { +// +// private final HttpResponseFutureCallback callback; +// +// public ClientHttpResponseFuture(Future response, HttpResponseFutureCallback callback) { +// super(response); +// this.callback = callback; +// } +// +// @Override +// protected ClientHttpResponse adapt(HttpResponse response) { +// return new HttpComponentsAsyncClientHttpResponse(response); +// } +// +// @Override +// public void addCallback(ListenableFutureCallback callback) { +// this.callback.addCallback(callback); +// } +// +// @Override +// public void addCallback(SuccessCallback successCallback, FailureCallback failureCallback) { +// this.callback.addSuccessCallback(successCallback); +// this.callback.addFailureCallback(failureCallback); +// } +// } +// +//} diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java index ecbf3a81f..de2b56567 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java @@ -1,211 +1,211 @@ -/* - * Copyright 2002-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.fr.third.springframework.http.client; - -import java.io.Closeable; -import java.io.IOException; -import java.net.URI; - -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.Configurable; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.client.HttpAsyncClients; -import org.apache.http.nio.client.HttpAsyncClient; -import org.apache.http.protocol.HttpContext; - -import com.fr.third.springframework.beans.factory.InitializingBean; -import com.fr.third.springframework.http.HttpMethod; -import com.fr.third.springframework.util.Assert; - -/** - * Asynchronous extension of the {@link HttpComponentsClientHttpRequestFactory}. Uses - * Apache HttpComponents - * HttpAsyncClient 4.0 to create requests. - * - * @author Arjen Poutsma - * @author Stephane Nicoll - * @since 4.0 - * @see HttpAsyncClient - */ -public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory - implements AsyncClientHttpRequestFactory, InitializingBean { - - private HttpAsyncClient asyncClient; - - - /** - * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} - * with a default {@link HttpAsyncClient} and {@link HttpClient}. - */ - public HttpComponentsAsyncClientHttpRequestFactory() { - super(); - this.asyncClient = HttpAsyncClients.createSystem(); - } - - /** - * 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); - } - - /** - * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} - * with the given {@link CloseableHttpAsyncClient} instance and a default {@link HttpClient}. - * @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory - */ - public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) { - super(); - setAsyncClient(asyncClient); - } - - /** - * 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); - } - - /** - * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} - * with the given {@link CloseableHttpClient} and {@link CloseableHttpAsyncClient} instances. - * @param httpClient the CloseableHttpClient instance to use for this request factory - * @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory - */ - public HttpComponentsAsyncClientHttpRequestFactory( - CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) { - - super(httpClient); - setAsyncClient(asyncClient); - } - - - /** - * 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; - } - - /** - * Return the {@code HttpAsyncClient} used for - * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}. - * @since 4.3.10 - * @see #getHttpClient() - */ - public HttpAsyncClient getAsyncClient() { - return this.asyncClient; - } - - /** - * Set the {@code CloseableHttpAsyncClient} used for - * {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}. - * @deprecated as of 4.3.10, in favor of {@link #setAsyncClient(HttpAsyncClient)} - */ - @Deprecated - public void setHttpAsyncClient(CloseableHttpAsyncClient asyncClient) { - this.asyncClient = asyncClient; - } - - /** - * Return the {@code CloseableHttpAsyncClient} used for - * {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}. - * @deprecated as of 4.3.10, in favor of {@link #getAsyncClient()} - */ - @Deprecated - public CloseableHttpAsyncClient getHttpAsyncClient() { - Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient, - "No CloseableHttpAsyncClient - use getAsyncClient() instead"); - return (CloseableHttpAsyncClient) this.asyncClient; - } - - - @Override - public void afterPropertiesSet() { - startAsyncClient(); - } - - private void startAsyncClient() { - HttpAsyncClient asyncClient = getAsyncClient(); - if (asyncClient instanceof CloseableHttpAsyncClient) { - CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) asyncClient; - if (!closeableAsyncClient.isRunning()) { - closeableAsyncClient.start(); - } - } - } - - @Override - public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { - 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(getAsyncClient()); - } - if (config != null) { - context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); - } - } - - return new HttpComponentsAsyncClientHttpRequest(getAsyncClient(), httpRequest, context); - } - - @Override - public void destroy() throws Exception { - try { - super.destroy(); - } - finally { - HttpAsyncClient asyncClient = getAsyncClient(); - if (asyncClient instanceof Closeable) { - ((Closeable) asyncClient).close(); - } - } - } - -} +///* +// * Copyright 2002-2017 the original author or authors. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +// +//package com.fr.third.springframework.http.client; +// +//import java.io.Closeable; +//import java.io.IOException; +//import java.net.URI; +// +//import org.apache.http.client.HttpClient; +//import org.apache.http.client.config.RequestConfig; +//import org.apache.http.client.methods.Configurable; +//import org.apache.http.client.methods.HttpUriRequest; +//import org.apache.http.client.protocol.HttpClientContext; +//import org.apache.http.impl.client.CloseableHttpClient; +//import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +//import org.apache.http.impl.nio.client.HttpAsyncClients; +//import org.apache.http.nio.client.HttpAsyncClient; +//import org.apache.http.protocol.HttpContext; +// +//import com.fr.third.springframework.beans.factory.InitializingBean; +//import com.fr.third.springframework.http.HttpMethod; +//import com.fr.third.springframework.util.Assert; +// +///** +// * Asynchronous extension of the {@link HttpComponentsClientHttpRequestFactory}. Uses +// * Apache HttpComponents +// * HttpAsyncClient 4.0 to create requests. +// * +// * @author Arjen Poutsma +// * @author Stephane Nicoll +// * @since 4.0 +// * @see HttpAsyncClient +// */ +//public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory +// implements AsyncClientHttpRequestFactory, InitializingBean { +// +// private HttpAsyncClient asyncClient; +// +// +// /** +// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} +// * with a default {@link HttpAsyncClient} and {@link HttpClient}. +// */ +// public HttpComponentsAsyncClientHttpRequestFactory() { +// super(); +// this.asyncClient = HttpAsyncClients.createSystem(); +// } +// +// /** +// * 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); +// } +// +// /** +// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} +// * with the given {@link CloseableHttpAsyncClient} instance and a default {@link HttpClient}. +// * @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory +// */ +// public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) { +// super(); +// setAsyncClient(asyncClient); +// } +// +// /** +// * 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); +// } +// +// /** +// * Create a new instance of the {@code HttpComponentsAsyncClientHttpRequestFactory} +// * with the given {@link CloseableHttpClient} and {@link CloseableHttpAsyncClient} instances. +// * @param httpClient the CloseableHttpClient instance to use for this request factory +// * @param asyncClient the CloseableHttpAsyncClient instance to use for this request factory +// */ +// public HttpComponentsAsyncClientHttpRequestFactory( +// CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) { +// +// super(httpClient); +// setAsyncClient(asyncClient); +// } +// +// +// /** +// * 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; +// } +// +// /** +// * Return the {@code HttpAsyncClient} used for +// * {@linkplain #createAsyncRequest(URI, HttpMethod) synchronous execution}. +// * @since 4.3.10 +// * @see #getHttpClient() +// */ +// public HttpAsyncClient getAsyncClient() { +// return this.asyncClient; +// } +// +// /** +// * Set the {@code CloseableHttpAsyncClient} used for +// * {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}. +// * @deprecated as of 4.3.10, in favor of {@link #setAsyncClient(HttpAsyncClient)} +// */ +// @Deprecated +// public void setHttpAsyncClient(CloseableHttpAsyncClient asyncClient) { +// this.asyncClient = asyncClient; +// } +// +// /** +// * Return the {@code CloseableHttpAsyncClient} used for +// * {@linkplain #createAsyncRequest(URI, HttpMethod) asynchronous execution}. +// * @deprecated as of 4.3.10, in favor of {@link #getAsyncClient()} +// */ +// @Deprecated +// public CloseableHttpAsyncClient getHttpAsyncClient() { +// Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient, +// "No CloseableHttpAsyncClient - use getAsyncClient() instead"); +// return (CloseableHttpAsyncClient) this.asyncClient; +// } +// +// +// @Override +// public void afterPropertiesSet() { +// startAsyncClient(); +// } +// +// private void startAsyncClient() { +// HttpAsyncClient asyncClient = getAsyncClient(); +// if (asyncClient instanceof CloseableHttpAsyncClient) { +// CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) asyncClient; +// if (!closeableAsyncClient.isRunning()) { +// closeableAsyncClient.start(); +// } +// } +// } +// +// @Override +// public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { +// 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(getAsyncClient()); +// } +// if (config != null) { +// context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); +// } +// } +// +// return new HttpComponentsAsyncClientHttpRequest(getAsyncClient(), httpRequest, context); +// } +// +// @Override +// public void destroy() throws Exception { +// try { +// super.destroy(); +// } +// finally { +// HttpAsyncClient asyncClient = getAsyncClient(); +// if (asyncClient instanceof Closeable) { +// ((Closeable) asyncClient).close(); +// } +// } +// } +// +//} diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java index b4849b56b..454e4681a 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java @@ -1,85 +1,85 @@ -/* - * Copyright 2002-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.fr.third.springframework.http.client; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; - -import com.fr.third.springframework.http.HttpHeaders; -import com.fr.third.springframework.util.StreamUtils; - -/** - * {@link ClientHttpResponse} implementation based on - * Apache HttpComponents HttpAsyncClient. - * - *

Created via the {@link HttpComponentsAsyncClientHttpRequest}. - * - * @author Oleg Kalnichevski - * @author Arjen Poutsma - * @since 4.0 - * @see HttpComponentsAsyncClientHttpRequest#executeAsync() - */ -final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResponse { - - private final HttpResponse httpResponse; - - private HttpHeaders headers; - - - HttpComponentsAsyncClientHttpResponse(HttpResponse httpResponse) { - this.httpResponse = httpResponse; - } - - - @Override - public int getRawStatusCode() throws IOException { - return this.httpResponse.getStatusLine().getStatusCode(); - } - - @Override - public String getStatusText() throws IOException { - return this.httpResponse.getStatusLine().getReasonPhrase(); - } - - @Override - public HttpHeaders getHeaders() { - if (this.headers == null) { - this.headers = new HttpHeaders(); - for (Header header : this.httpResponse.getAllHeaders()) { - this.headers.add(header.getName(), header.getValue()); - } - } - return this.headers; - } - - @Override - public InputStream getBody() throws IOException { - HttpEntity entity = this.httpResponse.getEntity(); - return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); - } - - @Override - public void close() { - // HTTP responses returned by async HTTP client are not bound to an - // active connection and do not have to deallocate any resources... - } - -} +///* +// * Copyright 2002-2016 the original author or authors. +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// */ +// +//package com.fr.third.springframework.http.client; +// +//import java.io.IOException; +//import java.io.InputStream; +// +//import org.apache.http.Header; +//import org.apache.http.HttpEntity; +//import org.apache.http.HttpResponse; +// +//import com.fr.third.springframework.http.HttpHeaders; +//import com.fr.third.springframework.util.StreamUtils; +// +///** +// * {@link ClientHttpResponse} implementation based on +// * Apache HttpComponents HttpAsyncClient. +// * +// *

Created via the {@link HttpComponentsAsyncClientHttpRequest}. +// * +// * @author Oleg Kalnichevski +// * @author Arjen Poutsma +// * @since 4.0 +// * @see HttpComponentsAsyncClientHttpRequest#executeAsync() +// */ +//final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResponse { +// +// private final HttpResponse httpResponse; +// +// private HttpHeaders headers; +// +// +// HttpComponentsAsyncClientHttpResponse(HttpResponse httpResponse) { +// this.httpResponse = httpResponse; +// } +// +// +// @Override +// public int getRawStatusCode() throws IOException { +// return this.httpResponse.getStatusLine().getStatusCode(); +// } +// +// @Override +// public String getStatusText() throws IOException { +// return this.httpResponse.getStatusLine().getReasonPhrase(); +// } +// +// @Override +// public HttpHeaders getHeaders() { +// if (this.headers == null) { +// this.headers = new HttpHeaders(); +// for (Header header : this.httpResponse.getAllHeaders()) { +// this.headers.add(header.getName(), header.getValue()); +// } +// } +// return this.headers; +// } +// +// @Override +// public InputStream getBody() throws IOException { +// HttpEntity entity = this.httpResponse.getEntity(); +// return (entity != null ? entity.getContent() : StreamUtils.emptyInput()); +// } +// +// @Override +// public void close() { +// // HTTP responses returned by async HTTP client are not bound to an +// // active connection and do not have to deallocate any resources... +// } +// +//} diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequest.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequest.java index 378f459b5..778fba7d1 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequest.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequest.java @@ -21,14 +21,14 @@ import java.net.URI; import java.util.List; import java.util.Map; -import org.apache.http.HttpEntity; -import org.apache.http.HttpEntityEnclosingRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.protocol.HTTP; -import org.apache.http.protocol.HttpContext; +import com.fr.third.org.apache.http.HttpEntity; +import com.fr.third.org.apache.http.HttpEntityEnclosingRequest; +import com.fr.third.org.apache.http.HttpResponse; +import com.fr.third.org.apache.http.client.HttpClient; +import com.fr.third.org.apache.http.client.methods.HttpUriRequest; +import com.fr.third.org.apache.http.entity.ByteArrayEntity; +import com.fr.third.org.apache.http.protocol.HTTP; +import com.fr.third.org.apache.http.protocol.HttpContext; import com.fr.third.springframework.http.HttpHeaders; import com.fr.third.springframework.http.HttpMethod; diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequestFactory.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequestFactory.java index b9287bce5..af4253359 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequestFactory.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpRequestFactory.java @@ -20,21 +20,21 @@ import java.io.Closeable; import java.io.IOException; import java.net.URI; -import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.Configurable; -import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpOptions; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpTrace; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.protocol.HttpContext; +import com.fr.third.org.apache.http.client.HttpClient; +import com.fr.third.org.apache.http.client.config.RequestConfig; +import com.fr.third.org.apache.http.client.methods.Configurable; +import com.fr.third.org.apache.http.client.methods.HttpEntityEnclosingRequestBase; +import com.fr.third.org.apache.http.client.methods.HttpGet; +import com.fr.third.org.apache.http.client.methods.HttpHead; +import com.fr.third.org.apache.http.client.methods.HttpOptions; +import com.fr.third.org.apache.http.client.methods.HttpPatch; +import com.fr.third.org.apache.http.client.methods.HttpPost; +import com.fr.third.org.apache.http.client.methods.HttpPut; +import com.fr.third.org.apache.http.client.methods.HttpTrace; +import com.fr.third.org.apache.http.client.methods.HttpUriRequest; +import com.fr.third.org.apache.http.client.protocol.HttpClientContext; +import com.fr.third.org.apache.http.impl.client.HttpClients; +import com.fr.third.org.apache.http.protocol.HttpContext; import com.fr.third.springframework.beans.factory.DisposableBean; import com.fr.third.springframework.http.HttpMethod; @@ -64,7 +64,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest static { try { // Looking for AbstractHttpClient class (deprecated as of HttpComponents 4.3) - abstractHttpClientClass = ClassUtils.forName("org.apache.http.impl.client.AbstractHttpClient", + abstractHttpClientClass = ClassUtils.forName("com.fr.third.org.apache.http.impl.client.AbstractHttpClient", HttpComponentsClientHttpRequestFactory.class.getClassLoader()); } catch (ClassNotFoundException ex) { @@ -146,7 +146,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest @SuppressWarnings("deprecation") private void setLegacyConnectionTimeout(HttpClient client, int timeout) { if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) { - client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); + client.getParams().setIntParameter(com.fr.third.org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); } } @@ -187,7 +187,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest @SuppressWarnings("deprecation") private void setLegacySocketTimeout(HttpClient client, int timeout) { if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) { - client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout); + client.getParams().setIntParameter(com.fr.third.org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout); } } @@ -342,7 +342,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest /** * Shutdown hook that closes the underlying - * {@link org.apache.http.conn.HttpClientConnectionManager ClientConnectionManager}'s + * {@link com.fr.third.org.apache.http.conn.HttpClientConnectionManager ClientConnectionManager}'s * connection pool, if any. */ @Override @@ -355,9 +355,9 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest /** - * An alternative to {@link org.apache.http.client.methods.HttpDelete} that - * extends {@link org.apache.http.client.methods.HttpEntityEnclosingRequestBase} - * rather than {@link org.apache.http.client.methods.HttpRequestBase} and + * An alternative to {@link com.fr.third.org.apache.http.client.methods.HttpDelete} that + * extends {@link com.fr.third.org.apache.http.client.methods.HttpEntityEnclosingRequestBase} + * rather than {@link com.fr.third.org.apache.http.client.methods.HttpRequestBase} and * hence allows HTTP delete with a request body. For use with the RestTemplate * exchange methods which allow the combination of HTTP DELETE with an entity. * @since 4.1.2 diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpResponse.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpResponse.java index 7eac80caa..8e9aa371c 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpResponse.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsClientHttpResponse.java @@ -20,10 +20,10 @@ import java.io.Closeable; import java.io.IOException; import java.io.InputStream; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; +import com.fr.third.org.apache.http.Header; +import com.fr.third.org.apache.http.HttpEntity; +import com.fr.third.org.apache.http.HttpResponse; +import com.fr.third.org.apache.http.util.EntityUtils; import com.fr.third.springframework.http.HttpHeaders; import com.fr.third.springframework.util.StreamUtils; diff --git a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java index 11e6f0fb6..2a4db7d02 100644 --- a/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java +++ b/fine-spring/src/main/java/com/fr/third/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java @@ -21,14 +21,14 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URI; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpEntityEnclosingRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.message.BasicHeader; -import org.apache.http.protocol.HttpContext; +import com.fr.third.org.apache.http.Header; +import com.fr.third.org.apache.http.HttpEntity; +import com.fr.third.org.apache.http.HttpEntityEnclosingRequest; +import com.fr.third.org.apache.http.HttpResponse; +import com.fr.third.org.apache.http.client.HttpClient; +import com.fr.third.org.apache.http.client.methods.HttpUriRequest; +import com.fr.third.org.apache.http.message.BasicHeader; +import com.fr.third.org.apache.http.protocol.HttpContext; import com.fr.third.springframework.http.HttpHeaders; import com.fr.third.springframework.http.HttpMethod;