aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-05-19 09:16:46 -0400
committerDan Timoney <dtimoney@att.com>2020-05-19 16:31:30 +0000
commitfc54a5c7bbea73399f9fc45d8145aa929eb8ff46 (patch)
tree5b246ab46456d8a17755b072ce7015991c2c4d3d
parentcaf0a0dc5adf6a24ba2b0306422ffebe53e3b3b7 (diff)
Fix incorrect encoding for query params
Issue-ID: CCSDK-2380 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca> Change-Id: I3a49f2c5a3a29383e43e2a4a3d6a9c13a9f933c2 (cherry picked from commit 1910b2b7879712ccac56580e8996a700f6dcec43)
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt2
-rw-r--r--ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt36
2 files changed, 37 insertions, 1 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt
index c9c8aab7d..11f6dc7e3 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt
@@ -94,7 +94,7 @@ interface BlueprintWebClientService {
* the difference is in convertToBasicHeaders vs basicHeaders
*/
val convertedHeaders: Array<BasicHeader> = convertToBasicHeaders(headers)
- val encodedPath = UriUtils.encodePath(path, StandardCharsets.UTF_8.name())
+ val encodedPath = UriUtils.encodeQuery(path, StandardCharsets.UTF_8.name())
return when (HttpMethod.resolve(methodType)) {
HttpMethod.DELETE -> delete(encodedPath, convertedHeaders, String::class.java)
HttpMethod.GET -> get(encodedPath, convertedHeaders, String::class.java)
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt
index fa357e1fe..71f8cd753 100644
--- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt
+++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt
@@ -51,10 +51,12 @@ import org.springframework.test.context.junit4.SpringRunner
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
+import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
@@ -115,6 +117,32 @@ class RestClientServiceTest {
}
@Test
+ fun testGetQueryParam() {
+ val restClientService = bluePrintRestLibPropertyService
+ .blueprintWebClientService("sample")
+ val response = restClientService.exchangeResource(
+ HttpMethod.GET.name, "/sample/query?id=3", ""
+ )
+ assertEquals(
+ "query with id:3", response.body,
+ "failed to get query param response"
+ )
+ }
+
+ @Test
+ fun testGetPathParamWithWhitespace() {
+ val restClientService = bluePrintRestLibPropertyService
+ .blueprintWebClientService("sample")
+ val response = restClientService.exchangeResource(
+ HttpMethod.GET.name, "/sample/path/id 3/get", ""
+ )
+ assertEquals(
+ "path param id:id 3", response.body,
+ "failed to get query param response"
+ )
+ }
+
+ @Test
fun testPatch() {
val restClientService = bluePrintRestLibPropertyService
.blueprintWebClientService("sample")
@@ -277,6 +305,14 @@ open class SampleController {
@GetMapping("/name")
fun getName(): String = "Sample Controller"
+ @GetMapping("/query")
+ fun getQuery(@RequestParam("id") id: String): String =
+ "query with id:$id"
+
+ @GetMapping("/path/{id}/get")
+ fun getPathParam(@PathVariable("id") id: String): String =
+ "path param id:$id"
+
@PatchMapping("/name")
fun patchName(): String = "Patch request successful"