diff --git a/pulsar-broker/src/test/java/com/yahoo/pulsar/client/api/PartitionedProducerConsumerTest.java b/pulsar-broker/src/test/java/com/yahoo/pulsar/client/api/PartitionedProducerConsumerTest.java index a25503abe5b83..1508fbf6fd5b0 100644 --- a/pulsar-broker/src/test/java/com/yahoo/pulsar/client/api/PartitionedProducerConsumerTest.java +++ b/pulsar-broker/src/test/java/com/yahoo/pulsar/client/api/PartitionedProducerConsumerTest.java @@ -59,7 +59,10 @@ public void testRoundRobinProducer() throws Exception { log.info("-- Starting {} test --", methodName); int numPartitions = 4; - DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic1"); + // creating topicName with special characters such as space,{,\,*,. for encoding + final String specialCharacter = "! * ' ( ) ; : @ & = + $ , /\\ ? % # [ ]"; + final String topicName = "my-partitionedtopic1" + specialCharacter; + DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/" + topicName); ConsumerConfiguration conf = new ConsumerConfiguration(); conf.setSubscriptionType(SubscriptionType.Exclusive); diff --git a/pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/LookupService.java b/pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/LookupService.java index bdd4e0c695d33..2e31bc2ffd03f 100644 --- a/pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/LookupService.java +++ b/pulsar-client/src/main/java/com/yahoo/pulsar/client/impl/LookupService.java @@ -22,6 +22,7 @@ import com.yahoo.pulsar.client.util.FutureUtil; import com.yahoo.pulsar.common.lookup.data.LookupData; import com.yahoo.pulsar.common.naming.DestinationName; +import static com.yahoo.pulsar.common.util.Codec.encode; class LookupService { @@ -36,7 +37,7 @@ public LookupService(HttpClient httpClient, boolean useTls) { @SuppressWarnings("deprecation") public CompletableFuture getBroker(DestinationName destination) { - return httpClient.get(BasePath + destination.getLookupName(), LookupData.class).thenCompose(lookupData -> { + return httpClient.get(BasePath + getLookupName(destination), LookupData.class).thenCompose(lookupData -> { // Convert LookupData into as SocketAddress, handling exceptions try { URI uri; @@ -56,4 +57,10 @@ public CompletableFuture getBroker(DestinationName destinatio } }); } + + public static String getLookupName(DestinationName destination) { + return String.format("%s/%s/%s/%s/%s", destination.getDomain(), destination.getProperty(), + destination.getCluster(), destination.getNamespacePortion(), + encode(destination.getLocalName()).replaceAll("\\+", "%20")); + } }