diff --git a/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php b/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php index d1a35d8..d62c4b3 100644 --- a/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php +++ b/client/src/Plugin/QueueWorker/CollectClientQueueWorker.php @@ -16,10 +16,9 @@ use Drupal\Core\Queue\QueueWorkerBase; use Drupal\Core\Queue\SuspendQueueException; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; -use GuzzleHttp\Message\ResponseInterface; +use Psr\Http\Message\ResponseInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Serializer\SerializerInterface; /** @@ -231,7 +230,7 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto // Special support for CollectJSON field definition. try { foreach ($this->getTransferObjects($item) as $item_values) { - $response = $this->httpClient->post($url, array_merge($item_values, $options)); + $response = $this->httpClient->request('POST', $url, array_merge($item_values, $options)); if ($response->getStatusCode() != 201) { throw new \Exception('Expected status code 201 Created, got ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . ' when submitting item to ' . $url . '.', 0); } @@ -263,7 +262,7 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto * * @param string $cache_key * The entity cache key. - * @param \GuzzleHttp\Message\ResponseInterface $response + * @param \Psr\Http\Message\ResponseInterface $response * The response. */ protected function cacheUuid($cache_key, ResponseInterface $response) { @@ -282,8 +281,12 @@ class CollectClientQueueWorker extends QueueWorkerBase implements ContainerFacto */ protected function parseResponse(ResponseInterface $response, $property) { try { + if (!$response->getBody()) { + return FALSE; + } + // Decode received data. - $json = $response->json(); + $json = json_decode($response->getBody()->getContents(), TRUE); if ($property == 'uuid') { return isset($json['data'][$property]) ? $json['data'][$property] : FALSE; diff --git a/client/tests/src/Unit/Plugin/QueueWorker/QueueWorkerTest.php b/client/tests/src/Unit/Plugin/QueueWorker/QueueWorkerTest.php index 6dca1e9..777b591 100644 --- a/client/tests/src/Unit/Plugin/QueueWorker/QueueWorkerTest.php +++ b/client/tests/src/Unit/Plugin/QueueWorker/QueueWorkerTest.php @@ -215,10 +215,10 @@ EOF; ); $url = 'http://example.com/collect/api/v1/submissions'; $location = 'http://server.collect.dev/collect/api/v1/submissions/f67c88c9-1608-4f47-8291-4e35411af61f'; - $response = $this->getMock('GuzzleHttp\Message\ResponseInterface'); + $response = $this->getMock('Psr\Http\Message\ResponseInterface'); $this->httpClient->expects($this->once()) - ->method('post') - ->with($url, $options) + ->method('request') + ->with('POST', $url, $options) ->will($this->returnValue($response)); $response->expects($this->once())