From d1e4b1d354574cb01bde8bdbdaa52e9d87ad3c5a Mon Sep 17 00:00:00 2001 From: "U-UNITED\\friebe" Date: Mon, 16 Jan 2017 13:51:57 +0100 Subject: [PATCH 1/2] Resolve GET parameters in URL, restoring BC See PR #20 --- src/main/php/webservices/rest/RestClient.class.php | 2 +- .../php/webservices/rest/RestRequest.class.php | 11 ++++++++++- .../rest/unittest/RestRequestTest.class.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/php/webservices/rest/RestClient.class.php b/src/main/php/webservices/rest/RestClient.class.php index c5f75366..4a35a42b 100644 --- a/src/main/php/webservices/rest/RestClient.class.php +++ b/src/main/php/webservices/rest/RestClient.class.php @@ -213,7 +213,7 @@ public function execute(RestRequest $request) { } else if ($request->hasBody()) { $send->setParameters($request->getBody()); } else { - $send->setParameters($request->getParameters()); + $send->setParameters($request->targetParameters()); } try { diff --git a/src/main/php/webservices/rest/RestRequest.class.php b/src/main/php/webservices/rest/RestRequest.class.php index 51205c51..d24b0b6c 100644 --- a/src/main/php/webservices/rest/RestRequest.class.php +++ b/src/main/php/webservices/rest/RestRequest.class.php @@ -451,6 +451,15 @@ private function authenticate($base, $url) { return $url; } + /** + * Returns parameters, resolving segments if necessary + * + * @return [:string] + */ + public function targetParameters() { + return array_map([$this, 'resolve'], $this->parameters); + } + /** * Resolves target URL * @@ -475,7 +484,7 @@ public function targetUrl(URL $base= null) { $url= clone $base; } - return $url->setParams(array_map([$this, 'resolve'], $this->parameters))->setPath($this->resolve($resource)); + return $url->setParams($this->targetParameters())->setPath($this->resolve($resource)); } /** diff --git a/src/test/php/webservices/rest/unittest/RestRequestTest.class.php b/src/test/php/webservices/rest/unittest/RestRequestTest.class.php index c4e58a87..a28e9a51 100755 --- a/src/test/php/webservices/rest/unittest/RestRequestTest.class.php +++ b/src/test/php/webservices/rest/unittest/RestRequestTest.class.php @@ -320,6 +320,20 @@ public function targetWithSegmentParametersAndConstantsMixed() { $this->assertEquals('/repos/thekid/xp-framework/issues/1', $fixture->targetUrl(new URL('http://test'))->getPath()); } + #[@test] + public function segments_allowed_in_get_parameters() { + $fixture= new RestRequest('/repos/?user={user}'); + $fixture->addSegment('user', 'thekid'); + $this->assertEquals(['user' => 'thekid'], $fixture->targetUrl(new URL('http://test'))->getParams()); + } + + #[@test] + public function segments_in_parameters_resolved_in_target_parameters() { + $fixture= new RestRequest('/repos/?user={user}'); + $fixture->addSegment('user', 'thekid'); + $this->assertEquals(['user' => 'thekid'], $fixture->targetParameters()); + } + #[@test, @values(['/rest/api/v2/', '/rest/api/v2'])] public function relativeResource($base) { $fixture= new RestRequest('issues'); From e0d6ba64a93cb37f1ffc4e1fe0a90c25313f313b Mon Sep 17 00:00:00 2001 From: "U-UNITED\\friebe" Date: Mon, 16 Jan 2017 13:53:59 +0100 Subject: [PATCH 2/2] QA: API docs for RestClient::execute() --- src/main/php/webservices/rest/RestClient.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/php/webservices/rest/RestClient.class.php b/src/main/php/webservices/rest/RestClient.class.php index 4a35a42b..ad5ed287 100644 --- a/src/main/php/webservices/rest/RestClient.class.php +++ b/src/main/php/webservices/rest/RestClient.class.php @@ -190,6 +190,7 @@ public function serializerFor($contentType) { * @param webservices.rest.RestRequest $request * @return webservices.rest.RestResponse * @throws lang.IllegalStateException if no connection is set + * @throws webservices.rest.RestException */ public function execute(RestRequest $request) { if (null === $this->connection) {