Skip to content

Commit b23bf47

Browse files
Adopt apache http client 5
1 parent ed0670b commit b23bf47

18 files changed

Lines changed: 221 additions & 390 deletions

File tree

multiapps-controller-core-test/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
<dependencies>
1616
<dependency>
17-
<groupId>org.apache.httpcomponents</groupId>
18-
<artifactId>httpclient</artifactId>
17+
<groupId>org.apache.httpcomponents.client5</groupId>
18+
<artifactId>httpclient5</artifactId>
1919
</dependency>
2020
<dependency>
2121
<groupId>org.cloudfoundry.multiapps</groupId>

multiapps-controller-core-test/src/main/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
exports org.cloudfoundry.multiapps.controller.core.test;
44

5-
requires transitive org.apache.httpcomponents.httpcore;
65
requires transitive org.cloudfoundry.multiapps.mta;
76

8-
requires org.apache.httpcomponents.httpclient;
7+
requires org.apache.httpcomponents.core5.httpcore5;
98
requires org.cloudfoundry.multiapps.common;
109
requires org.cloudfoundry.multiapps.common.test;
1110
requires org.junit.jupiter.api;
1211
requires org.mockito;
1312

1413
requires static java.compiler;
1514
requires static org.immutables.value;
15+
requires org.apache.httpcomponents.client5.httpclient5;
1616

1717
}

multiapps-controller-core-test/src/main/java/org/cloudfoundry/multiapps/controller/core/test/HttpClientMock.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import java.io.IOException;
44
import java.util.List;
5-
6-
import org.apache.http.HttpHost;
7-
import org.apache.http.HttpResponse;
8-
import org.apache.http.client.ResponseHandler;
9-
import org.apache.http.impl.client.CloseableHttpClient;
10-
import org.apache.http.protocol.HttpContext;
5+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
6+
import org.apache.hc.core5.http.ClassicHttpRequest;
7+
import org.apache.hc.core5.http.HttpHost;
8+
import org.apache.hc.core5.http.HttpResponse;
9+
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
10+
import org.apache.hc.core5.http.protocol.HttpContext;
1111
import org.cloudfoundry.multiapps.common.Nullable;
1212
import org.immutables.value.Value;
1313
import org.mockito.ArgumentMatchers;
@@ -23,9 +23,6 @@ public abstract class HttpClientMock {
2323
@Nullable
2424
public abstract Throwable getException();
2525

26-
@Nullable
27-
public abstract String getResponseHandlerReturnValue();
28-
2926
@Value.Derived
3027
public CloseableHttpClient getMock() {
3128
try {
@@ -49,12 +46,10 @@ public CloseableHttpClient getMock() {
4946
Mockito.when(httpClient.execute(ArgumentMatchers.<HttpHost> any(), ArgumentMatchers.any(),
5047
ArgumentMatchers.<HttpContext> any()))
5148
.thenAnswer(answer);
49+
Mockito.when(
50+
httpClient.execute(ArgumentMatchers.<ClassicHttpRequest> any(), ArgumentMatchers.<HttpClientResponseHandler<Object>> any()))
51+
.thenAnswer(answer);
5252

53-
if (getResponseHandlerReturnValue() != null) {
54-
Mockito.when(httpClient.execute(ArgumentMatchers.any(), ArgumentMatchers.any(),
55-
ArgumentMatchers.<ResponseHandler<Object>> any()))
56-
.thenReturn(getResponseHandlerReturnValue());
57-
}
5853
return httpClient;
5954
} catch (IOException e) {
6055
throw new IllegalStateException(e);

multiapps-controller-core-test/src/main/java/org/cloudfoundry/multiapps/controller/core/test/HttpMocks.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.cloudfoundry.multiapps.controller.core.test;
22

33
import java.util.function.UnaryOperator;
4-
5-
import org.apache.http.client.methods.CloseableHttpResponse;
6-
import org.apache.http.impl.client.CloseableHttpClient;
4+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
5+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
76

87
public class HttpMocks {
98

multiapps-controller-core-test/src/main/java/org/cloudfoundry/multiapps/controller/core/test/HttpResponseMock.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
import java.nio.charset.StandardCharsets;
44
import java.util.Map;
55
import java.util.Map.Entry;
6-
7-
import org.apache.http.Header;
8-
import org.apache.http.HttpEntity;
9-
import org.apache.http.HttpResponse;
10-
import org.apache.http.ProtocolVersion;
11-
import org.apache.http.StatusLine;
12-
import org.apache.http.client.methods.CloseableHttpResponse;
13-
import org.apache.http.entity.StringEntity;
14-
import org.apache.http.message.BasicHeader;
15-
import org.apache.http.message.BasicStatusLine;
6+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
7+
import org.apache.hc.core5.http.Header;
8+
import org.apache.hc.core5.http.HttpEntity;
9+
import org.apache.hc.core5.http.HttpResponse;
10+
import org.apache.hc.core5.http.io.entity.StringEntity;
11+
import org.apache.hc.core5.http.message.BasicHeader;
1612
import org.immutables.value.Value;
1713
import org.mockito.Mockito;
1814

@@ -28,18 +24,14 @@ public abstract class HttpResponseMock {
2824
@Value.Derived
2925
public CloseableHttpResponse getMock() {
3026
CloseableHttpResponse response = Mockito.mock(CloseableHttpResponse.class);
31-
Mockito.when(response.getStatusLine())
32-
.thenReturn(createStatusLine(getStatusCode()));
27+
Mockito.when(response.getCode())
28+
.thenReturn(getStatusCode());
3329
Mockito.when(response.getEntity())
3430
.thenReturn(createHttpEntity(getBody()));
3531
mockHeaders(response);
3632
return response;
3733
}
3834

39-
private static StatusLine createStatusLine(int statusCode) {
40-
return new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), statusCode, null);
41-
}
42-
4335
private static HttpEntity createHttpEntity(String body) {
4436
return new StringEntity(body, StandardCharsets.UTF_8);
4537
}

multiapps-controller-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,9 @@
111111
<groupId>jakarta.inject</groupId>
112112
<artifactId>jakarta.inject-api</artifactId>
113113
</dependency>
114+
<dependency>
115+
<groupId>org.apache.httpcomponents.client5</groupId>
116+
<artifactId>httpclient5</artifactId>
117+
</dependency>
114118
</dependencies>
115119
</project>

multiapps-controller-core/src/main/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
requires org.apache.commons.collections4;
6060
requires org.apache.commons.io;
6161
requires org.apache.commons.lang3;
62-
requires org.apache.httpcomponents.httpclient;
63-
requires org.apache.httpcomponents.httpcore;
62+
requires org.apache.httpcomponents.client5.httpclient5;
63+
requires org.apache.httpcomponents.core5.httpcore5;
6464
requires org.cloudfoundry.multiapps.common;
6565
requires org.cloudfoundry.multiapps.controller.api;
6666
requires org.slf4j;

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/CloudControllerHeaderConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.cloudfoundry.multiapps.controller.core.cf;
22

33
import java.util.Map;
4-
54
import org.apache.commons.lang3.RandomStringUtils;
65
import org.apache.commons.lang3.StringUtils;
7-
import org.apache.http.HttpHeaders;
6+
import org.apache.hc.core5.http.HttpHeaders;
87
import org.cloudfoundry.multiapps.controller.core.Constants;
98

109
public class CloudControllerHeaderConfiguration {

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/http/CookieSpecification.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)