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> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>${httpclient.version}</version> <version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version> <version>${commons-lang3.version}</version>

View File

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