Skip to content

Commit

Permalink
Add basic auth headers if userinfo present.
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMaciaszek committed Jun 16, 2023
1 parent b031519 commit 1b86b2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public AbstractJersey3EurekaHttpClient(Client jerseyClient, String serviceUrl) {
}
this.userName = localUserName;
this.password = localPassword;
if (userName != null) {
HttpAuthenticationFeature basicAuth = HttpAuthenticationFeature.basic(userName, password);
this.jerseyClient.register(basicAuth);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public class EurekaJersey3ClientImpl implements EurekaJersey3Client {

private static final String PROTOCOL = "https";
private static final String PROTOCOL_SCHEME = "SSL";
private static final int HTTPS_PORT = 443;
private static final String KEYSTORE_TYPE = "JKS";

private final Client apacheHttpClient;
private final Client jerseyClient;

private final ConnectionCleanerTask connectionCleanerTask;

Expand Down Expand Up @@ -91,7 +90,7 @@ public EurekaJersey3ClientImpl(
jerseyClientConfig.connectorProvider(new ApacheConnectorProvider());
jerseyClientConfig.property(ClientProperties.CONNECT_TIMEOUT, connectionTimeout);
jerseyClientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
apacheHttpClient = ClientBuilder.newClient(jerseyClientConfig);
jerseyClient = ClientBuilder.newClient(jerseyClientConfig);
connectionCleanerTask = new ConnectionCleanerTask(connectionIdleTimeout);
eurekaConnCleaner.scheduleWithFixedDelay(
connectionCleanerTask, HTTP_CONNECTION_CLEANER_INTERVAL_MS,
Expand All @@ -104,7 +103,7 @@ public EurekaJersey3ClientImpl(

@Override
public Client getClient() {
return apacheHttpClient;
return jerseyClient;
}

/**
Expand All @@ -117,8 +116,8 @@ public void destroyResources() {
eurekaConnCleaner.execute(connectionCleanerTask);
eurekaConnCleaner.shutdown();
}
if (apacheHttpClient != null) {
apacheHttpClient.close();
if (jerseyClient != null) {
jerseyClient.close();
}
}

Expand Down Expand Up @@ -344,7 +343,7 @@ private ConnectionCleanerTask(int connectionIdleTimeout) {
public void run() {
Stopwatch start = executionTimeStats.start();
try {
HttpClientConnectionManager cm = (HttpClientConnectionManager) apacheHttpClient
HttpClientConnectionManager cm = (HttpClientConnectionManager) jerseyClient
.getConfiguration()
.getProperty(ApacheClientProperties.CONNECTION_MANAGER);
cm.closeIdleConnections(connectionIdleTimeout, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public void tearDown() throws Exception {
@Override
protected EurekaHttpClient getEurekaHttpClient(URI serviceURI) {
Jersey3ApplicationClientFactoryBuilder factoryBuilder = Jersey3ApplicationClientFactory.newBuilder();
if (serviceURI.getUserInfo() != null) {
factoryBuilder.withFeature(HttpAuthenticationFeature.basicBuilder().build());
}
TransportClientFactory clientFactory = factoryBuilder.build();
jerseyHttpClient = (AbstractJersey3EurekaHttpClient) clientFactory.newClient(new DefaultEndpoint(serviceURI.toString()));
return jerseyHttpClient;
Expand Down

0 comments on commit 1b86b2e

Please sign in to comment.