Skip to content

Commit

Permalink
Spring 6.0 upgrade: org.apache.http.client -> org.apache.hc.client5
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Apr 24, 2023
1 parent 24fdcad commit 93eb993
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest;
Expand Down Expand Up @@ -186,11 +185,11 @@ public void send(Message message, String transportName, Event event, Task task,
HttpClientBuilder builder = HttpClientBuilder.create();
String username = smsGatewayConfigurationType.getUsername();
ProtectedStringType password = smsGatewayConfigurationType.getPassword();
CredentialsProvider provider = new BasicCredentialsProvider();
BasicCredentialsProvider provider = new BasicCredentialsProvider();
if (username != null) {
String plainPassword = password != null ? transportSupport.protector().decryptString(password) : null;
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, plainPassword);
provider.setCredentials(AuthScope.ANY, credentials);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, plainPassword.toCharArray());
provider.setCredentials(new AuthScope(null, null, -1, null, null), credentials);
builder = builder.setDefaultCredentialsProvider(provider);
}
String proxyUsername = smsGatewayConfigurationType.getProxyUsername();
Expand All @@ -204,7 +203,7 @@ public void send(Message message, String transportName, Event event, Task task,
}
if (StringUtils.isNotBlank(proxyUsername)) {
String plainProxyPassword = proxyPassword != null ? transportSupport.protector().decryptString(proxyPassword) : null;
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(proxyUsername, plainProxyPassword);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(proxyUsername, plainProxyPassword.toCharArray());
provider.setCredentials(new AuthScope(proxy), credentials);
}
builder = builder.setDefaultCredentialsProvider(provider);
Expand All @@ -220,7 +219,7 @@ public void send(Message message, String transportName, Event event, Task task,
}
try (ClientHttpResponse response = request.execute()) {
LOGGER.debug("Result: " + response.getStatusCode() + "/" + response.getStatusText());
if (response.getStatusCode().series() != HttpStatus.Series.SUCCESSFUL) {
if (!response.getStatusCode().is2xxSuccessful()) {
throw new SystemException("SMS gateway communication failed: "
+ response.getStatusCode() + ": " + response.getStatusText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
import javax.xml.namespace.QName;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
Expand Down Expand Up @@ -214,11 +212,11 @@ public void send(Message message, String transportName, Event event, Task task,
HttpClientBuilder builder = HttpClientBuilder.create();
String username = smsGatewayConfigurationType.getUsername();
ProtectedStringType password = smsGatewayConfigurationType.getPassword();
CredentialsProvider provider = new BasicCredentialsProvider();
BasicCredentialsProvider provider = new BasicCredentialsProvider();
if (username != null) {
String plainPassword = password != null ? protector.decryptString(password) : null;
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, plainPassword);
provider.setCredentials(AuthScope.ANY, credentials);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, plainPassword.toCharArray());
provider.setCredentials(new AuthScope(null, null, -1, null, null), credentials);
builder = builder.setDefaultCredentialsProvider(provider);
}
String proxyUsername = smsGatewayConfigurationType.getProxyUsername();
Expand All @@ -232,7 +230,7 @@ public void send(Message message, String transportName, Event event, Task task,
}
if (StringUtils.isNotBlank(proxyUsername)) {
String plainProxyPassword = proxyPassword != null ? protector.decryptString(proxyPassword) : null;
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(proxyUsername, plainProxyPassword);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(proxyUsername, plainProxyPassword.toCharArray());
provider.setCredentials(new AuthScope(proxy), credentials);
}
builder = builder.setDefaultCredentialsProvider(provider);
Expand All @@ -248,7 +246,7 @@ public void send(Message message, String transportName, Event event, Task task,
}
ClientHttpResponse response = request.execute();
LOGGER.debug("Result: " + response.getStatusCode() + "/" + response.getStatusText());
if (response.getStatusCode().series() != HttpStatus.Series.SUCCESSFUL) {
if (!response.getStatusCode().is2xxSuccessful()) {
throw new SystemException("SMS gateway communication failed: " + response.getStatusCode() + ": " + response.getStatusText());
}
LOGGER.debug("Message sent successfully to {} via gateway {}.", message.getTo(), smsGatewayConfigurationType.getName());
Expand Down

0 comments on commit 93eb993

Please sign in to comment.