Skip to content

Commit eb77e88

Browse files
authored
Merge branch 'master' into users/svegiraju/conversation-api-2
2 parents e618070 + b7e45a0 commit eb77e88

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

sdk-tests/src/test/java/io/dapr/it/methodinvoke/http/MethodInvokeController.java

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.web.bind.annotation.PostMapping;
77
import org.springframework.web.bind.annotation.PutMapping;
88
import org.springframework.web.bind.annotation.RequestBody;
9+
import org.springframework.web.bind.annotation.RequestParam;
910
import org.springframework.web.bind.annotation.RestController;
1011

1112
import java.util.ArrayList;
@@ -88,6 +89,11 @@ public void sleep(@RequestBody int seconds) throws InterruptedException {
8889
Thread.sleep(seconds * 1000);
8990
}
9091

92+
@GetMapping(path = "/query")
93+
public Map<String, String> getQuery(@RequestParam("uri") String uri) {
94+
return Map.of("uri", uri);
95+
}
96+
9197
@GetMapping(path = "/health")
9298
public void health() {
9399
}

sdk-tests/src/test/java/io/dapr/it/methodinvoke/http/MethodInvokeIT.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.dapr.it.methodinvoke.http;
22

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import io.dapr.client.DaprClient;
4-
import io.dapr.client.DaprClientBuilder;
5+
import io.dapr.client.DaprHttp;
56
import io.dapr.client.domain.HttpExtension;
67
import io.dapr.exceptions.DaprException;
78
import io.dapr.it.BaseIT;
@@ -140,4 +141,24 @@ public void testInvokeException() throws Exception {
140141
assertTrue(new String(exception.getPayload()).contains("Internal Server Error"));
141142
}
142143
}
144+
145+
@Test
146+
public void testInvokeQueryParamEncoding() throws Exception {
147+
try (DaprClient client = daprRun.newDaprClientBuilder().build()) {
148+
client.waitForSidecar(10000).block();
149+
150+
String uri = "abc/pqr";
151+
Map<String, List<String>> queryParams = Map.of("uri", List.of(uri));
152+
HttpExtension httpExtension = new HttpExtension(DaprHttp.HttpMethods.GET, queryParams, Map.of());
153+
JsonNode result = client.invokeMethod(
154+
daprRun.getAppName(),
155+
"/query",
156+
null,
157+
httpExtension,
158+
JsonNode.class
159+
).block();
160+
161+
assertEquals(uri, result.get("uri").asText());
162+
}
163+
}
143164
}

sdk/src/main/java/io/dapr/client/DaprHttp.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.io.IOException;
2626
import java.net.URI;
27-
import java.net.URISyntaxException;
2827
import java.net.URLEncoder;
2928
import java.net.http.HttpClient;
3029
import java.net.http.HttpRequest;
@@ -324,10 +323,17 @@ private static String getContentType(Map<String, String> headers) {
324323
private static URI createUri(URI uri, String[] pathSegments, Map<String, List<String>> urlParameters) {
325324
String path = createPath(uri, pathSegments);
326325
String query = createQuery(urlParameters);
326+
StringBuilder result = new StringBuilder();
327+
328+
result.append(uri.getScheme()).append("://").append(uri.getAuthority()).append(path);
329+
330+
if (query != null) {
331+
result.append("?").append(query);
332+
}
327333

328334
try {
329-
return new URI(uri.getScheme(), uri.getAuthority(), path, query, null);
330-
} catch (URISyntaxException exception) {
335+
return URI.create(result.toString());
336+
} catch (IllegalArgumentException exception) {
331337
throw new DaprException(exception);
332338
}
333339
}
@@ -346,6 +352,10 @@ private static String createPath(URI uri, String[] pathSegments) {
346352
}
347353

348354
for (String segment : pathSegments) {
355+
if (segment == null || segment.isEmpty()) {
356+
continue; // Skip empty segments
357+
}
358+
349359
pathBuilder.append(encodePathSegment(segment)).append("/"); // Encode each segment
350360
}
351361

@@ -363,6 +373,11 @@ private static String createQuery(Map<String, List<String>> urlParameters) {
363373

364374
for (Map.Entry<String, List<String>> entry : urlParameters.entrySet()) {
365375
String key = entry.getKey();
376+
377+
if (key == null || key.isEmpty()) {
378+
continue; // Skip empty keys
379+
}
380+
366381
List<String> values = entry.getValue();
367382

368383
for (String value : values) {

0 commit comments

Comments
 (0)