fix merge issue; refactoring

This commit is contained in:
binary-joe 2019-09-14 19:37:32 +02:00
parent eafae99b79
commit 60c990b8c1
2 changed files with 15 additions and 11 deletions

View File

@ -16,6 +16,8 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>

View File

@ -48,12 +48,11 @@ public class HttpClient {
}
}
private void setAuthenticator() {
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
});
private HttpURLConnection createConnection(String urlString) throws MalformedURLException, IOException, ProtocolException {
URL url = new URL(String.format(urlString));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
return connection;
}
private String createBasicAuthHeaderValue() {
@ -63,10 +62,13 @@ public class HttpClient {
return authHeaderValue;
}
private HttpURLConnection createConnection(String urlString) throws MalformedURLException, IOException, ProtocolException {
URL url = new URL(String.format(urlString));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
return connection;
private void setAuthenticator() {
Authenticator.setDefault(new BasicAuthenticator());
}
private final class BasicAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
}