Jon Jon - 1 year ago 204
PHP Question

PHP JasperReports Server API Error

I am trying to ultimately run and display reports from a remote Jasper Server in a PHP application. What I am trying to do this with is the jrs-rest-php-client project on github.

The error:

Fatal error: Uncaught exception 'Jaspersoft\Exception\RESTRequestException' with message 'An unexpected HTTP status code was returned by the server' in C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php:409
Stack trace:
#0 C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php(479): Jaspersoft\Tool\RESTRequest->handleError(0, Array, false)
#1 C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Service\ReportService.php(40): Jaspersoft\Tool\RESTRequest->prepAndSend('https://jasper....', Array, 'GET', NULL, true)
#2 C:\xampp\htdocs\jrs\report.php(30): Jaspersoft\Service\ReportService->runReport('/Reports/Distri...', 'html')
#3 {main} thrown in C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php on line 409


require_once __DIR__ . "/vendor/autoload.php";
use Jaspersoft\Client\Client;
$d = new Client(
$info = $d->serverInfo();

Any ideas?

Answer Source

Looking into the code of RESTRequest.php there are two cases in which this exception is thrown:

  • A JSON result set with an unknown error code is returned (unknown meaning different from 200 OK)
  • No JSON result set is returned at all

So I suspect the connection isn't working properly. To find out more, you should catch the exception in your code and evaluate it:

It could look something like this (I'm more familiar with Java):

try {
    $d = new Client(

    $info = $d->serverInfo();

} catch (RESTRequestException $e) {
    echo 'RESTRequestException:';
    echo 'Exception message:   ',  $e->getMessage(), "\n";
    echo 'Set parameters:      ',  $e->parameters, "\n";
    echo 'Expected status code:',  $e->expectedStatusCodes, "\n";
    echo 'Error code:          ',  $e->errorCode, "\n";

If there is still an error, you can check the following:

  • Can you reach the jasper server from the server where this code is deployed? Sometimes e.g. firewall settings can interfere.
  • Is the organization called exactly like defined in the properties of the organization in the server? (Open repository / right click on organization / properties / resource-id)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download