You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by ji...@apache.org on 2022/08/01 08:10:52 UTC
[pulsar] branch branch-2.7 updated: [Branch 2.7][fix][proxy] Fix client service url (#16894)
This is an automated email from the ASF dual-hosted git repository.
jianghaiting pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.7 by this push:
new 76ec18eef1f [Branch 2.7][fix][proxy] Fix client service url (#16894)
76ec18eef1f is described below
commit 76ec18eef1f7488f9ce909db4728a9063eb0ee0b
Author: JiangHaiting <ji...@apache.org>
AuthorDate: Mon Aug 1 16:10:47 2022 +0800
[Branch 2.7][fix][proxy] Fix client service url (#16894)
* [fix][proxy] Fix client service url (#16834)
(cherry picked from commit eedee403da4ee531546b6440d82ed4bf14fa333a)
* fix compile error
Co-authored-by: Zixuan Liu <no...@gmail.com>
---
.../pulsar/proxy/server/ProxyConnection.java | 4 +++-
.../pulsar/proxy/server/ProxyConnectionTest.java | 25 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
index 3c73284e7ed..6ae0e52f961 100644
--- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
+++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java
@@ -529,8 +529,10 @@ public class ProxyConnection extends PulsarHandler {
ClientConfigurationData createClientConfiguration()
throws PulsarClientException.UnsupportedAuthenticationException {
ClientConfigurationData initialConf = new ClientConfigurationData();
- initialConf.setServiceUrl(service.getServiceUrl());
ProxyConfiguration proxyConfig = service.getConfiguration();
+ initialConf.setServiceUrl(
+ proxyConfig.isTlsEnabledWithBroker() ? service.getServiceUrlTls() : service.getServiceUrl());
+
// Apply all arbitrary configuration. This must be called before setting any fields annotated as
// @Secret on the ClientConfigurationData object because of the way they are serialized.
// See https://github.com/apache/pulsar/issues/8509 for more information.
diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java
index 5f533e37d35..0dccb4942d2 100644
--- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java
+++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java
@@ -18,8 +18,13 @@
*/
package org.apache.pulsar.proxy.server;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
import org.testng.annotations.Test;
public class ProxyConnectionTest {
@@ -35,4 +40,24 @@ public class ProxyConnectionTest {
assertFalse(ProxyConnection
.matchesHostAndPort("pulsar://", "pulsar://1.2.3.4:12345", "1.2.3.4:1234"));
}
+ @Test
+ public void testCreateClientConfiguration() throws PulsarClientException.UnsupportedAuthenticationException {
+ ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
+ proxyConfiguration.setTlsEnabledWithBroker(true);
+ String proxyUrlTls = "pulsar+ssl://proxy:6651";
+ String proxyUrl = "pulsar://proxy:6650";
+
+ ProxyService proxyService = mock(ProxyService.class);
+ doReturn(proxyConfiguration).when(proxyService).getConfiguration();
+ doReturn(proxyUrlTls).when(proxyService).getServiceUrlTls();
+ doReturn(proxyUrl).when(proxyService).getServiceUrl();
+
+ ProxyConnection proxyConnection = new ProxyConnection(proxyService, null);
+ ClientConfigurationData clientConfiguration = proxyConnection.createClientConfiguration();
+ assertEquals(clientConfiguration.getServiceUrl(), proxyUrlTls);
+
+ proxyConfiguration.setTlsEnabledWithBroker(false);
+ clientConfiguration = proxyConnection.createClientConfiguration();
+ assertEquals(clientConfiguration.getServiceUrl(), proxyUrl);
+ }
}