From e85cadec49f3799940eed35e732d4cbdd5dcb9e7 Mon Sep 17 00:00:00 2001 From: jeho0815 Date: Wed, 13 Dec 2017 22:01:45 +0800 Subject: [PATCH] JAV-570 As a SDK user, I need to debug miecroserivce behind a proxy so that I can connect to HW cloud by config proxy --- .../client/http/HttpClientPool.java | 58 +++++++++---------- .../config/ServiceRegistryConfig.java | 14 +++-- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/HttpClientPool.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/HttpClientPool.java index a5e51a3e02..83c4078a69 100644 --- a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/HttpClientPool.java +++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/HttpClientPool.java @@ -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); } -} \ No newline at end of file + return httpClientOptions; + } +} diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/config/ServiceRegistryConfig.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/config/ServiceRegistryConfig.java index 252e036a81..8d052d991f 100644 --- a/service-registry/src/main/java/io/servicecomb/serviceregistry/config/ServiceRegistryConfig.java +++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/config/ServiceRegistryConfig.java @@ -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() { @@ -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; @@ -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); @@ -291,4 +297,4 @@ private String getProperty(String defaultValue, String... keys) { return defaultValue; } } -} \ No newline at end of file +}