Exception or error:
I got a 500 error response from server while trying to contact an api via a PHP source code:
Code HTTP = 500. net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: ($F{urlMediaGnx} != null && $F{urlMediaGnx} != "") ? Utils.getBufferedImage($F{urlMediaGnx}) : null
Here is the PHP source code for the function that call the API:
function callApiMedia ($codeProduit)
{
$retour = false;
if (!empty($codeProduit)) {
$url = "/medias/$codeProduit?allMedias=false&size=small";
$context = strtoupper(common::pref("context"));
if (!empty($context)) {
$baseUrl = getServerBaseUrl($context);
if (!empty($baseUrl)) {
$url = $baseUrl.$url;
// entĂȘtes HTTP
$headers = [
'Content-type: text/plain',
'charset=UTF-8'
];
$ch = curl_init();
http_build_query($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// appel au webservice
$r = curl_exec($ch);
$result = array();
$result['httpCode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result['body'] = $r;
curl_close($ch);
return $result;
}
}
}
return $retour;
}
Here is the main PHP source code.
Please Help.
$bookingDetailBeans = array();
foreach ($sqlBookingDetailResultSet as $sqlBookingDetailResult) {
$response = callApiMedia($sqlBookingDetailResult['CODPRO']);
$urlMediaGnx = "";
if ($response && $response['httpCode'] == 200) {
$response = json_decode($response['body']);
$urlMediaGnx = $response->medias;
$urlMediaGnx = ((object)$urlMediaGnx[0]);
$urlMediaGnx = $urlMediaGnx->secureUrl;
}
$bookingDetailBeans[] = array(
"codPro" => $sqlBookingDetailResult['CODPRO'],
"nomPro" => $sqlBookingDetailResult['NOMPRO'],
"qteCde" => $sqlBookingDetailResult['QTE_CDE'],
"nomencDoua" => $sqlBookingDetailResult['NOMENC_DOUA'],
"urlMediaGnx" => $urlMediaGnx,
"compo" => $sqlBookingDetailResult['COMPO']
);
}
How to solve: