Skip to content

Commit

Permalink
JAV-570 As a SDK user, I need to debug miecroserivce behind a proxy s…
Browse files Browse the repository at this point in the history
…o that I can connect to HW cloud by config proxy
  • Loading branch information
jeho0815 authored and WillemJiang committed Dec 14, 2017
1 parent e10ed16 commit e85cade
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@
*/
public final class HttpClientPool extends AbstractClientPool {

private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientPool.class);
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientPool.class);

public static final HttpClientPool INSTANCE = new HttpClientPool();
public static final HttpClientPool INSTANCE = new HttpClientPool();

private HttpClientPool() {
}
private HttpClientPool() {
}

@Override
public HttpClientOptions createHttpClientOptions() {
HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion();
HttpClientOptions httpClientOptions = new HttpClientOptions();
httpClientOptions.setProtocolVersion(ver);
httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout());
httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout());
if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) {
ProxyOptions proxy = new ProxyOptions();
proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost());
proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort());
proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername());
proxy.setPassword(ServiceRegistryConfig.INSTANCE.getProxyPasswd());
httpClientOptions.setProxyOptions(proxy);
}
if (ver == HttpVersion.HTTP_2) {
LOGGER.debug("service center client protocol version is HTTP/2");
httpClientOptions.setHttp2ClearTextUpgrade(false);
}
if (ServiceRegistryConfig.INSTANCE.isSsl()) {
LOGGER.debug("service center client performs requests over TLS");
buildSecureClientOptions(httpClientOptions);
}
return httpClientOptions;
@Override
public HttpClientOptions createHttpClientOptions() {
HttpVersion ver = ServiceRegistryConfig.INSTANCE.getHttpVersion();
HttpClientOptions httpClientOptions = new HttpClientOptions();
httpClientOptions.setProtocolVersion(ver);
httpClientOptions.setConnectTimeout(ServiceRegistryConfig.INSTANCE.getConnectionTimeout());
httpClientOptions.setIdleTimeout(ServiceRegistryConfig.INSTANCE.getIdleConnectionTimeout());
if (ServiceRegistryConfig.INSTANCE.isProxyEnable()) {
ProxyOptions proxy = new ProxyOptions();
proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost());
proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort());
proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername());
proxy.setPassword(ServiceRegistryConfig.INSTANCE.getProxyPasswd());
httpClientOptions.setProxyOptions(proxy);
}
if (ver == HttpVersion.HTTP_2) {
LOGGER.debug("service center client protocol version is HTTP/2");
httpClientOptions.setHttp2ClearTextUpgrade(false);
}
if (ServiceRegistryConfig.INSTANCE.isSsl()) {
LOGGER.debug("service center client performs requests over TLS");
buildSecureClientOptions(httpClientOptions);
}
}
return httpClientOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ public final class ServiceRegistryConfig {
public static final String MICROSERVICE_VERSION_FACTORY = "servicecomb.microserviceVersionFactory";

private boolean ssl = true;

public static final String PROXY_PRE_NAME = "cse.proxy.";

public static final String PROXY_ENABLE = PROXY_PRE_NAME + "enable";

public static final String PROXY_HOST = PROXY_PRE_NAME + "host";

public static final String PROXY_PORT = PROXY_PRE_NAME + "port";

public static final String PROXY_USERNAME = PROXY_PRE_NAME + "username";

public static final String PROXY_PASSWD = PROXY_PRE_NAME + "passwd";

private ServiceRegistryConfig() {
Expand All @@ -104,7 +109,8 @@ public int getWorkerPoolSize() {
if (workerPoolSize <= 0) {
int nAvailableProcessors = Runtime.getRuntime().availableProcessors();
LOGGER.warn("The property `{}` must be positive integer, fallback to use number of available processors: {}",
workerPoolSizeKey, nAvailableProcessors);
workerPoolSizeKey,
nAvailableProcessors);
return nAvailableProcessors;
}
return workerPoolSize;
Expand Down Expand Up @@ -250,7 +256,7 @@ public String getSecretKey() {
String tenantName = getProperty(null, TENANT_SECRET_KEY);
return tenantName;
}

public Boolean isProxyEnable() {
String enable = getProperty("false", PROXY_ENABLE);
return Boolean.parseBoolean(enable);
Expand Down Expand Up @@ -291,4 +297,4 @@ private String getProperty(String defaultValue, String... keys) {
return defaultValue;
}
}
}
}

0 comments on commit e85cade

Please sign in to comment.