Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uri encoding for http topic lookup #147

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -36,7 +37,7 @@ public LookupService(HttpClient httpClient, boolean useTls) {

@SuppressWarnings("deprecation")
public CompletableFuture<InetSocketAddress> 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;
Expand All @@ -56,4 +57,10 @@ public CompletableFuture<InetSocketAddress> 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"));
}
}