Skip to content

Commit 30a3916

Browse files
author
rathnapandi
committed
upgrade httpclient to version 5
1 parent e00d515 commit 30a3916

44 files changed

Lines changed: 361 additions & 358 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎modules/apim-adapter/pom.xml‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<dependencies>
1818
<dependency>
19-
<groupId>org.apache.httpcomponents</groupId>
20-
<artifactId>httpclient</artifactId>
19+
<groupId>org.apache.httpcomponents.client5</groupId>
20+
<artifactId>httpclient5</artifactId>
2121
</dependency>
2222
<dependency>
2323
<groupId>commons-cli</groupId>
@@ -35,10 +35,7 @@
3535
<groupId>org.apache.commons</groupId>
3636
<artifactId>commons-text</artifactId>
3737
</dependency>
38-
<dependency>
39-
<groupId>org.apache.httpcomponents</groupId>
40-
<artifactId>httpmime</artifactId>
41-
</dependency>
38+
<!-- httpmime is bundled in httpclient5 -->
4239
<dependency>
4340
<groupId>com.fasterxml.jackson.core</groupId>
4441
<artifactId>jackson-core</artifactId>

‎modules/apim-adapter/src/main/java/com/axway/apim/adapter/APIManagerAdapter.java‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
import com.fasterxml.jackson.databind.JsonNode;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
2020
import org.apache.commons.io.IOUtils;
21-
import org.apache.http.Header;
22-
import org.apache.http.HttpEntity;
23-
import org.apache.http.HttpResponse;
24-
import org.apache.http.NameValuePair;
25-
import org.apache.http.client.entity.UrlEncodedFormEntity;
26-
import org.apache.http.client.methods.CloseableHttpResponse;
27-
import org.apache.http.client.utils.URIBuilder;
28-
import org.apache.http.entity.ContentType;
29-
import org.apache.http.entity.mime.MultipartEntityBuilder;
30-
import org.apache.http.message.BasicNameValuePair;
31-
import org.apache.http.util.EntityUtils;
21+
import org.apache.hc.core5.http.Header;
22+
import org.apache.hc.core5.http.HttpEntity;
23+
import org.apache.hc.core5.http.HttpResponse;
24+
import org.apache.hc.core5.http.NameValuePair;
25+
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
26+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
27+
import org.apache.hc.core5.net.URIBuilder;
28+
import org.apache.hc.core5.http.ContentType;
29+
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
30+
import org.apache.hc.core5.http.message.BasicNameValuePair;
31+
import org.apache.hc.core5.http.io.entity.EntityUtils;
32+
import org.apache.hc.core5.http.ParseException;
3233
import org.ehcache.Cache;
3334
import org.ehcache.CacheManager;
3435
import org.ehcache.StateTransitionException;
@@ -231,7 +232,7 @@ public void loginToAPIManager() throws AppException {
231232
User user = getCurrentUser();
232233
String role = getHigherRole(user);
233234
assignRoles(role);
234-
} catch (IOException | URISyntaxException e) {
235+
} catch (IOException | URISyntaxException | ParseException e) {
235236
throw new AppException("Can't login to API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
236237
} catch (InterruptedException e) {
237238
Thread.currentThread().interrupt();
@@ -294,7 +295,7 @@ public void logoutFromAPIManager() throws AppException {
294295
URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/login").build();
295296
DELRequest logoutRequest = new DELRequest(uri);
296297
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) logoutRequest.execute()) {
297-
int statusCode = httpResponse.getStatusLine().getStatusCode();
298+
int statusCode = httpResponse.getCode();
298299
if (statusCode != 204) {
299300
String response = EntityUtils.toString(httpResponse.getEntity());
300301
LOG.warn("Logout failed with statusCode: {} Got response: {}", statusCode, response);
@@ -313,7 +314,7 @@ public static User getCurrentUser() throws AppException {
313314
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) currentUserRequest.execute()) {
314315
getCsrfToken(httpResponse);
315316
String currentUser = EntityUtils.toString(httpResponse.getEntity());
316-
int statusCode = httpResponse.getStatusLine().getStatusCode();
317+
int statusCode = httpResponse.getCode();
317318
if (statusCode != 200) {
318319
throw new AppException("Status-Code: " + statusCode + ", Can't get current-user for user '" + currentUser + "'",
319320
ErrorCode.API_MANAGER_COMMUNICATION);
@@ -332,7 +333,7 @@ public static User getCurrentUser() throws AppException {
332333
}
333334

334335
private static void getCsrfToken(HttpResponse response) throws AppException {
335-
for (Header header : response.getAllHeaders()) {
336+
for (Header header : response.getHeaders()) {
336337
if (header.getName().equalsIgnoreCase("csrf-token")) {
337338
APIMHttpClient.getInstance().setCsrfToken(header.getValue());
338339
break;
@@ -532,7 +533,7 @@ public static Image getImageFromAPIM(URI uri, String baseFilename) throws AppExc
532533
try {
533534
RestAPICall getRequest = new GETRequest(uri);
534535
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) getRequest.execute()) {
535-
int statusCode = httpResponse.getStatusLine().getStatusCode();
536+
int statusCode = httpResponse.getCode();
536537
if (statusCode == 404) return null; // No Image found
537538
if (statusCode != 200) {
538539
String response = EntityUtils.toString(httpResponse.getEntity());
@@ -583,7 +584,7 @@ public static String getCertInfo(InputStream certificate, String password, CaCer
583584
.build();
584585
POSTRequest postRequest = new POSTRequest(entity, uri);
585586
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) postRequest.execute()) {
586-
int statusCode = httpResponse.getStatusLine().getStatusCode();
587+
int statusCode = httpResponse.getCode();
587588
String response = EntityUtils.toString(httpResponse.getEntity());
588589
if (statusCode != 200) {
589590
if (response != null && response.contains("Bad password")) {
@@ -608,7 +609,7 @@ public List<CaCert> getCertInfoFromUrl(String url) throws AppException {
608609
params.add(new BasicNameValuePair("outbound", "true"));
609610
POSTRequest postRequest = new POSTRequest(new UrlEncodedFormEntity(params), uri);
610611
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) postRequest.execute()) {
611-
int statusCode = httpResponse.getStatusLine().getStatusCode();
612+
int statusCode = httpResponse.getCode();
612613
if (statusCode != 200) {
613614
String response = EntityUtils.toString(httpResponse.getEntity());
614615
throw new AppException("API-Manager failed to read certificate information from URL. Got response: '" + response + "'", ErrorCode.API_MANAGER_COMMUNICATION);

‎modules/apim-adapter/src/main/java/com/axway/apim/adapter/HttpHelper.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package com.axway.apim.adapter;
22

33
import com.axway.apim.lib.utils.rest.RestAPICall;
4-
import org.apache.http.HttpEntity;
5-
import org.apache.http.client.methods.CloseableHttpResponse;
6-
import org.apache.http.util.EntityUtils;
4+
import org.apache.hc.core5.http.HttpEntity;
5+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
6+
import org.apache.hc.core5.http.io.entity.EntityUtils;
7+
import org.apache.hc.core5.http.ParseException;
78

89
import java.io.IOException;
910

1011
public class HttpHelper {
1112

12-
public Response execute(RestAPICall restAPICall, boolean responseBody) throws IOException {
13+
public Response execute(RestAPICall restAPICall, boolean responseBody) throws IOException, ParseException {
1314
try(CloseableHttpResponse closeableHttpResponse = (CloseableHttpResponse) restAPICall.execute()){
1415
Response response = new Response();
15-
response.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode());
16+
response.setStatusCode(closeableHttpResponse.getCode());
1617
HttpEntity httpEntity = closeableHttpResponse.getEntity();
1718
if(responseBody && httpEntity != null)
1819
response.setResponseBody(EntityUtils.toString(httpEntity));

‎modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.axway.apim.lib.utils.Utils;
99
import com.axway.apim.lib.utils.Utils.FedKeyType;
1010
import org.apache.commons.lang3.StringUtils;
11-
import org.apache.http.NameValuePair;
12-
import org.apache.http.message.BasicNameValuePair;
11+
import org.apache.hc.core5.http.NameValuePair;
12+
import org.apache.hc.core5.http.message.BasicNameValuePair;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
1515

‎modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAccessAdapter.java‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
import com.fasterxml.jackson.databind.ser.FilterProvider;
2323
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
2424
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
25-
import org.apache.http.HttpEntity;
26-
import org.apache.http.client.methods.CloseableHttpResponse;
27-
import org.apache.http.client.utils.URIBuilder;
28-
import org.apache.http.entity.ContentType;
29-
import org.apache.http.entity.StringEntity;
30-
import org.apache.http.util.EntityUtils;
25+
import org.apache.hc.core5.http.HttpEntity;
26+
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
27+
import org.apache.hc.core5.net.URIBuilder;
28+
import org.apache.hc.core5.http.ContentType;
29+
import org.apache.hc.core5.http.io.entity.StringEntity;
30+
import org.apache.hc.core5.http.io.entity.EntityUtils;
31+
import org.apache.hc.core5.http.ParseException;
3132
import org.ehcache.Cache;
3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
@@ -88,7 +89,7 @@ private void readAPIAccessFromAPIManager(Type type, String id) throws AppExcepti
8889
LOG.debug("Load API-Access with type: {} from API-Manager with ID: {}", type, id);
8990
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) getRequest.execute()) {
9091
String response = EntityUtils.toString(httpResponse.getEntity());
91-
int statusCode = httpResponse.getStatusLine().getStatusCode();
92+
int statusCode = httpResponse.getCode();
9293
if (statusCode < 200 || statusCode > 299) {
9394
LOG.error("Error loading API-Access from API-Manager for {}. Response-Code: {}. Got response: {}", type, statusCode, response);
9495
throw new AppException("Error loading API-Access from API-Manager for " + type + ". Response-Code: " + statusCode, ErrorCode.API_MANAGER_COMMUNICATION);
@@ -100,7 +101,7 @@ private void readAPIAccessFromAPIManager(Type type, String id) throws AppExcepti
100101
apiManagerResponse.put(type, mappedResponse);
101102
putToCache(id, type, response);
102103
}
103-
} catch (IOException | URISyntaxException e) {
104+
} catch (IOException | URISyntaxException | ParseException e) {
104105
throw new AppException("Error loading API-Access from API-Manager for " + type + " from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
105106
}
106107
}
@@ -215,7 +216,7 @@ public APIAccess createAPIAccessForApplication(APIAccess apiAccess, String appli
215216
HttpEntity entity = new StringEntity(mapper.writeValueAsString(apiAccess), ContentType.APPLICATION_JSON);
216217
RestAPICall request = new POSTRequest(entity, uri);
217218
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) request.execute()) {
218-
int statusCode = httpResponse.getStatusLine().getStatusCode();
219+
int statusCode = httpResponse.getCode();
219220
String response = EntityUtils.toString(httpResponse.getEntity());
220221
if (statusCode != 201) {
221222
if (statusCode == 409 && response.contains(RESOURCE_ALREADY_EXISTS)) {
@@ -283,7 +284,7 @@ public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty
283284
removeFromCache(parentEntity.getId(), type);
284285
} catch (InterruptedException e) {
285286
Thread.currentThread().interrupt();
286-
} catch (IOException | URISyntaxException e) {
287+
} catch (IOException | URISyntaxException | ParseException e) {
287288
throw new AppException("Error creating/updating API Access.", ErrorCode.CANT_CREATE_API_PROXY, e);
288289
}
289290
}
@@ -294,7 +295,7 @@ public void deleteAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Ty
294295
// Use an admin account for this request
295296
RestAPICall request = new DELRequest(uri);
296297
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) request.execute()) {
297-
int statusCode = httpResponse.getStatusLine().getStatusCode();
298+
int statusCode = httpResponse.getCode();
298299
if (statusCode < 200 || statusCode > 299) {
299300
String errorResponse = EntityUtils.toString(httpResponse.getEntity());
300301
LOG.error("Can't delete API access requests for application. Response-Code: {}. Got response: {}", statusCode, errorResponse);
@@ -342,7 +343,7 @@ public List<ApiOrganizationSubscription> getSubscribedOrganizationsAndApplicatio
342343
URI uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(cmd.getApiBasepath() + "/proxies/" + apiId + "/apiaccess").build();
343344
RestAPICall request = new GETRequest(uri);
344345
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) request.execute()) {
345-
int statusCode = httpResponse.getStatusLine().getStatusCode();
346+
int statusCode = httpResponse.getCode();
346347
String response = EntityUtils.toString(httpResponse.getEntity());
347348
if (statusCode > 200) {
348349
LOG.error("Can't get API access requests for API. Response-Code: {}. Got response: {}", statusCode, response);

0 commit comments

Comments
 (0)