-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Hello,
I've been using your library since last year to handle OData requests, thanks for your work, it really helped a lot.
When using $client->batch() against SAP SuccessFactors OData v2, the client throws an ODataException during decodeBody().
Here an example of a simple query made to SuccessFactors with the library :
$batch = $client->batch();
$batch->get("EmpJob?\$top=5&\$format=json", 'get-empjob');
$response = $batch->execute();After debugging, we got the response, and the decode part fails, with this error : The HTTP client sent back an invalid response.
Here is the response (redacted for privacy reasons) :
--batch_f20d8021-677a-4f93-8e62-862b6f383d15
Content-Type: application/http
Content-Transfer-Encoding: binary
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
DataServiceVersion: 2.0
Record-Count: 5
X-SF-Record-Count-Recursive: 5
successfactors-message: X-SF-Correlation-Id, successfactors-sourcetype are missing in request headers
Content-Length: 76038
{
"d" : {
"results" : [REDACTED]
}
}
--batch_f20d8021-677a-4f93-8e62-862b6f383d15--
What happened is in the decodeBody() function in ODataResponse :
private function decodeBody()
{
$decodedBody = json_decode($this->body, true, 512, JSON_BIGINT_AS_STRING);
if ($decodedBody === null) {
$matches = null;
preg_match('~\{(?:[^{}]|(?R))*\}~', $this->body, $matches);
$decodedBody = json_decode($matches[0], true, 512, JSON_BIGINT_AS_STRING);
if ($decodedBody === null) {
$decodedBody = array();
}
}
return $decodedBody;
}First try fail, because the body isnt a full JSON, then the preg_match doesnt match anything, so when trying to decode $matches[0], we got an ErrorException because of "Undefined array key 0", so ODataRequest throw the ODataException with the UNABLE_TO_PARSE_RESPONSE constant.
I'm quite not sure why since I'm not really an OData expert, I'm willing to help as far as I can.
Thanks for your help and for your really good lib !
Have a nice day.